-
-
Notifications
You must be signed in to change notification settings - Fork 300
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
fix(ui): upgrade tui to latest version and fix breaking changes #190
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,8 @@ use ::tui::backend::Backend; | |
use ::tui::layout::{Alignment, Rect}; | ||
use ::tui::style::{Modifier, Style}; | ||
use ::tui::terminal::Frame; | ||
use ::tui::widgets::{Paragraph, Text, Widget}; | ||
use ::tui::text::Span; | ||
use ::tui::widgets::Paragraph; | ||
|
||
pub struct HelpText { | ||
pub paused: bool, | ||
|
@@ -20,34 +21,31 @@ const TEXT_TAB_TIP: &str = " Use <TAB> to rearrange tables."; | |
|
||
impl HelpText { | ||
pub fn render(&self, frame: &mut Frame<impl Backend>, rect: Rect) { | ||
let text = { | ||
let pause_content = if self.paused { | ||
TEXT_WHEN_PAUSED | ||
} else { | ||
TEXT_WHEN_NOT_PAUSED | ||
}; | ||
|
||
let dns_content = if rect.width <= FIRST_WIDTH_BREAKPOINT { | ||
"" | ||
} else if self.show_dns { | ||
TEXT_WHEN_DNS_SHOWN | ||
} else { | ||
TEXT_WHEN_DNS_NOT_SHOWN | ||
}; | ||
let pause_content = if self.paused { | ||
TEXT_WHEN_PAUSED | ||
} else { | ||
TEXT_WHEN_NOT_PAUSED | ||
}; | ||
|
||
let tab_text = if rect.width <= SECOND_WIDTH_BREAKPOINT { | ||
"" | ||
} else { | ||
TEXT_TAB_TIP | ||
}; | ||
let dns_content = if rect.width <= FIRST_WIDTH_BREAKPOINT { | ||
"" | ||
} else if self.show_dns { | ||
TEXT_WHEN_DNS_SHOWN | ||
} else { | ||
TEXT_WHEN_DNS_NOT_SHOWN | ||
}; | ||
|
||
[Text::styled( | ||
format!("{}{}{}", pause_content, tab_text, dns_content), | ||
Style::default().modifier(Modifier::BOLD), | ||
)] | ||
let tab_text = if rect.width <= SECOND_WIDTH_BREAKPOINT { | ||
"" | ||
} else { | ||
TEXT_TAB_TIP | ||
}; | ||
Paragraph::new(text.iter()) | ||
.alignment(Alignment::Left) | ||
.render(frame, rect); | ||
|
||
let text = Span::styled( | ||
format!("{}{}{}", pause_content, tab_text, dns_content), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sticking strings together in Rust always gives me a bit of grief, but I think this also works here: [pause_content, tab_text, dns_content].concat(), To me it seems a tiny bit cleaner and is, apparently, about 3x faster because it can pre-compute the size of the final string I think. We are talking nanoseconds though, so it really doesn't matter and is a matter of style I think :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aha, good to know - thanks! I made the change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw, @TheLostLambda - I sent you an email on a different subject. Mentioning it here because I remember there were some spam-filtering issues between us in the past. :) |
||
Style::default().add_modifier(Modifier::BOLD), | ||
); | ||
let paragraph = Paragraph::new(text).alignment(Alignment::Left); | ||
frame.render_widget(paragraph, rect); | ||
} | ||
} |
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.
We should be able to change this to 0.12 without breaking anything. I've given it a test on my machine and no breaking API changes have been made since 0.10 I don't think.