From 98c943885a7efcac0bae732b9f4518c965f3668d Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Sun, 12 Apr 2026 17:38:20 -0600 Subject: [PATCH] feat: keymap-aware legend, live dap.status, debug-mode colorscheme MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three things the user caught in testing: 1. **Legend keymap-aware.** The cbar labels used hardcoded tails ("tep", "escend", "eturn") that assumed the default first-letter keys. If a user configured `keys.step_over = "n"` it would render as "(n)tep" — garbage. And disabled keys (`false` in config) still showed up because `keyof` fell back to the default letter. Now `keyof` returns nil for disabled actions (caller SKIPS rendering the entry) and `build_control_text` auto-picks between inline form "(s)tep" when the actual key matches the label's first letter and prefix form "(n) step" when it doesn't. Controls carry their full label ("step") plus the canonical default key — the render figures out which form fits the user's current keymap. 2. **dap.status() lag.** `dap.status()` polls a message queue one at a time per call (nvim-dap/lua/dap/progress.lua:50). We were only polling on event_stopped/continued/terminated/etc., so queued state strings drained behind reality — user saw "Running" when already paused, "All threads stopped" one step late, etc. Now we also subscribe to the `User DapProgressUpdate` autocmd that dap fires on EVERY status update, keeping the bar in sync. 3. **Debug-mode colorscheme.** New `config.opts.colorscheme` option (default nil). If set to a string, M.enter switches to it BEFORE define_highlights (so our TurboDebug* groups derive from the new theme's colors); M.exit restores the previous `vim.g.colors_name`. --- lua/turbo-debug/config.lua | 6 ++ lua/turbo-debug/mode.lua | 133 ++++++++++++++++++++++++++++--------- 2 files changed, 106 insertions(+), 33 deletions(-) diff --git a/lua/turbo-debug/config.lua b/lua/turbo-debug/config.lua index 492fa4b..66c712d 100644 --- a/lua/turbo-debug/config.lua +++ b/lua/turbo-debug/config.lua @@ -62,6 +62,12 @@ M.defaults = { -- sidebar position: "left" (default) or "right" sidebar = "left", + -- Optional colorscheme to switch to while debug mode is active. + -- `nil` (default) keeps the user's current colorscheme. Any other + -- string value is passed directly to `:colorscheme`. On M.exit the + -- previous colorscheme is restored. + colorscheme = nil, + -- highlight the active dapui pane's border/separator vs. dim inactive panes active_window_highlight = true, diff --git a/lua/turbo-debug/mode.lua b/lua/turbo-debug/mode.lua index 0a04f55..84dbb2f 100644 --- a/lua/turbo-debug/mode.lua +++ b/lua/turbo-debug/mode.lua @@ -43,6 +43,13 @@ local last_dapui_total_height = nil -- color. Restored byte-for-byte on M.exit. local saved_winsep_hl = nil +-- The user's colorscheme at M.enter time, saved only if `config.opts. +-- colorscheme` is set and the current colorscheme differs. Restored on +-- M.exit. Lets the user pin a distinct theme for debug sessions (e.g. a +-- high-contrast theme for reading register dumps) without permanently +-- switching their editor. +local saved_colorscheme = nil + local dapui_initialized = false local vt_initialized = false @@ -306,29 +313,53 @@ local function action(name) return function() local a = M.actions(); if a[name] then a[name]() end end end +-- Returns the user's configured key for an action, or the fallback default +-- when the user hasn't overridden it. Returns nil when the action is +-- explicitly disabled (set to `false` in config.opts.keys) — callers should +-- SKIP rendering a legend entry for that action entirely, since the modal +-- keymap install path at M._install_for_buf also skips it. local function keyof(name, fallback) local k = config.opts.keys[name] - if type(k) == "string" then return k end + if k == false then return nil end + if type(k) == "string" and k ~= "" then return k end return fallback end --- Build a label's byte-level representation. --- Format: " ()[ ]" --- e.g. ` (s)tep over` with `over` styled italic. +-- Build a control label's byte-level representation. +-- +-- Picks between two forms based on whether the user's actual key matches +-- the first letter of the label (case-insensitive): +-- inline: " ()[ ]" e.g. "(s)tep over" +-- prefix: " ()