Print output when done

This commit is contained in:
Austen Adler 2022-12-29 15:10:28 -05:00
parent bdd28da59e
commit 3471ea3c0b

View File

@ -190,7 +190,7 @@ fn main() -> Result<()> {
let (message_rx, command_request_tx) = init_message_passing();
// Run the actual application
let app = App::new(message_rx, command_request_tx, text_orig);
let mut app = App::new(message_rx, command_request_tx, text_orig);
enable_raw_mode()?;
let mut stdout = io::stdout();
execute!(
@ -202,7 +202,7 @@ fn main() -> Result<()> {
let backend = CrosstermBackend::new(stdout);
let mut terminal = Terminal::new(backend)?;
let res = run_app(&mut terminal, app);
let res = run_app(&mut terminal, &mut app);
// Restore terminal
disable_raw_mode()?;
@ -219,6 +219,8 @@ fn main() -> Result<()> {
if let Some(res) = res {
std::io::stderr().write_all(res.as_bytes())?;
std::io::stderr().write_all(b"\n")?;
// TODO: I do not want to collect the whole thing into a vec
app.command_options.read().command_result.as_ref().map(|r| std::io::stdout().write_all(&r.stdout.bytes().collect::<Vec<u8>>())).transpose()?;
}
Ok(())
@ -248,7 +250,7 @@ fn init_message_passing() -> (Receiver<EventMessage>, Sender<CommandRequest>) {
#[allow(clippy::too_many_lines)]
#[cfg_attr(debug_assertions, instrument(skip(terminal, app)))]
fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> Result<Option<String>> {
fn run_app<B: Backend>(terminal: &mut Terminal<B>, app: &mut App) -> Result<Option<String>> {
// When starting the app, ensure the command runs at least once
{
let mut command_options = app.command_options.write();