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