1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-22 12:51:31 +03:00

add wezterm show-keys command

This prints out the key and mouse assignments

refs: https://github.com/wez/wezterm/issues/2134
This commit is contained in:
Wez Furlong 2022-06-22 09:14:34 -07:00
parent 14282f99bc
commit 80671f29bd
7 changed files with 94 additions and 3 deletions

View File

@ -130,7 +130,7 @@ impl Default for Pattern {
}
/// A mouse event that can trigger an action
#[derive(Debug, Clone, PartialEq, Eq, Hash, FromDynamic, ToDynamic)]
#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Hash, FromDynamic, ToDynamic)]
pub enum MouseEventTrigger {
/// Mouse button is pressed. streak is how many times in a row
/// it was pressed.

View File

@ -50,6 +50,7 @@ As features stabilize some brief notes about them will accumulate here.
* RPM and DEB packages now install zsh and bash `wezterm` CLI completions
* Color schemes: [arcoiris](colorschemes/a/index.md#arcoiris), [duckbones](colorschemes/d/index.md#duckbones), [Grey-green](colorschemes/g/index.md#grey-green), [kanagawabones](colorschemes/k/index.md#kanagawabones), [Neon](colorschemes/n/index.md#neon), [neobones_dark](colorschemes/n/index.md#neobones_dark), [neobones_light](colorschemes/n/index.md#neobones_light), [seoulbones_dark](colorschemes/s/index.md#seoulbones_dark), [seoulbones_light](colorschemes/s/index.md#seoulbones_light), [tokyonight-day](colorschemes/t/index.md#tokyonight-day), [tokyonight-storm](colorschemes/t/index.md#tokyonight-storm), [tokyonight](colorschemes/t/index.md#tokyonight), [vimbones](colorschemes/v/index.md#vimbones), [zenbones](colorschemes/z/index.md#zenbones), [zenbones_dark](colorschemes/z/index.md#zenbones_dark), [zenbones_light](colorschemes/z/index.md#zenbones_light), [zenburned](colorschemes/z/index.md#zenburned), [zenwritten_dark](colorschemes/z/index.md#zenwritten_dark), [zenwritten_light](colorschemes/z/index.md#zenwritten_light)
* [wezterm.GLOBAL](config/lua/wezterm/GLOBAL.md) for persisting lua data across config reloads
* `wezterm show-keys` command to show key and mouse binding assignments [#2134](https://github.com/wez/wezterm/issues/2134)
#### Updated
* Bundled harfbuzz to 4.3.0

View File

@ -13,7 +13,7 @@ use wezterm_dynamic::{FromDynamic, ToDynamic};
pub use termwiz::input::{KeyCode, Modifiers as KeyModifiers};
#[cfg_attr(feature = "use_serde", derive(Deserialize, Serialize))]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, FromDynamic, ToDynamic)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash, FromDynamic, ToDynamic)]
pub enum MouseButton {
Left,
Middle,

View File

@ -334,3 +334,6 @@ pub struct LsFontsCommand {
#[clap(long = "text", conflicts_with = "list-system")]
pub text: Option<String>,
}
#[derive(Debug, Parser, Clone)]
pub struct ShowKeysCommand {}

View File

@ -4,7 +4,7 @@ use config::keyassignment::{
MouseEventTrigger, SelectionMode,
};
use config::ConfigHandle;
use std::collections::HashMap;
use std::collections::{BTreeMap, HashMap};
use std::time::Duration;
use wezterm_term::input::MouseButton;
use window::{KeyCode, Modifiers};
@ -264,4 +264,77 @@ impl InputMap {
.get(&(event, mods.remove_positional_mods()))
.cloned()
}
pub fn show_keys(&self) {
if let Some((key, mods, duration)) = &self.leader {
println!("Leader: {key:?} {mods:?} {duration:?}");
}
section_header("Default key table");
show_key_table(&self.keys.default);
println!();
let mut table_names = self.keys.by_name.keys().collect::<Vec<_>>();
table_names.sort();
for name in table_names {
if let Some(table) = self.keys.by_name.get(name) {
section_header(&format!("Key Table: {name}"));
show_key_table(table);
println!();
}
}
section_header("Mouse");
self.show_mouse();
}
fn show_mouse(&self) {
let ordered = self.mouse.iter().collect::<BTreeMap<_, _>>();
let mut trigger_width = 0;
let mut mod_width = 0;
for (trigger, mods) in ordered.keys() {
mod_width = mod_width.max(format!("{mods:?}").len());
trigger_width = trigger_width.max(format!("{trigger:?}").len());
}
for ((trigger, mods), action) in ordered {
let mods = if *mods == Modifiers::NONE {
String::new()
} else {
format!("{mods:?}")
};
let trigger = format!("{trigger:?}");
println!("\t{mods:mod_width$} {trigger:trigger_width$} -> {action:?}");
}
}
}
fn section_header(title: &str) {
let dash = "-".repeat(title.len());
println!("{title}");
println!("{dash}");
println!();
}
fn show_key_table(table: &config::keyassignment::KeyTable) {
let ordered = table.iter().collect::<BTreeMap<_, _>>();
let mut key_width = 0;
let mut mod_width = 0;
for (key, mods) in ordered.keys() {
mod_width = mod_width.max(format!("{mods:?}").len());
key_width = key_width.max(format!("{key:?}").len());
}
for ((key, mods), entry) in ordered {
let action = &entry.action;
let mods = if *mods == Modifiers::NONE {
String::new()
} else {
format!("{mods:?}")
};
let key = format!("{key:?}");
println!("\t{mods:mod_width$} {key:key_width$} -> {action:?}");
}
}

View File

@ -106,6 +106,9 @@ enum SubCommand {
#[clap(name = "ls-fonts", about = "Display information about fonts")]
LsFonts(LsFontsCommand),
#[clap(name = "show-keys", about = "Show key assignments")]
ShowKeys(ShowKeysCommand),
}
async fn async_run_ssh(opts: SshCommand) -> anyhow::Result<()> {
@ -712,6 +715,12 @@ fn maybe_show_configuration_error_window() {
}
}
fn run_show_keys(config: config::ConfigHandle, _cmd: &ShowKeysCommand) -> anyhow::Result<()> {
let map = crate::inputmap::InputMap::new(&config);
map.show_keys();
Ok(())
}
pub fn run_ls_fonts(config: config::ConfigHandle, cmd: &LsFontsCommand) -> anyhow::Result<()> {
use wezterm_font::parser::ParsedFont;
@ -1005,5 +1014,6 @@ fn run() -> anyhow::Result<()> {
SubCommand::Serial(serial) => run_serial(config, &serial),
SubCommand::Connect(connect) => run_mux_client(connect),
SubCommand::LsFonts(cmd) => run_ls_fonts(config, &cmd),
SubCommand::ShowKeys(cmd) => run_show_keys(config, &cmd),
}
}

View File

@ -76,6 +76,9 @@ enum SubCommand {
#[clap(name = "ls-fonts", about = "Display information about fonts")]
LsFonts(LsFontsCommand),
#[clap(name = "show-keys", about = "Show key assignments")]
ShowKeys(ShowKeysCommand),
#[clap(name = "cli", about = "Interact with experimental mux server")]
Cli(CliCommand),
@ -474,6 +477,7 @@ fn run() -> anyhow::Result<()> {
{
SubCommand::Start(_)
| SubCommand::LsFonts(_)
| SubCommand::ShowKeys(_)
| SubCommand::Ssh(_)
| SubCommand::Serial(_)
| SubCommand::Connect(_) => delegate_to_gui(saver),