Cleanup
This commit is contained in:
parent
d12e3bb43a
commit
d188897c3f
@ -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>,
|
||||||
|
24
src/main.rs
24
src/main.rs
@ -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) => {
|
|
||||||
command_options.command_result.status_success = false;
|
|
||||||
command_options.command_result.stderr = stderr;
|
|
||||||
}
|
}
|
||||||
|
// 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(""),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
33
src/ui.rs
33
src/ui.rs
@ -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 ¤t_state == ps {
|
// if let Some(ps) = previous_state {
|
||||||
event!(Level::INFO, "Not rendering: {current_state:?}");
|
// if ¤t_state == ps {
|
||||||
// return Some(current_state);
|
// event!(Level::INFO, "Not rendering: {current_state:?}");
|
||||||
}
|
// return Some(current_state);
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
f.render_widget(
|
f.render_widget(
|
||||||
Paragraph::new(bytes_to_text(&data))
|
Paragraph::new(bytes_to_text(&data))
|
||||||
|
Loading…
Reference in New Issue
Block a user