-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use ratatui instead of tui-rs for the terminal UI #505
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, we're not bumping the project-wide MSRV just for a single binary crate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The MSRV of the other crates in the workspace doesn't change here - they can still be built with 1.70.0, but the version of the rust toolchain used to build the entire workspace does unfortunately need to change, or somehow just this this crate needs to be built with a later version. Putting a rust-toolchain.toml config in the metrics-observer works when building at that folder level, but building the workspace still uses the root rust version.
This was introduced due to the following problem:
The same error occurs when building the workspace with
cargo build --workspace
We could remove the metrics-observer from the workspace if that would help, but I think that might be sub optimal. Is there another way to get around this?
We could also use Ratatui 0.25.0, the last version which supported Rust 1.70. The delta is about 400 commits - which 30% of the total commits of the entire repo.
Incidentally Rust 1.74 is in almost the same place as Rust 1.70 was metrics last did a MSRV bump for metrics. It will be 7 versions behind current when 1.81 is released in 2 weeks time. Do you have any downstream crates that are constrained this far back?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point, and my mistake.
I agree it would be suboptimal, although still a reasonable approach.
This seems more suboptimal: switching to another replacement crate and not even getting on the latest version.
No, but maintaining a lower MSRV is just good practice (IMO) for foundational crates.
After reading through and thinking about it as I was writing all of this, I think leaving this change in place is fine, but we should update the
test-matrixed
CI step (here) to add the MSRV to the matrix of versions to test against. This will provide a counterbalance torust-toolchain.toml
no longer being pinned to the MSRV.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I added a test using rust 1.70, with a parameter to exclude testing the metrics-observer package.
I also added some docs showing why this is there (linking back to your comment here).