From d188897c3f291eb31d88de56d99239f95f970929 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Tue, 20 Dec 2022 21:56:36 -0500 Subject: [PATCH] Cleanup --- src/command.rs | 12 ------------ src/main.rs | 24 +++++++++++++++++------- src/ui.rs | 33 ++++++++++----------------------- 3 files changed, 27 insertions(+), 42 deletions(-) diff --git a/src/command.rs b/src/command.rs index 142d627..17b1056 100644 --- a/src/command.rs +++ b/src/command.rs @@ -32,18 +32,6 @@ pub struct CommandResult { pub stderr: Rope, } -// TODO: Result? -impl Default for CommandResult { - fn default() -> Self { - Self { - status_success: true, - // TODO: Option - stdout: Rope::from_str(""), - stderr: Rope::from_str(""), - } - } -} - pub fn command_event_loop( command_request_receiver: Receiver, event_sender: Sender, diff --git a/src/main.rs b/src/main.rs index 27c7158..d090698 100644 --- a/src/main.rs +++ b/src/main.rs @@ -68,7 +68,7 @@ pub struct CommandOptions { wordsplit: bool, /// The result of a command execution - command_result: CommandResult, + command_result: Option, /// The position of the cursor cmdline_position: u16, @@ -104,7 +104,7 @@ impl CommandOptions { cmdline_position: 0_u16, hidden_options: Vec::new(), cmdline: String::new(), - command_result: CommandResult::default(), + command_result: None, autorun: true, wordsplit: true, }; @@ -412,12 +412,22 @@ fn run_app(terminal: &mut Terminal, app: App) -> Result { - command_options.command_result = c; - } - CommandCompleted::Failure(stderr) => { - command_options.command_result.status_success = false; - command_options.command_result.stderr = stderr; + command_options.command_result = Some(c); } + // TODO: This could be cleaned up + CommandCompleted::Failure(stderr) => match command_options.command_result { + Some(ref mut c) => { + c.status_success = false; + c.stderr = stderr; + } + None => { + command_options.command_result = Some(CommandResult { + status_success: false, + stderr: stderr, + stdout: Rope::from_str(""), + }) + } + }, } } diff --git a/src/ui.rs b/src/ui.rs index 13efdf3..a3f92e5 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -81,12 +81,9 @@ pub fn draw(f: &mut Frame, app: &App) { ); // Render the output in the outpout region - ui_output( - f, - chunks[1], - &mut render_states, - &command_options.command_result, - ); + if let Some(ref command_result) = command_options.command_result { + ui_output(f, chunks[1], &mut render_states, command_result); + } f.set_cursor( vertical_chunks[1].x + command_options.cmdline_position + 1, @@ -133,17 +130,6 @@ fn ui_output( command_result.stderr.slice(..), "Stderr", ); - - // f.render_widget( - // Paragraph::new(bytes_to_text(&command_result.stdout.bytes().collect())) - // .block(Block::default().title("Output").borders(Borders::ALL)), - // chunks[0], - // ); - // f.render_widget( - // Paragraph::new(bytes_to_text(&command_result.stderr.bytes().collect())) - // .block(Block::default().title("Error").borders(Borders::ALL)), - // chunks[1], - // ); } event!(Level::INFO, "Done rendering out"); } @@ -180,12 +166,13 @@ fn lazy_render_rope_slice<'a, B: Backend>( input_hash: util::hash_bytes(&data), }; - if let Some(ps) = previous_state { - if ¤t_state == ps { - event!(Level::INFO, "Not rendering: {current_state:?}"); - // return Some(current_state); - } - } + // TODO: Do not render if already rendered + // if let Some(ps) = previous_state { + // if ¤t_state == ps { + // event!(Level::INFO, "Not rendering: {current_state:?}"); + // return Some(current_state); + // } + // } f.render_widget( Paragraph::new(bytes_to_text(&data))