fdehau / tui-rs

Build terminal user interfaces and dashboards using Rust
MIT License
10.84k stars 487 forks source link

[help] Suppressing `println` from other code #409

Closed yatesco closed 1 year ago

yatesco commented 4 years ago

Hi - TUI newbie here :-).

I poll my log server for new log messages and unfortunately the client emits printlns which get rendered on top of the TUI. I know it's possible to gag stdout but that seems a very silly thing to do in a TUI!

Is there an idiomatic way of creating a new stdout and piping the println to that?

To be clear, this isn't a separate process, it is:

loop {
  do_tui_rendering_stuff()?;
  refresh_logs();
}

and refresh_logs has printlns.

Other than "well obviously don't use printlns!", what options do I have?

Thanks!

extrawurst commented 3 years ago

that's actually more a thing to configure in the backend of your choice. e.g the crossterm example for using stderr is here: https://github.com/crossterm-rs/crossterm/blob/master/examples/stderr.rs

but that only fixes the println obviously. stuff printed to stderr will still be appearing in your tui