diff options
Diffstat (limited to 'vendor/prodash/src/render/tui/utils.rs')
-rw-r--r-- | vendor/prodash/src/render/tui/utils.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/vendor/prodash/src/render/tui/utils.rs b/vendor/prodash/src/render/tui/utils.rs new file mode 100644 index 000000000..7a261edce --- /dev/null +++ b/vendor/prodash/src/render/tui/utils.rs @@ -0,0 +1,25 @@ +use std::{future::Future, pin::Pin, task::Poll, time::Duration}; + +use async_io::Timer; + +/// Returns a stream of 'ticks', each being duration `dur` apart. +/// +/// Can be useful to provide the TUI with additional events in regular intervals, +/// when using the [`tui::render_with_input(…events)`](./fn.render_with_input.html) function. +pub fn ticker(dur: Duration) -> impl futures_core::Stream<Item = ()> { + let mut delay = Timer::after(dur); + futures_lite::stream::poll_fn(move |ctx| { + let res = Pin::new(&mut delay).poll(ctx); + match res { + Poll::Pending => Poll::Pending, + Poll::Ready(_) => { + delay = Timer::after(dur); + Poll::Ready(Some(())) + } + } + }) +} + +pub const VERTICAL_LINE: &str = "│"; + +pub use tui_react::{draw_text_nowrap_fn, draw_text_with_ellipsis_nowrap, util::*}; |