diff options
Diffstat (limited to '')
| -rw-r--r-- | src/main.rs | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs index f2e2165..c5494f4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -158,15 +158,15 @@ impl Ducky { fn key(&mut self, event: &KeyDownEvent, window: &mut Window, cx: &mut Context<Self>) { let key = &event.keystroke; // User byte bindings can override application actions deliberately. - let stroke = key.unparse(); - if let Some(data) = self.config.bindings.get(&stroke).cloned() { + if let Some(data) = self.config.bytes_for(key).map(str::to_owned) { self.send(data.as_bytes(), cx); + window.prevent_default(); cx.stop_propagation(); return; } let action = self.config.action_for(key); if let Some(action) = action { - match action.as_str() { + match action { "new_tab" => self.new_tab(cx), "close_tab" => self.close_tab(cx), "copy" => self.copy(cx), @@ -381,6 +381,9 @@ fn active_after_close(active: usize, closed: usize, remaining: usize) -> usize { fn key_bytes(key: &Keystroke, application: bool) -> Option<Vec<u8>> { let m = key.modifiers; + if config::MACOS && m.platform { + return None; + } let code = match key.key.as_str() { "enter" => "\r", "backspace" => "\x7f", @@ -834,8 +837,10 @@ fn main() -> anyhow::Result<()> { return Ok(()); } if args.iter().any(|s| s == "--help") { + let primary = config::SHORTCUT_MODIFIER; + let alt = config::ALT_MODIFIER; println!( - "Ducky Shell\n\nUsage: ducky [--check-config | --config-dir | --version]\n\nCtrl+T/W: new/close tab\nAlt+1..9 / Alt+0: select tab\nCtrl+Tab: next tab\nCtrl+C/V: copy/paste\nCtrl+Alt+C: terminal interrupt\nCtrl+R: reload Lua config\nCtrl+B: toggle status bar\nCtrl+=/-: font size\nShift+PageUp/Down: scrollback" + "Ducky Shell\n\nUsage: ducky [--check-config | --config-dir | --version]\n\n{primary}+T/W: new/close tab\n{alt}+1..9 / {alt}+0: select tab\nCtrl+Tab / Ctrl+Shift+Tab: next/previous tab\n{primary}+C/V: copy/paste\n{primary}+{alt}+C: terminal interrupt\n{primary}+R: reload Lua config\n{primary}+B: toggle status bar\n{primary}+=/-: font size\nShift+PageUp/Down: scrollback" ); return Ok(()); } @@ -905,6 +910,12 @@ mod tests { key_bytes(&Keystroke::parse("ctrl-c").unwrap(), false), Some(vec![3]) ); + if config::MACOS { + assert_eq!( + key_bytes(&Keystroke::parse("cmd-enter").unwrap(), false), + None + ); + } assert_eq!( key_bytes(&Keystroke::parse("up").unwrap(), true), Some(b"\x1bOA".to_vec()) |