Skip to content
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

Feat help alt key binding #703

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ command line option.
| Command | Description | Default |
|------------------------|-------------------------------------------------|----------|
| `toggle-help` | Toggle help | `h` |
| `toggle-help-alt` | Toggle help (alternative binding) | `?` |
| `toggle-settings` | Toggle settings | `s` |
| `next-hop` | Select next hop | `down` |
| `previous-hop` | Select previous hop | `up` |
Expand Down
8 changes: 8 additions & 0 deletions src/config/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use strum::{AsRefStr, EnumString, EnumVariantNames};
#[derive(Debug, Clone, Copy)]
pub struct TuiBindings {
pub toggle_help: TuiKeyBinding,
pub toggle_help_alt: TuiKeyBinding,
pub toggle_settings: TuiKeyBinding,
pub previous_hop: TuiKeyBinding,
pub next_hop: TuiKeyBinding,
Expand Down Expand Up @@ -45,6 +46,7 @@ impl TuiBindings {
pub fn find_duplicates(&self) -> Vec<String> {
let (_, duplicates) = [
(self.toggle_help, TuiCommandItem::ToggleHelp),
(self.toggle_help_alt, TuiCommandItem::ToggleHelpAlt),
(self.toggle_settings, TuiCommandItem::ToggleSettings),
(self.previous_hop, TuiCommandItem::PreviousHop),
(self.next_hop, TuiCommandItem::NextHop),
Expand Down Expand Up @@ -104,6 +106,10 @@ impl From<(HashMap<TuiCommandItem, TuiKeyBinding>, ConfigBindings)> for TuiBindi
.get(&TuiCommandItem::ToggleHelp)
.or(cfg.toggle_help.as_ref())
.unwrap_or(&TuiKeyBinding::new(KeyCode::Char('h'))),
toggle_help_alt: *cmd_items
.get(&TuiCommandItem::ToggleHelpAlt)
.or(cfg.toggle_help_alt.as_ref())
.unwrap_or(&TuiKeyBinding::new(KeyCode::Char('?'))),
toggle_settings: *cmd_items
.get(&TuiCommandItem::ToggleSettings)
.or(cfg.toggle_settings.as_ref())
Expand Down Expand Up @@ -435,6 +441,8 @@ impl Display for TuiKeyBinding {
pub enum TuiCommandItem {
/// Toggle the help dialog.
ToggleHelp,
/// Alternative command to toggle the help dialog.
ToggleHelpAlt,
/// Toggle the settings dialog.
ToggleSettings,
/// Move down to the next hop.
Expand Down
1 change: 1 addition & 0 deletions src/config/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ pub struct ConfigThemeColors {
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
pub struct ConfigBindings {
pub toggle_help: Option<TuiKeyBinding>,
pub toggle_help_alt: Option<TuiKeyBinding>,
pub toggle_settings: Option<TuiKeyBinding>,
pub previous_hop: Option<TuiKeyBinding>,
pub next_hop: Option<TuiKeyBinding>,
Expand Down
4 changes: 3 additions & 1 deletion src/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ fn run_app<B: Backend>(
let bindings = &app.tui_config.bindings;
if app.show_help {
if bindings.toggle_help.check(key)
|| bindings.toggle_help_alt.check(key)
|| bindings.clear_selection.check(key)
|| bindings.quit.check(key)
{
Expand All @@ -88,7 +89,8 @@ fn run_app<B: Backend>(
} else if bindings.previous_hop.check(key) {
app.previous_settings_item();
}
} else if bindings.toggle_help.check(key) {
} else if bindings.toggle_help.check(key) || bindings.toggle_help_alt.check(key)
{
app.toggle_help();
} else if bindings.toggle_settings.check(key) {
app.toggle_settings();
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::fmt::{Display, Formatter};
#[derive(Debug, Clone, Copy)]
pub struct Bindings {
pub toggle_help: KeyBinding,
pub toggle_help_alt: KeyBinding,
pub toggle_settings: KeyBinding,
pub previous_hop: KeyBinding,
pub next_hop: KeyBinding,
Expand Down Expand Up @@ -38,6 +39,7 @@ impl From<TuiBindings> for Bindings {
fn from(value: TuiBindings) -> Self {
Self {
toggle_help: KeyBinding::from(value.toggle_help),
toggle_help_alt: KeyBinding::from(value.toggle_help_alt),
toggle_settings: KeyBinding::from(value.toggle_settings),
previous_hop: KeyBinding::from(value.previous_hop),
next_hop: KeyBinding::from(value.next_hop),
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/render/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const HELP_LINES: [&str; 20] = [
"{ & } - expand & collapse hosts to max and min",
"+ & - - zoom chart in and out",
"z - toggle AS information (if available)",
"h - toggle help",
"h or ? - toggle help",
"s - toggle settings",
"q - quit",
];
3 changes: 2 additions & 1 deletion src/frontend/render/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ fn format_binding_settings(app: &TuiApp) -> Vec<SettingsItem> {
let binds = &app.tui_config.bindings;
vec![
SettingsItem::new("toggle-help", format!("{}", binds.toggle_help)),
SettingsItem::new("toggle-help-alt", format!("{}", binds.toggle_help_alt)),
SettingsItem::new("toggle-settings", format!("{}", binds.toggle_settings)),
SettingsItem::new("next-hop", format!("{}", binds.next_hop)),
SettingsItem::new("previous-hop", format!("{}", binds.previous_hop)),
Expand Down Expand Up @@ -399,7 +400,7 @@ pub const SETTINGS_TABS: [(&str, usize); 6] = [
("Trace", 14),
("Dns", 3),
("GeoIp", 1),
("Bindings", 25),
("Bindings", 26),
("Theme", 27),
];

Expand Down
1 change: 1 addition & 0 deletions trippy-config-sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ map-info-panel-text-color = "gray"
# See https://github.com/fujiapple852/trippy#key-bindings-reference for details.
[bindings]
toggle-help = "h"
toggle-help-alt = "?"
toggle-settings = "s"
next-hop = "down"
previous-hop = "up"
Expand Down
Loading