-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use ratatui instead of tui-rs for the terminal UI (#505)
- Loading branch information
Showing
7 changed files
with
61 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ name = "metrics-observer" | |
version = "0.4.0" | ||
authors = ["Toby Lawrence <[email protected]>"] | ||
edition = "2018" | ||
rust-version = "1.70.0" | ||
rust-version = "1.74.0" | ||
|
||
license = "MIT" | ||
|
||
|
@@ -23,8 +23,7 @@ bytes = { version = "1", default-features = false } | |
crossbeam-channel = { version = "0.5", default-features = false, features = ["std"] } | ||
prost = { version = "0.12", default-features = false } | ||
prost-types = { version = "0.12", default-features = false } | ||
tui = { version = "0.19", default-features = false, features = ["termion"] } | ||
termion = { version = "2", default-features = false } | ||
ratatui = { version = "0.28.0", default-features = false, features = ["crossterm"] } | ||
chrono = { version = "0.4", default-features = false, features = ["clock"] } | ||
|
||
[build-dependencies] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,18 @@ | ||
use std::io; | ||
use std::thread; | ||
use std::time::Duration; | ||
|
||
use crossbeam_channel::{bounded, Receiver, RecvTimeoutError, TrySendError}; | ||
use termion::event::Key; | ||
use termion::input::TermRead; | ||
use ratatui::crossterm::event::{self, Event, KeyEvent, KeyEventKind}; | ||
|
||
pub struct InputEvents { | ||
rx: Receiver<Key>, | ||
} | ||
pub struct InputEvents; | ||
|
||
impl InputEvents { | ||
pub fn new() -> InputEvents { | ||
let (tx, rx) = bounded(1); | ||
thread::spawn(move || { | ||
let stdin = io::stdin(); | ||
for key in stdin.keys().flatten() { | ||
// If our queue is full, we don't care. The user can just press the key again. | ||
if let Err(TrySendError::Disconnected(_)) = tx.try_send(key) { | ||
eprintln!("input event channel disconnected"); | ||
return; | ||
} | ||
pub fn next() -> io::Result<Option<KeyEvent>> { | ||
if event::poll(Duration::from_secs(1))? { | ||
match event::read()? { | ||
Event::Key(key) if key.kind == KeyEventKind::Press => return Ok(Some(key)), | ||
_ => {} | ||
} | ||
}); | ||
|
||
InputEvents { rx } | ||
} | ||
|
||
pub fn next(&mut self) -> Result<Option<Key>, RecvTimeoutError> { | ||
match self.rx.recv_timeout(Duration::from_secs(1)) { | ||
Ok(key) => Ok(Some(key)), | ||
Err(RecvTimeoutError::Timeout) => Ok(None), | ||
Err(e) => Err(e), | ||
} | ||
Ok(None) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use tui::widgets::ListState; | ||
use ratatui::widgets::ListState; | ||
|
||
pub struct Selector(usize, ListState); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,7 +276,7 @@ macro_rules! into_f64 { | |
}; | ||
} | ||
|
||
pub(self) use into_f64; | ||
use into_f64; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
[toolchain] | ||
channel = "1.70.0" | ||
# Note that this is greater than the MSRV of the workspace (1.70) due to metrics-observer needing | ||
# 1.74, while all the other crates only require 1.70. See | ||
# https://github.com/metrics-rs/metrics/pull/505#discussion_r1724092556 for more information. | ||
channel = "1.74.0" |