Revert StatefulView
This commit is contained in:
12
src/app.rs
12
src/app.rs
@@ -36,9 +36,7 @@ impl App {
|
||||
let Some(current_view) = self.state.view.as_mut() else {
|
||||
continue;
|
||||
};
|
||||
let Some(view) = current_view.get_view() else {
|
||||
continue;
|
||||
};
|
||||
let view = current_view.get_view();
|
||||
if !view.is_running() { break Ok(()) }
|
||||
terminal.draw(|frame| self.draw(frame))?;
|
||||
}
|
||||
@@ -55,9 +53,7 @@ impl App {
|
||||
let Some(current_view) = self.state.view.as_mut() else {
|
||||
return Err(eyre!("there is no view"));
|
||||
};
|
||||
let Some(view) = current_view.get_view() else {
|
||||
return Err(eyre!("there is no view"));
|
||||
};
|
||||
let view = current_view.get_view();
|
||||
view.handle_input(key)?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -66,9 +62,7 @@ impl App {
|
||||
let Some(current_view) = self.state.view.as_mut() else {
|
||||
return;
|
||||
};
|
||||
let Some(view) = current_view.get_view() else {
|
||||
return;
|
||||
};
|
||||
let view = current_view.get_view();
|
||||
if let Some(pos) = view.screen_cursor() {
|
||||
frame.set_cursor_position(pos);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use crate::config::types::ApplicationConfig;
|
||||
use crate::widgets::popups::folder::AddFolderPopup;
|
||||
use crate::widgets::views::{StatefulView, View};
|
||||
use crossterm::event::KeyCode::Char;
|
||||
use crossterm::event::{Event, KeyCode, KeyEventKind};
|
||||
use rat_cursor::HasScreenCursor;
|
||||
@@ -9,6 +8,7 @@ use ratatui::layout::{Constraint, Direction, Layout, Rect};
|
||||
use ratatui::prelude::{Color, Line, Span, Style, Text, Widget};
|
||||
use ratatui::widgets::{Block, Borders, Paragraph, StatefulWidget};
|
||||
use crate::widgets::popups::AppPopup;
|
||||
use crate::widgets::views::View;
|
||||
|
||||
pub struct MainView {
|
||||
pub state: MainViewState
|
||||
@@ -74,9 +74,9 @@ impl MainViewState {
|
||||
}
|
||||
}
|
||||
|
||||
impl StatefulView for MainView {
|
||||
type State = MainViewState;
|
||||
fn handle_input(state: &mut Self::State, event: &Event) -> color_eyre::Result<()> {
|
||||
impl View for MainView {
|
||||
fn handle_input(&mut self, event: &Event) -> color_eyre::Result<()> {
|
||||
let state = &mut self.state;
|
||||
state.handle_popup(event)?;
|
||||
|
||||
if let Event::Key(key_event) = event {
|
||||
@@ -99,8 +99,8 @@ impl StatefulView for MainView {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn is_running(state: &Self::State) -> bool {
|
||||
!matches!(state.status, Status::Exiting)
|
||||
fn is_running(&self) -> bool {
|
||||
!matches!(self.state.status, Status::Exiting)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,22 +9,15 @@ pub trait View: HasScreenCursor {
|
||||
fn is_running(&self) -> bool;
|
||||
}
|
||||
|
||||
pub trait StatefulView: HasScreenCursor {
|
||||
type State;
|
||||
fn handle_input(state: &mut Self::State, event: &Event) -> color_eyre::Result<()>;
|
||||
fn is_running(state: &Self::State) -> bool;
|
||||
}
|
||||
|
||||
pub enum AppView {
|
||||
Main(MainView),
|
||||
}
|
||||
|
||||
impl AppView {
|
||||
pub fn get_view(&mut self) -> Option<&mut dyn View> {
|
||||
pub fn get_view(&mut self) -> &mut dyn View
|
||||
{
|
||||
match self {
|
||||
_ => None
|
||||
AppView::Main(main_view) => main_view
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Implement Stateful View
|
||||
}
|
||||
Reference in New Issue
Block a user