diff options
| author | duckyriley <[email protected]> | 2026-11-23 21:21:22 +0800 |
|---|---|---|
| committer | duckyriley <[email protected]> | 2026-11-23 21:21:22 +0800 |
| commit | 9ef7ba021629c9fa3e111798c61b35a02dfaae20 (patch) | |
| tree | 599fad203f9588be81eb71a79dd57a67e6c01b26 | |
| parent | d5901ef3de6c3c8c60e7aca7610ab5eb2d4bbaa5 (diff) | |
| download | ducky-9ef7ba021629c9fa3e111798c61b35a02dfaae20.tar.gz ducky-9ef7ba021629c9fa3e111798c61b35a02dfaae20.zip | |
Fix inactive tab closing and add Lua shortcut actions and themes
| -rw-r--r-- | assets/config.lua | 46 | ||||
| -rw-r--r-- | assets/screenshots/customized.png | bin | 17235 -> 20920 bytes | |||
| -rw-r--r-- | assets/screenshots/ducky.png | bin | 21853 -> 24654 bytes | |||
| -rw-r--r-- | assets/screenshots/ember.png | bin | 0 -> 24654 bytes | |||
| -rw-r--r-- | assets/screenshots/glacier.png | bin | 0 -> 21149 bytes | |||
| -rw-r--r-- | assets/screenshots/paper.png | bin | 0 -> 24687 bytes | |||
| -rw-r--r-- | assets/shell.bash | 10 | ||||
| -rw-r--r-- | assets/themes/ember.lua | 13 | ||||
| -rw-r--r-- | assets/themes/glacier.lua | 13 | ||||
| -rw-r--r-- | assets/themes/paper.lua | 13 | ||||
| -rwxr-xr-x | build.sh | 5 | ||||
| -rw-r--r-- | readme.md | 41 | ||||
| -rw-r--r-- | src/config.rs | 111 | ||||
| -rw-r--r-- | src/main.rs | 165 |
14 files changed, 327 insertions, 90 deletions
diff --git a/assets/config.lua b/assets/config.lua index 65de5ea..64a0f39 100644 --- a/assets/config.lua +++ b/assets/config.lua @@ -1,21 +1,32 @@ --- Ducky runs this file on startup; Ctrl+Shift+R reloads it. +-- Ducky runs this file on startup; Ctrl+R reloads it. -- Full Lua 5.4 is available. Only run scripts you trust. --- Try the bundled theme after installation: return require('themes.lagoon') +-- Your appearance is editable here; bundled themes: ember, glacier, paper, lagoon. -- You can compute settings with Lua and require modules beside this file. local home = os.getenv('HOME') return { font = 'JetBrainsMono Nerd Font Mono', - font_size = 15, - line_height = 21, - padding = 26, - background = '#141218', - foreground = '#ded7e8', - accent = '#c4a7e7', - surface = '#211d29', - muted = '#82758f', - border = '#393041', + font_size = 16, + line_height = 24, + padding = 30, + background = '#171411', + foreground = '#dfd1bb', + accent = '#e7ad72', + surface = '#29231c', + muted = '#8d7a66', + border = '#49382a', show_status_bar = true, - status_bar_toggle = 'ctrl-shift-b', + -- GPUI keystroke -> application action. Remove or remap any entry. + shortcuts = { + ['ctrl-t']='new_tab', ['ctrl-w']='close_tab', + ['ctrl-c']='copy', ['ctrl-v']='paste', ['ctrl-alt-c']='interrupt', + ['ctrl-r']='reload', ['ctrl-b']='toggle_status', + ['ctrl-tab']='next_tab', ['ctrl-shift-tab']='previous_tab', + ['ctrl-=']='font_larger', ['ctrl--']='font_smaller', + ['shift-pageup']='scroll_up', ['shift-pagedown']='scroll_down', + ['alt-1']='tab:1', ['alt-2']='tab:2', ['alt-3']='tab:3', + ['alt-4']='tab:4', ['alt-5']='tab:5', ['alt-6']='tab:6', + ['alt-7']='tab:7', ['alt-8']='tab:8', ['alt-9']='tab:9', ['alt-0']='tab:10', + }, width = 1100, height = 720, scrollback = 10000, @@ -24,17 +35,14 @@ return { cwd = home, env = { COLORTERM = 'truecolor' }, -- Send any command or escape sequence using a custom shortcut. - -- Keystrokes use GPUI syntax: ctrl-shift-g, alt-h, etc. + -- Keystrokes use GPUI syntax: ctrl-g, alt-h, etc. bindings = { - ['ctrl-shift-g'] = 'git status\r', - ['ctrl-shift-h'] = 'cd ~\r', + ['ctrl-g'] = 'git status\r', + ['ctrl-h'] = 'cd ~\r', }, -- Palette indices 0..15 (normal and bright ANSI colors). palette = { - '#211d29', '#eb8b9c', '#a6d5b0', '#e8c997', - '#9bbae8', '#c4a7e7', '#97d5cf', '#d4cbdc', - '#71657e', '#f5a5b6', '#c1e7c8', '#f2dbb8', - '#b8d1f4', '#dec4f4', '#b5e7e1', '#f1eaf6', + '#29231c', '#d98375', '#b1bd8b', '#e4c387', '#a1b5b1', '#e7ad72', '#9ec5b4', '#dfd1bb', '#877364', '#eba293', '#c9d3a8', '#f0d6a6', '#bed0c9', '#f1c69d', '#bcdfcd', '#f4e9d7' }, -- Optional startup customization (for example require your own modules). -- startup = 'printf "Welcome to Ducky\\n"\r', diff --git a/assets/screenshots/customized.png b/assets/screenshots/customized.png Binary files differindex 9fac024..ca06364 100644 --- a/assets/screenshots/customized.png +++ b/assets/screenshots/customized.png diff --git a/assets/screenshots/ducky.png b/assets/screenshots/ducky.png Binary files differindex 523a943..ceadd5f 100644 --- a/assets/screenshots/ducky.png +++ b/assets/screenshots/ducky.png diff --git a/assets/screenshots/ember.png b/assets/screenshots/ember.png Binary files differnew file mode 100644 index 0000000..ceadd5f --- /dev/null +++ b/assets/screenshots/ember.png diff --git a/assets/screenshots/glacier.png b/assets/screenshots/glacier.png Binary files differnew file mode 100644 index 0000000..32e178b --- /dev/null +++ b/assets/screenshots/glacier.png diff --git a/assets/screenshots/paper.png b/assets/screenshots/paper.png Binary files differnew file mode 100644 index 0000000..f73eb15 --- /dev/null +++ b/assets/screenshots/paper.png diff --git a/assets/shell.bash b/assets/shell.bash index d36d1e5..fc4404b 100644 --- a/assets/shell.bash +++ b/assets/shell.bash @@ -3,12 +3,12 @@ _ducky_prompt() { local status=$? branch branch=$(git symbolic-ref --quiet --short HEAD 2>/dev/null) || branch='' - PS1=$'\n\[\e[38;2;196;167;231m\]╭─ ' - PS1+='\[\e[38;2;222;215;232m\]\w' + PS1=$'\n\[\e[35m\]╭─ ' + PS1+='\[\e[0m\]\w' _ducky_branch=$branch - [[ -n $branch ]] && PS1+=' \[\e[38;2;151;213;207m\]⎇ ${_ducky_branch}' - [[ $status -ne 0 ]] && PS1+=" \[\e[38;2;235;139;156m\]${status}" - PS1+=$'\n\[\e[38;2;196;167;231m\]╰─❯ \[\e[0m\]' + [[ -n $branch ]] && PS1+=' \[\e[36m\]⎇ ${_ducky_branch}' + [[ $status -ne 0 ]] && PS1+=" \[\e[31m\]${status}" + PS1+=$'\n\[\e[35m\]╰─❯ \[\e[0m\]' } # Keep other prompt hooks, then set Ducky's prompt last. if declare -p PROMPT_COMMAND 2>/dev/null | grep -q 'declare -a'; then diff --git a/assets/themes/ember.lua b/assets/themes/ember.lua new file mode 100644 index 0000000..e7bb1dc --- /dev/null +++ b/assets/themes/ember.lua @@ -0,0 +1,13 @@ +-- Apply from config.lua with require('themes.ember'). +return { + background = '#171411', + foreground = '#dfd1bb', + surface = '#29231c', + accent = '#e7ad72', + muted = '#8d7a66', + border = '#49382a', + font_size = 16, + line_height = 24, + padding = 30, + palette = { '#29231c', '#d98375', '#b1bd8b', '#e4c387', '#a1b5b1', '#e7ad72', '#9ec5b4', '#dfd1bb', '#877364', '#eba293', '#c9d3a8', '#f0d6a6', '#bed0c9', '#f1c69d', '#bcdfcd', '#f4e9d7' }, +} diff --git a/assets/themes/glacier.lua b/assets/themes/glacier.lua new file mode 100644 index 0000000..358d2a2 --- /dev/null +++ b/assets/themes/glacier.lua @@ -0,0 +1,13 @@ +-- Apply from config.lua with require('themes.glacier'). +return { + background = '#101923', + foreground = '#d6e6f0', + surface = '#1b2c3b', + accent = '#89c9ef', + muted = '#6d8ca4', + border = '#2e495e', + font_size = 15, + line_height = 23, + padding = 28, + palette = { '#1b2c3b', '#ed8e9c', '#a5d6bd', '#e5cf9b', '#89c9ef', '#a6bdf3', '#87ddd7', '#d6e6f0', '#66859c', '#f3a8b2', '#bee5d0', '#f1dfb5', '#acdfff', '#c3d2ff', '#aff2e9', '#f2f9ff' }, +} diff --git a/assets/themes/paper.lua b/assets/themes/paper.lua new file mode 100644 index 0000000..96802d2 --- /dev/null +++ b/assets/themes/paper.lua @@ -0,0 +1,13 @@ +-- Apply from config.lua with require('themes.paper'). +return { + background = '#eee8dc', + foreground = '#403b34', + surface = '#e1d8c8', + accent = '#9c5738', + muted = '#8a7c68', + border = '#cbbb9f', + font_size = 16, + line_height = 25, + padding = 32, + palette = { '#403b34', '#a9433f', '#57734c', '#966d29', '#466c89', '#9c5738', '#367b75', '#d8cebc', '#8a7c68', '#bf5c50', '#6b895c', '#b98c3c', '#6288a4', '#b67550', '#57948d', '#faf6ed' }, +} @@ -20,7 +20,10 @@ install -d "$bin_dir" "$config_dir" install -m 755 "target/$profile/ducky" "$bin_dir/ducky" install -d "$config_dir/themes" if [[ ! -e $config_dir/shell.bash ]]; then install -m 644 assets/shell.bash "$config_dir/shell.bash"; fi -if [[ ! -e $config_dir/themes/lagoon.lua ]]; then install -m 644 assets/themes/lagoon.lua "$config_dir/themes/lagoon.lua"; fi +for theme in assets/themes/*.lua; do + theme_name=${theme##*/} + if [[ ! -e $config_dir/themes/$theme_name ]]; then install -m 644 "$theme" "$config_dir/themes/$theme_name"; fi +done if [[ $platform == Linux ]]; then install -d "$data_dir/applications" "$data_dir/icons/hicolor/scalable/apps" install -m 644 assets/ducky.svg "$data_dir/icons/hicolor/scalable/apps/dev.ducky.shell.svg" @@ -86,18 +86,47 @@ cd ducky  - + + + # Features -- Default violet theme, JetBrainsMono Nerd Font Mono, and a two-line Bash prompt with Git branch and exit status. Install the font for the matching appearance. +- Default warm amber theme, JetBrainsMono Nerd Font Mono, and a two-line Bash prompt with Git branch and exit status. Install the font for the matching appearance. - Native Rust + GPUI rendering; PTY-backed login shell, ANSI/256/truecolor, alternate screen, Unicode and IME input. - Integrated draggable tab bar with window controls and resize edges. -- `Ctrl+Shift+B` hides or restores the bottom bar; set `show_status_bar = false` in Lua to keep it hidden at launch. Change `status_bar_toggle` to customize the shortcut. -- Tabs: `Ctrl+Shift+T` opens, `Ctrl+Shift+W` closes, `Ctrl+Tab` cycles. -- Mouse selection, `Ctrl+Shift+C` copies selection (or visible screen), `Ctrl+Shift+V` pastes with bracketed-paste support. +- `Ctrl+B` hides or restores the bottom bar; set `show_status_bar = false` in Lua to keep it hidden at launch. Remap `toggle_status` in the Lua `shortcuts` table to change the shortcut. +- Tabs: `Ctrl+T` opens, `Ctrl+W` closes the active tab, `Alt+1`–`Alt+9` selects a tab (`Alt+0` selects tab 10), and `Ctrl+Tab` cycles. Close any tab with its × button or middle-click. +- `Ctrl+C` copies without interrupting the foreground process. `Ctrl+Alt+C` sends the terminal interrupt. +- Mouse selection, `Ctrl+C` copies selection (or visible screen), `Ctrl+V` pastes with bracketed-paste support. - Mouse-wheel scrollback and `Shift+PageUp` / `Shift+PageDown`. - Lua 5.4 configuration in your platform's config directory under `ducky/config.lua` (paths above), created on first launch. Lua modules can live alongside it. - Customize fonts, spacing, colors, ANSI palette, window dimensions, shell arguments, environment, startup commands, and shortcuts. The generated config contains examples. Lua scripts run with your user permissions. -- `Ctrl+Shift+R` reloads appearance and bindings; new tabs pick up shell/environment changes. `Ctrl+Shift++` / `Ctrl+Shift+-` changes font size. +- `Ctrl+R` reloads appearance and bindings; new tabs pick up shell/environment changes. `Ctrl+=` / `Ctrl+-` changes font size. - `ducky --check-config` validates Lua; `ducky --config-dir` prints its location. + +Application shortcuts are configured in Lua separately from raw terminal byte bindings: + +```lua +shortcuts = { + ['ctrl-t'] = 'new_tab', + ['ctrl-w'] = 'close_tab', + ['ctrl-c'] = 'copy', + ['ctrl-v'] = 'paste', + ['ctrl-alt-c'] = 'interrupt', + ['ctrl-r'] = 'reload', + ['ctrl-b'] = 'toggle_status', + ['alt-1'] = 'tab:1', + ['alt-2'] = 'tab:2', + -- Also: next_tab, previous_tab, font_larger, font_smaller, scroll_up, scroll_down. +} +``` + +The `shortcuts` table replaces the default map when supplied. `bindings` sends raw strings and takes priority over application shortcuts. Press your reload shortcut after editing the config. + +Bundled themes: `ember`, `glacier`, `paper`, and `lagoon`. To apply a theme while keeping your other settings, use a local `config` table and end your Lua file with: + +```lua +for key, value in pairs(require('themes.glacier')) do config[key] = value end +return config +``` diff --git a/src/config.rs b/src/config.rs index c1b00ae..3532f80 100644 --- a/src/config.rs +++ b/src/config.rs @@ -16,7 +16,7 @@ pub struct Config { pub muted: u32, pub border: u32, pub show_status_bar: bool, - pub status_bar_toggle: String, + pub shortcuts: HashMap<String, String>, pub width: f32, pub height: f32, pub scrollback: usize, @@ -44,9 +44,51 @@ pub fn color(s: &str) -> Result<u32> { Ok(u32::from_str_radix(s, 16)?) } impl Config { + pub fn action_for(&self, key: &gpui::Keystroke) -> Option<String> { + self.shortcuts.iter().find_map(|(binding, action)| { + let parsed = gpui::Keystroke::parse(binding).ok()?; + (parsed.modifiers == key.modifiers && parsed.key.eq_ignore_ascii_case(&key.key)) + .then(|| action.clone()) + }) + } + pub fn shortcut(&self, action: &str) -> String { + let mut keys = self + .shortcuts + .iter() + .filter(|(_, a)| a.as_str() == action) + .map(|(k, _)| k.clone()) + .collect::<Vec<_>>(); + keys.sort(); + keys.first() + .map(|k| { + k.split('-') + .map(|part| match part { + "ctrl" => "Ctrl".into(), + "alt" => "Alt".into(), + "shift" => "Shift".into(), + s => s.to_uppercase(), + }) + .collect::<Vec<String>>() + .join("+") + }) + .unwrap_or_else(|| "unbound".into()) + } pub fn load() -> Result<Self> { let dir = directory(); std::fs::create_dir_all(&dir)?; + let themes = dir.join("themes"); + std::fs::create_dir_all(&themes)?; + for (name, source) in [ + ("ember", include_str!("../assets/themes/ember.lua")), + ("glacier", include_str!("../assets/themes/glacier.lua")), + ("paper", include_str!("../assets/themes/paper.lua")), + ("lagoon", include_str!("../assets/themes/lagoon.lua")), + ] { + let path = themes.join(format!("{name}.lua")); + if !path.exists() { + std::fs::write(path, source)?; + } + } let prompt = dir.join("shell.bash"); if !prompt.exists() { std::fs::write(&prompt, include_str!("../assets/shell.bash"))?; @@ -139,7 +181,7 @@ impl Config { .map_err(|e| anyhow::anyhow!(e.to_string()))?, )?, show_status_bar: get!("show_status_bar"), - status_bar_toggle: get!("status_bar_toggle"), + shortcuts: get!("shortcuts"), width: get!("width"), height: get!("height"), scrollback: get!("scrollback"), @@ -166,6 +208,32 @@ impl Config { "invalid font, spacing, window dimensions, scrollback, or palette (requires 16 colors)" ); } + for (key, action) in &c.shortcuts { + gpui::Keystroke::parse(key) + .map_err(|e| anyhow::anyhow!("invalid shortcut {key}: {e}"))?; + let valid = matches!( + action.as_str(), + "new_tab" + | "close_tab" + | "copy" + | "paste" + | "reload" + | "toggle_status" + | "interrupt" + | "next_tab" + | "previous_tab" + | "font_larger" + | "font_smaller" + | "scroll_up" + | "scroll_down" + ) || action + .strip_prefix("tab:") + .and_then(|s| s.parse::<usize>().ok()) + .is_some_and(|i| i > 0); + if !valid { + bail!("unknown shortcut action: {action}"); + } + } Ok(c) } } @@ -184,6 +252,45 @@ mod tests { assert_eq!(c.palette.len(), 16); } #[test] + fn lua_shortcuts_separate_copy_interrupt_and_tab_selection() { + let c = Config::parse(DEFAULT, std::path::Path::new("/tmp")).unwrap(); + for (key, action) in [ + ("ctrl-c", "copy"), + ("ctrl-alt-c", "interrupt"), + ("alt-4", "tab:4"), + ("ctrl-r", "reload"), + ] { + assert_eq!( + c.action_for(&gpui::Keystroke::parse(key).unwrap()) + .as_deref(), + Some(action) + ); + } + let custom = Config::parse( + "return {shortcuts={['alt-x']='copy'}}", + std::path::Path::new("/tmp"), + ) + .unwrap(); + assert_eq!( + custom + .action_for(&gpui::Keystroke::parse("alt-x").unwrap()) + .as_deref(), + Some("copy") + ); + assert!( + custom + .action_for(&gpui::Keystroke::parse("ctrl-c").unwrap()) + .is_none() + ); + assert!( + Config::parse( + "return {shortcuts={['alt-x']='typo'}}", + std::path::Path::new("/tmp") + ) + .is_err() + ); + } + #[test] fn prompt_path_uses_platform_config_directory() { let dir = std::path::Path::new("/Users/example/Library/Application Support/ducky"); let c = Config::parse(DEFAULT, dir).unwrap(); diff --git a/src/main.rs b/src/main.rs index f6a6dfb..f2e2165 100644 --- a/src/main.rs +++ b/src/main.rs @@ -80,13 +80,23 @@ impl Ducky { cx.notify(); } fn close_tab(&mut self, cx: &mut Context<Self>) { - self.tabs.remove(self.active); + self.close_tab_at(self.active, cx); + } + fn close_tab_at(&mut self, index: usize, cx: &mut Context<Self>) { + if index >= self.tabs.len() { + return; + } + let terminal = self.tabs.remove(index); + // Waiting for an old shell to exit must never stall GPUI's event loop. + std::thread::spawn(move || drop(terminal)); if self.tabs.is_empty() { cx.quit(); return; } - self.active = self.active.min(self.tabs.len() - 1); + self.active = active_after_close(self.active, index, self.tabs.len()); self.selection = None; + self.dragging = false; + self.composition.clear(); cx.notify(); } fn reload(&mut self, cx: &mut Context<Self>) { @@ -147,61 +157,59 @@ impl Ducky { } fn key(&mut self, event: &KeyDownEvent, window: &mut Window, cx: &mut Context<Self>) { let key = &event.keystroke; - let m = key.modifiers; - if key.unparse() == self.config.status_bar_toggle { - self.config.show_status_bar = !self.config.show_status_bar; - cx.notify(); + // User byte bindings can override application actions deliberately. + let stroke = key.unparse(); + if let Some(data) = self.config.bindings.get(&stroke).cloned() { + self.send(data.as_bytes(), cx); cx.stop_propagation(); return; } - if m.control && m.shift { - match key.key.to_lowercase().as_str() { - "t" => self.new_tab(cx), - "w" => self.close_tab(cx), - "r" => self.reload(cx), - "c" => self.copy(cx), - "v" => self.paste(cx), - "tab" => { + let action = self.config.action_for(key); + if let Some(action) = action { + match action.as_str() { + "new_tab" => self.new_tab(cx), + "close_tab" => self.close_tab(cx), + "copy" => self.copy(cx), + "paste" => self.paste(cx), + "reload" => self.reload(cx), + "toggle_status" => { + self.config.show_status_bar = !self.config.show_status_bar; + } + "interrupt" => self.send(&[3], cx), + "next_tab" => { + self.active = (self.active + 1) % self.tabs.len(); + self.selection = None; + } + "previous_tab" => { self.active = (self.active + self.tabs.len() - 1) % self.tabs.len(); self.selection = None; - cx.notify(); } - "=" | "+" => { + "font_larger" => { self.config.font_size = (self.config.font_size + 1.).min(48.); self.config.line_height = self.config.font_size * 1.4; - cx.notify(); } - "-" => { + "font_smaller" => { self.config.font_size = (self.config.font_size - 1.).max(8.); self.config.line_height = self.config.font_size * 1.4; - cx.notify(); } + "scroll_up" => self.tabs[self.active].scroll(20), + "scroll_down" => self.tabs[self.active].scroll(-20), _ => { - if let Some(data) = self.config.bindings.get(&key.unparse()).cloned() { - self.send(data.as_bytes(), cx); - } else { - return; + if let Some(index) = action + .strip_prefix("tab:") + .and_then(|s| s.parse::<usize>().ok()) + { + if index <= self.tabs.len() { + self.active = index - 1; + self.selection = None; + } } } } - cx.stop_propagation(); - return; - } - if m.control && key.key == "tab" { - self.active = (self.active + 1) % self.tabs.len(); - self.selection = None; - cx.notify(); - cx.stop_propagation(); - return; - } - if let Some(data) = self.config.bindings.get(&key.unparse()).cloned() { - self.send(data.as_bytes(), cx); - cx.stop_propagation(); - return; - } - if m.shift && (key.key == "pageup" || key.key == "pagedown") { - self.tabs[self.active].scroll(if key.key == "pageup" { 20 } else { -20 }); - cx.notify(); + if !self.tabs.is_empty() { + cx.notify(); + } + window.prevent_default(); cx.stop_propagation(); return; } @@ -365,6 +373,12 @@ impl Ducky { } } +fn active_after_close(active: usize, closed: usize, remaining: usize) -> usize { + active + .saturating_sub(usize::from(closed < active)) + .min(remaining.saturating_sub(1)) +} + fn key_bytes(key: &Keystroke, application: bool) -> Option<Vec<u8>> { let m = key.modifiers; let code = match key.key.as_str() { @@ -473,7 +487,38 @@ impl Render for Ducky { "" } )) - .on_click(cx.listener(move |this, _, _, cx| { + .child( + div() + .id(("close-tab", i)) + .size(px(18.)) + .rounded_sm() + .flex() + .items_center() + .justify_center() + .text_color(rgb(c.muted)) + .hover(|s| s.bg(rgb(c.border)).text_color(rgb(c.foreground))) + .child("×") + .on_mouse_down( + MouseButton::Left, + cx.listener(move |this, _, window, cx| { + cx.stop_propagation(); + window.prevent_default(); + this.close_tab_at(i, cx); + window.focus(&this.focus); + }), + ), + ) + .on_mouse_down( + MouseButton::Middle, + cx.listener(move |this, _, window, cx| { + cx.stop_propagation(); + window.prevent_default(); + this.close_tab_at(i, cx); + window.focus(&this.focus); + }), + ) + .on_click(cx.listener(move |this, _, window, cx| { + window.focus(&this.focus); this.active = i; this.selection = None; cx.notify(); @@ -486,11 +531,14 @@ impl Render for Ducky { .unwrap() .screen() .scrollback(); - let toggle = c - .status_bar_toggle - .replace('-', "+") - .replace("ctrl", "Ctrl") - .replace("shift", "Shift"); + let toggle = c.shortcut("toggle_status"); + let hints = format!( + "{} tab · {} copy · {} paste · {} reload", + c.shortcut("new_tab"), + c.shortcut("copy"), + c.shortcut("paste"), + c.shortcut("reload") + ); div() .size_full() .flex() @@ -690,15 +738,11 @@ impl Render for Ducky { }), )) .child( - div() - .flex() - .gap_4() - .child("Ctrl+Shift T tab · C copy · V paste · R reload") - .child( - div() - .text_color(rgb(c.accent)) - .child(format!("{toggle} hide")), - ), + div().flex().gap_4().child(hints).child( + div() + .text_color(rgb(c.accent)) + .child(format!("{toggle} hide")), + ), ), ) }) @@ -791,7 +835,7 @@ fn main() -> anyhow::Result<()> { } if args.iter().any(|s| s == "--help") { println!( - "Ducky Shell\n\nUsage: ducky [--check-config | --config-dir | --version]\n\nCtrl+Shift+T/W: new/close tab\nCtrl+Tab: next tab\nCtrl+Shift+C/V: copy/paste\nCtrl+Shift+R: reload Lua config\nCtrl+Shift+B: toggle status bar\nCtrl+Shift++/-: font size\nShift+PageUp/Down: scrollback" + "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" ); return Ok(()); } @@ -849,6 +893,13 @@ fn main() -> anyhow::Result<()> { mod tests { use super::*; #[test] + fn closing_earlier_or_inactive_tabs_preserves_selection() { + assert_eq!(active_after_close(3, 0, 3), 2); + assert_eq!(active_after_close(0, 2, 3), 0); + assert_eq!(active_after_close(2, 2, 2), 1); + assert_eq!(active_after_close(1, 1, 3), 1); + } + #[test] fn terminal_key_encoding() { assert_eq!( key_bytes(&Keystroke::parse("ctrl-c").unwrap(), false), |