Skip to content

Commit

Permalink
frontend: move terminal draw into view::view()
Browse files Browse the repository at this point in the history
Signed-off-by: aserowy <serowy@hotmail.com>
  • Loading branch information
aserowy committed Feb 19, 2024
1 parent 50edb26 commit e257d00
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion y1337-frontend/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub struct Emitter {
}

impl Emitter {
pub fn listen(initial_path: PathBuf) -> Self {
pub fn start(initial_path: PathBuf) -> Self {
let (sender, receiver) = mpsc::channel(1);
let internal_sender = sender.clone();

Expand Down
7 changes: 4 additions & 3 deletions y1337-frontend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub async fn run(settings: Settings) -> Result<(), AppError> {
}

let initial_path = get_initial_path(&settings.startup_path);
let mut emitter = Emitter::listen(initial_path.clone());
let mut emitter = Emitter::start(initial_path.clone());

let mut result = Vec::new();
'app_loop: while let Some(messages) = emitter.receiver.recv().await {
Expand Down Expand Up @@ -68,7 +68,7 @@ pub async fn run(settings: Settings) -> Result<(), AppError> {
}
}

terminal.draw(|frame| view::view(&mut model, frame, &layout))?;
view::view(&mut terminal, &mut model, &layout)?;

// TODO: refactor post render actions
let post_render_actions = render_actions.iter().filter_map(|actn| match actn {
Expand Down Expand Up @@ -106,7 +106,8 @@ pub async fn run(settings: Settings) -> Result<(), AppError> {

emitter.resume();
terminal.resume()?;
terminal.draw(|frame| view::view(&mut model, frame, &layout))?;

view::view(&mut terminal, &mut model, &layout)?;
}
PostRenderAction::Quit(stdout_result) => {
if let Some(stdout_result) = stdout_result {
Expand Down
18 changes: 9 additions & 9 deletions y1337-frontend/src/view/mod.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use ratatui::Frame;

use crate::{layout::AppLayout, model::Model};
use crate::{error::AppError, layout::AppLayout, model::Model, terminal::Term};

mod buffer;
mod commandline;
mod statusline;

pub fn view(model: &mut Model, frame: &mut Frame, layout: &AppLayout) {
pub fn view(terminal: &mut Term, model: &mut Model, layout: &AppLayout) -> Result<(), AppError> {
// NOTE: If perf matters, call view only on relevant changed model parts
commandline::view(model, frame, layout.commandline);
terminal.draw(|frame| {
commandline::view(model, frame, layout.commandline);

buffer::view(&model.mode, &model.current.buffer, frame, layout.current);
buffer::view(&model.mode, &model.parent.buffer, frame, layout.parent);
buffer::view(&model.mode, &model.preview.buffer, frame, layout.preview);
buffer::view(&model.mode, &model.current.buffer, frame, layout.current);
buffer::view(&model.mode, &model.parent.buffer, frame, layout.parent);
buffer::view(&model.mode, &model.preview.buffer, frame, layout.preview);

statusline::view(model, frame, layout.statusline);
statusline::view(model, frame, layout.statusline);
})
}

0 comments on commit e257d00

Please sign in to comment.