This commit is contained in:
Austen Adler 2022-12-20 21:56:36 -05:00
parent d12e3bb43a
commit d188897c3f
3 changed files with 27 additions and 42 deletions

View File

@ -32,18 +32,6 @@ pub struct CommandResult {
pub stderr: Rope, pub stderr: Rope,
} }
// TODO: Result?
impl Default for CommandResult {
fn default() -> Self {
Self {
status_success: true,
// TODO: Option<Rope>
stdout: Rope::from_str(""),
stderr: Rope::from_str(""),
}
}
}
pub fn command_event_loop( pub fn command_event_loop(
command_request_receiver: Receiver<CommandRequest>, command_request_receiver: Receiver<CommandRequest>,
event_sender: Sender<EventMessage>, event_sender: Sender<EventMessage>,

View File

@ -68,7 +68,7 @@ pub struct CommandOptions {
wordsplit: bool, wordsplit: bool,
/// The result of a command execution /// The result of a command execution
command_result: CommandResult, command_result: Option<CommandResult>,
/// The position of the cursor /// The position of the cursor
cmdline_position: u16, cmdline_position: u16,
@ -104,7 +104,7 @@ impl CommandOptions {
cmdline_position: 0_u16, cmdline_position: 0_u16,
hidden_options: Vec::new(), hidden_options: Vec::new(),
cmdline: String::new(), cmdline: String::new(),
command_result: CommandResult::default(), command_result: None,
autorun: true, autorun: true,
wordsplit: true, wordsplit: true,
}; };
@ -412,12 +412,22 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, app: App) -> Result<Option<St
let mut command_options = app.command_options.write(); let mut command_options = app.command_options.write();
match command_completed { match command_completed {
CommandCompleted::Success(c) => { CommandCompleted::Success(c) => {
command_options.command_result = c; command_options.command_result = Some(c);
} }
CommandCompleted::Failure(stderr) => { // TODO: This could be cleaned up
command_options.command_result.status_success = false; CommandCompleted::Failure(stderr) => match command_options.command_result {
command_options.command_result.stderr = stderr; 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(""),
})
}
},
} }
} }

View File

@ -81,12 +81,9 @@ pub fn draw<B: Backend>(f: &mut Frame<B>, app: &App) {
); );
// Render the output in the outpout region // Render the output in the outpout region
ui_output( if let Some(ref command_result) = command_options.command_result {
f, ui_output(f, chunks[1], &mut render_states, command_result);
chunks[1], }
&mut render_states,
&command_options.command_result,
);
f.set_cursor( f.set_cursor(
vertical_chunks[1].x + command_options.cmdline_position + 1, vertical_chunks[1].x + command_options.cmdline_position + 1,
@ -133,17 +130,6 @@ fn ui_output<B: Backend>(
command_result.stderr.slice(..), command_result.stderr.slice(..),
"Stderr", "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"); event!(Level::INFO, "Done rendering out");
} }
@ -180,12 +166,13 @@ fn lazy_render_rope_slice<'a, B: Backend>(
input_hash: util::hash_bytes(&data), input_hash: util::hash_bytes(&data),
}; };
if let Some(ps) = previous_state { // TODO: Do not render if already rendered
if &current_state == ps { // if let Some(ps) = previous_state {
event!(Level::INFO, "Not rendering: {current_state:?}"); // if &current_state == ps {
// event!(Level::INFO, "Not rendering: {current_state:?}");
// return Some(current_state); // return Some(current_state);
} // }
} // }
f.render_widget( f.render_widget(
Paragraph::new(bytes_to_text(&data)) Paragraph::new(bytes_to_text(&data))