diff --git a/README.md b/README.md index 6e989ba7..84ec203b 100644 --- a/README.md +++ b/README.md @@ -383,6 +383,10 @@ Arguments that can be passed to the `kitty_scrollback_nvim` Kitten defined in [k | status_window.style_simple | `boolean` | If true, use plaintext instead of nerd font icons | | status_window.autoclose | `boolean` | If true, close the status window after kitty-scrollback.nvim is ready | | status_window.show_timer | `boolean` | If true, show a timer in the status window while kitty-scrollback.nvim is loading | +| status_window.icons | `KsbStatusWindowIcons?` | Icons displayed in the status window | +| status_window.icons.kitty | `string` | kitty status window icon | +| status_window.icons.heart | `string` | heart string heart status window icon | +| status_window.icons.nvim | `string` | nvim status window icon | | paste_window | `KsbPasteWindowOpts?` | options for paste window that sends commands to Kitty | | paste_window.highlight_as_normal_win | `fun(): boolean?` | If function returns true, use Normal highlight group. If false, use NormalFloat | | paste_window.filetype | `string?` | The filetype of the paste window | @@ -402,15 +406,52 @@ Arguments that can be passed to the `kitty_scrollback_nvim` Kitten defined in [k ### Nerd Fonts By default, `kitty-scrollback.nvim` uses [Nerd Fonts](https://www.nerdfonts.com) in the status window. If you would like to -use ASCII instead, set the option `status_window.style_simple` to `true`. +use ASCII instead, set the option `status_window.style_simple` to `true`. + +> [!NOTE]\ +> Nerd Fonts release v3.1.0 added the Neovim icon! See **ksb_example_status_win_nvim** in [Advanced Configuration](https://github.com/mikesmithgh/kitty-scrollback.nvim/wiki/Advanced-Configuration) for a demo and example configuration. +> +> *The following example configuration sets a global kitty-scrollback.nvim configuration to use the neovim icon instead of vim icon* +> +> **kitty.conf** +> ```kitty +> action_alias kitty_scrollback_nvim kitten /Users/mike/gitrepos/kitty-scrollback.nvim/python/kitty_scrollback_nvim.py --nvim-args -u kitty-scrollback-nvim-kitten-config.lua +> ``` +> +> **kitty-scrollback-nvim-kitten-config.lua** +> ```lua +> -- I am still working on a better experience for configuring kitty-scrollback.nvim, but this works for now +> vim.opt.runtimepath:append(vim.fn.stdpath('data') .. '/lazy/kitty-scrollback.nvim') -- assuming lazy.nvim setup +> require('kitty-scrollback').setup({ +> global = function() +> return { +> status_window = { +> icons = { +> nvim = '', +> }, +> }, +> } +> end, +> }) +> ``` -- Status window with Nerd Fonts opts.status_window.style_simple = false -![style_simple_false](https://github.com/mikesmithgh/kitty-scrollback.nvim/assets/10135646/662bf132-0b39-4028-b69f-eb85fbb69b60) +- Status window with Nerd Fonts v3.1.0+ opts.status_window.icons.nvim = '' opts.status_window.style_simple = false +
+ status-win-icon-nvim +
+ +- Status window with Nerd Fonts < v3.1.0 opts.status_window.icons.nvim = '' opts.status_window.style_simple = false +
+ status-win-icon-vim +
- Status window with ASCII text opts.status_window.style_simple = true -![style_simple_true](https://github.com/mikesmithgh/kitty-scrollback.nvim/assets/10135646/c19a1869-e4e4-40fd-b619-fed771d0153f) +
+ status-win-icon-simple +
+ diff --git a/doc/kitty-scrollback.nvim.txt b/doc/kitty-scrollback.nvim.txt index bd3974c3..d9e73327 100644 --- a/doc/kitty-scrollback.nvim.txt +++ b/doc/kitty-scrollback.nvim.txt @@ -1,4 +1,4 @@ -*kitty-scrollback.nvim.txt* For NVIM v0.9+ Last change: 2023 November 24 +*kitty-scrollback.nvim.txt* For NVIM v0.9+ Last change: 2023 November 26 ============================================================================== Table of Contents *kitty-scrollback.nvim-table-of-contents* @@ -401,6 +401,14 @@ KITTY-SCROLLBACK.NVIM CONFIGURATION FILE ~ status_window.show_timer boolean If true, show a timer in the status window while kitty-scrollback.nvim is loading + status_window.icons KsbStatusWindowIcons? Icons displayed in the status window + + status_window.icons.kitty string kitty status window icon + + status_window.icons.heart string heart string heart status window icon + + status_window.icons.nvim string nvim status window icon + paste_window KsbPasteWindowOpts? options for paste window that sends commands to Kitty paste_window.highlight_as_normal_win fun(): boolean? If function returns true, use Normal highlight group. If @@ -468,6 +476,23 @@ in the status window. If you would like to use ASCII instead, set the option `status_window.style_simple` to `true`. + `ℹ` `NOTE` + Nerd Fonts release v3.1.0 added the Neovim icon! See + **ksb_example_status_win_nvim** in Advanced Configuration + + for a demo and example configuration. + _The following example configuration sets a global kitty-scrollback.nvim + configuration to use the neovim icon instead of vim icon_ + **kitty.conf** `kitty action_alias kitty_scrollback_nvim kitten + /Users/mike/gitrepos/kitty-scrollback.nvim/python/kitty_scrollback_nvim.py + --nvim-args -u kitty-scrollback-nvim-kitten-config.lua` + **kitty-scrollback-nvim-kitten-config.lua** `lua -- I am still working on a + better experience for configuring kitty-scrollback.nvim, but this works for now + vim.opt.runtimepath:append(vim.fn.stdpath('data') .. + '/lazy/kitty-scrollback.nvim') -- assuming lazy.nvim setup + require('kitty-scrollback').setup({ global = function() return { status_window + = { icons = { nvim = '', }, }, } end, })` + COMMANDS AND LUA API *kitty-scrollback.nvim-commands-and-lua-api* The API is available via the `kitty-scrollback.api` module. e.g., diff --git a/doc/kitty-scrollback.nvim_spec.txt b/doc/kitty-scrollback.nvim_spec.txt index 42f35a20..e76f14e0 100644 --- a/doc/kitty-scrollback.nvim_spec.txt +++ b/doc/kitty-scrollback.nvim_spec.txt @@ -61,14 +61,24 @@ KsbKittyGetText *kitty-scrollback.launch.KsbKittyGetText* {extent} (string|"screen"|"all"|"selection"|"first_cmd_output_on_screen"|"last_cmd_output"|"last_visited_cmd_output"|"last_non_empty_output") What text to get. The default of screen means all text currently on the screen. all means all the screen+scrollback and selection means the currently selected text. first_cmd_output_on_screen means the output of the first command that was run in the window on screen. last_cmd_output means the output of the last command that was run in the window. last_visited_cmd_output means the first command output below the last scrolled position via scroll_to_prompt. last_non_empty_output is the output from the last command run in the window that had some non empty output. The last four require shell_integration to be enabled. Choices: screen, all, first_cmd_output_on_screen, last_cmd_output, last_non_empty_output, last_visited_cmd_output, selection + *kitty-scrollback.launch.KsbStatusWindowIcons* +KsbStatusWindowIcons + + Fields: ~ + {kitty} (string) kitty status window icon, defaults to 󰄛 + {heart} (string) heart status window icon, defaults to 󰣐 + {nvim} (string) nvim status window icon, defaults to  + + *kitty-scrollback.launch.KsbStatusWindowOpts* KsbStatusWindowOpts Fields: ~ - {enabled} (boolean) If true, show status window in upper right corner of the screen - {style_simple} (boolean) If true, use plaintext instead of nerd font icons - {autoclose} (boolean) If true, close the status window after kitty-scrollback.nvim is ready - {show_timer} (boolean) If true, show a timer in the status window while kitty-scrollback.nvim is loading + {enabled} (boolean) If true, show status window in upper right corner of the screen + {style_simple} (boolean) If true, use plaintext instead of nerd font icons + {autoclose} (boolean) If true, close the status window after kitty-scrollback.nvim is ready + {show_timer} (boolean) If true, show a timer in the status window while kitty-scrollback.nvim is loading + {icons} (KsbStatusWindowIcons) Icons displayed in the status window, defaults to 󰄛 󰣐  KsbWinOpts *kitty-scrollback.launch.KsbWinOpts* @@ -108,15 +118,15 @@ KsbPasteWindowOpts KsbOpts *kitty-scrollback.launch.KsbOpts* Fields: ~ - {callbacks} (KsbCallbacks|nil) fire and forget callback functions - {keymaps_enabled} (boolean|nil) if true, enabled all default keymaps - {restore_options} (boolean|nil) if true, restore options that were modified while processing the scrollback buffer - {highlight_overrides} (KsbHighlights|nil) kitty-scrollback.nvim highlight overrides - {status_window} (KsbStatusWindowOpts|nil) options for status window indicating that kitty-scrollback.nvim is ready - {paste_window} (KsbPasteWindowOpts|nil) options for paste window that sends commands to Kitty - {kitty_get_text} (KsbKittyGetText|nil) options passed to get-text when reading scrollback buffer, see `kitty @ get-text --help` - {checkhealth} (boolean|nil) if true execute :checkhealth kitty-scrollback and skip setup - {visual_selection_highlight_mode} (string|"darken"|"kitty"|"nvim"|"reverse") + {callbacks} (KsbCallbacks|nil) fire and forget callback functions + {keymaps_enabled} (boolean|nil) if true, enabled all default keymaps + {restore_options} (boolean|nil) if true, restore options that were modified while processing the scrollback buffer + {highlight_overrides} (KsbHighlights|nil) kitty-scrollback.nvim highlight overrides + {status_window} (KsbStatusWindowOpts|nil) options for status window indicating that kitty-scrollback.nvim is ready + {paste_window} (KsbPasteWindowOpts|nil) options for paste window that sends commands to Kitty + {kitty_get_text} (KsbKittyGetText|nil) options passed to get-text when reading scrollback buffer, see `kitty @ get-text --help` + {checkhealth} (boolean|nil) if true execute :checkhealth kitty-scrollback and skip setup + {visual_selection_highlight_mode} (string|"darken"|"kitty"|"nvim"|"reverse"|nil) M.setup({kitty_data_str}) *kitty-scrollback.launch.setup* diff --git a/lua/kitty-scrollback/configs/example.lua b/lua/kitty-scrollback/configs/example.lua index dae9bef2..9ec72fef 100644 --- a/lua/kitty-scrollback/configs/example.lua +++ b/lua/kitty-scrollback/configs/example.lua @@ -343,17 +343,19 @@ return { }, } end, - [prefix .. 'status_win_simple'] = function() + [prefix .. 'status_win_nvim'] = function() return { status_window = { - style_simple = true, + icons = { + nvim = '', + }, }, } end, - [prefix .. 'status_win_try_detect_nerd_fonts'] = function() + [prefix .. 'status_win_simple'] = function() return { status_window = { - style_simple = not require('kitty-scrollback.kitty_commands').try_detect_nerd_font(), + style_simple = true, }, } end, diff --git a/lua/kitty-scrollback/highlights.lua b/lua/kitty-scrollback/highlights.lua index e7ea5295..4735058c 100644 --- a/lua/kitty-scrollback/highlights.lua +++ b/lua/kitty-scrollback/highlights.lua @@ -76,7 +76,7 @@ local function highlight_definitions() }, KittyScrollbackNvimHeart = { default = true, - fg = '#ff6961', + fg = '#d55b54', }, KittyScrollbackNvimSpinner = { default = true, @@ -92,7 +92,7 @@ local function highlight_definitions() }, KittyScrollbackNvimVim = { default = true, - fg = '#188b25', + fg = '#87987e', }, KittyScrollbackNvimPasteWinNormal = { default = true, diff --git a/lua/kitty-scrollback/kitty_commands.lua b/lua/kitty-scrollback/kitty_commands.lua index 814dc993..46a72e34 100644 --- a/lua/kitty-scrollback/kitty_commands.lua +++ b/lua/kitty-scrollback/kitty_commands.lua @@ -5,7 +5,9 @@ local M = {} ---@type KsbPrivate local p -local opts ---@diagnostic disable-line: unused-local + +---@type KsbOpts +local opts M.setup = function(private, options) p = private @@ -306,6 +308,12 @@ M.open_kitty_loading_window = function(env) 'KITTY_SCROLLBACK_NVIM_STATUS_WINDOW_ENABLED=' .. tostring(opts.status_window.enabled), '--env', 'KITTY_SCROLLBACK_NVIM_SHOW_TIMER=' .. tostring(opts.status_window.show_timer), + '--env', + 'KITTY_SCROLLBACK_NVIM_KITTY_ICON=' .. tostring(opts.status_window.icons.kitty), + '--env', + 'KITTY_SCROLLBACK_NVIM_HEART_ICON=' .. tostring(opts.status_window.icons.heart), + '--env', + 'KITTY_SCROLLBACK_NVIM_NVIM_ICON=' .. tostring(opts.status_window.icons.nvim), }, vim.list_extend(env or {}, { p.kitty_data.ksb_dir .. '/python/loading.py' })) local ok, result = system_handle_error(kitty_cmd) if ok then @@ -344,33 +352,4 @@ M.send_text_to_clipboard = function(text) }) end -M.try_detect_nerd_font = function() - -- setup backports for v0.9 because try_detect_nerd_font can be called outside of standard setup flow - if vim.fn.has('nvim-0.10') <= 0 then - require('kitty-scrollback.backport').setup() - end - local has_nerd_font = false - vim - .system({ - 'kitty', - '--debug-font-fallback', - '--start-as', - 'minimized', - '--override', - 'shell=sh', - 'sh', - '-c', - 'kill $PPID', - }, { - text = true, - stderr = function(_, data) - if data and data:lower():match('.*nerd.*font.*') then - has_nerd_font = true - end - end, - }) - :wait() - return has_nerd_font -end - return M diff --git a/lua/kitty-scrollback/launch.lua b/lua/kitty-scrollback/launch.lua index bc5701d2..336ba2d4 100644 --- a/lua/kitty-scrollback/launch.lua +++ b/lua/kitty-scrollback/launch.lua @@ -72,11 +72,17 @@ local opts = {} ---@field clear_selection boolean If true, clear the selection in the matched window, if any. ---@field extent string | 'screen' | 'all' | 'selection' | 'first_cmd_output_on_screen' | 'last_cmd_output' | 'last_visited_cmd_output' | 'last_non_empty_output' What text to get. The default of screen means all text currently on the screen. all means all the screen+scrollback and selection means the currently selected text. first_cmd_output_on_screen means the output of the first command that was run in the window on screen. last_cmd_output means the output of the last command that was run in the window. last_visited_cmd_output means the first command output below the last scrolled position via scroll_to_prompt. last_non_empty_output is the output from the last command run in the window that had some non empty output. The last four require shell_integration to be enabled. Choices: screen, all, first_cmd_output_on_screen, last_cmd_output, last_non_empty_output, last_visited_cmd_output, selection +---@class KsbStatusWindowIcons +---@field kitty string kitty status window icon, defaults to 󰄛 +---@field heart string heart status window icon, defaults to 󰣐 +---@field nvim string nvim status window icon, defaults to  + ---@class KsbStatusWindowOpts ---@field enabled boolean If true, show status window in upper right corner of the screen ---@field style_simple boolean If true, use plaintext instead of nerd font icons ---@field autoclose boolean If true, close the status window after kitty-scrollback.nvim is ready ---@field show_timer boolean If true, show a timer in the status window while kitty-scrollback.nvim is loading +---@field icons KsbStatusWindowIcons Icons displayed in the status window, defaults to 󰄛 󰣐  ---@alias KsbWinOpts table @@ -102,7 +108,7 @@ local opts = {} ---@field paste_window KsbPasteWindowOpts|nil options for paste window that sends commands to Kitty ---@field kitty_get_text KsbKittyGetText|nil options passed to get-text when reading scrollback buffer, see `kitty @ get-text --help` ---@field checkhealth boolean|nil if true execute :checkhealth kitty-scrollback and skip setup ----@field visual_selection_highlight_mode string | 'darken' | 'kitty' | 'nvim' | 'reverse' +---@field visual_selection_highlight_mode string | 'darken' | 'kitty' | 'nvim' | 'reverse' | nil local default_opts = { callbacks = nil, keymaps_enabled = true, @@ -113,6 +119,11 @@ local default_opts = { style_simple = false, autoclose = false, show_timer = false, + icons = { + kitty = '󰄛', + heart = '󰣐', -- variants 󰣐 |  |  | ♥ |  | 󱢠 |  + nvim = '', -- variants  |  |  |  + }, }, paste_window = { highlight_as_normal_win = nil, @@ -258,8 +269,15 @@ M.setup = function(kitty_data_str) p.kitty_data = vim.fn.json_decode(kitty_data_str) load_requires() -- must be after p.kitty_data initialized + -- if a config named 'global' is found, that will be applied to all configurations regardless of prefix + -- if a config name is prefixed 'ksb_builtin_', only configs in configs/builtin.lua will be referenced. The one exception is the config named 'global' + -- if a config name is prefixed 'ksb_example_', only configs in configs/example.lua will be referenced. The one exception is the config named 'global' + -- if a config does not meet the above criteria, check if a user had defined a configuration with the given config name and use that + local config_name = p.kitty_data.kitty_scrollback_config or 'default' local config_source = require('kitty-scrollback') + local global_fn = config_source.configs['global'] + local global_opts = global_fn and global_fn(p.kitty_data) or {} if config_name:match('^ksb_builtin_.*') then config_source = require('kitty-scrollback.configs.builtin') end @@ -268,7 +286,8 @@ M.setup = function(kitty_data_str) end local config_fn = config_source.configs[config_name] local user_opts = config_fn and config_fn(p.kitty_data) or {} - opts = vim.tbl_deep_extend('force', default_opts, user_opts) + opts = vim.tbl_deep_extend('force', default_opts, global_opts, user_opts) + vim.print(opts.status_window.icons) ksb_backport.setup() ksb_health.setup(p, opts) diff --git a/lua/kitty-scrollback/windows.lua b/lua/kitty-scrollback/windows.lua index d7dd7089..5222f96b 100644 --- a/lua/kitty-scrollback/windows.lua +++ b/lua/kitty-scrollback/windows.lua @@ -136,14 +136,14 @@ end M.show_status_window = function() if opts.status_window.enabled then - local kitty_icon = '󰄛' - local love_icon = '' - local vim_icon = '' + local kitty_icon = opts.status_window.icons.kitty + local love_icon = opts.status_window.icons.heart + local nvim_icon = opts.status_window.icons.nvim local width = 9 if opts.status_window.style_simple then kitty_icon = 'kitty-scrollback.nvim' love_icon = '' - vim_icon = '' + nvim_icon = '' width = 25 end local popup_bufid = vim.api.nvim_create_buf(false, true) @@ -188,12 +188,12 @@ M.show_status_window = function() .. ' ' .. love_icon .. ' ' - .. vim_icon + .. nvim_icon .. ' ' vim.defer_fn(function() if spinner_icon == '' then vim.fn.timer_stop(status_window_timer) - fmt_msg = ' ' .. kitty_icon .. ' ' .. love_icon .. ' ' .. vim_icon .. ' ' + fmt_msg = ' ' .. kitty_icon .. ' ' .. love_icon .. ' ' .. nvim_icon .. ' ' local ok, _ = pcall(vim.api.nvim_win_get_config, popup_winid) if ok then vim.schedule(function() diff --git a/python/loading.py b/python/loading.py index aaa6ce0b..635ab45c 100755 --- a/python/loading.py +++ b/python/loading.py @@ -30,12 +30,16 @@ def env_to_fg_color(name): heart_color = env_to_fg_color('KITTY_SCROLLBACK_NVIM_HEART') spinner_color = env_to_fg_color('KITTY_SCROLLBACK_NVIM_SPINNER') kitty_color = env_to_fg_color('KITTY_SCROLLBACK_NVIM_KITTY') -vim_color = env_to_fg_color('KITTY_SCROLLBACK_NVIM_VIM') +nvim_color = env_to_fg_color('KITTY_SCROLLBACK_NVIM_VIM') reset = '\x1b[0m' -kitty = kitty_color + '󰄛' + reset -heart = heart_color + '' + reset -vim = vim_color + '' + reset +kitty_icon = os.environ.get('KITTY_SCROLLBACK_NVIM_KITTY_ICON', '󰄛') +heart_icon = os.environ.get('KITTY_SCROLLBACK_NVIM_HEART_ICON', '󰣐') +nvim_icon = os.environ.get('KITTY_SCROLLBACK_NVIM_NVIM_ICON', '') + +kitty = kitty_color + kitty_icon + reset +heart = heart_color + heart_icon + reset +vim = nvim_color + nvim_icon + reset if style_simple: spinner = itertools.cycle(['-', '-', '\\', '\\', '|', '|', '/', '/']) @@ -54,27 +58,28 @@ def env_to_fg_color(name): start = time.time() while True: - os.system('cls' if os.name == 'nt' else 'clear') - size = os.get_terminal_size(sys.__stdout__.fileno()) - time_elapsed = '' - if show_timer: - time_elapsed = '{:.1f}s'.format(time.time() - start) - time_progress = f'{time_color}{time_elapsed}{reset}' - if style_simple: - spin = spinner_color + next( - spinner) + reset + time_color + ' kitty-scrollback.nvim' + reset - ll = f'{time_progress} {spin} ' - line = ll.rjust(size.columns + (len(time_color + reset)) + - (len(time_color + reset)) + - (len(spinner_color + reset))) - - else: - spin = spinner_color + next(spinner) + reset - msg = f'{kitty} {heart} {vim} ' - line = f'{time_progress} {spin} {msg}'.rjust( - size.columns + (len(time_color + reset)) + - (len(spinner_color + reset)) + (len(kitty_color + reset)) + - (len(heart_color + reset)) + (len(vim_color + reset))) if status_window_enabled: + os.system('cls' if os.name == 'nt' else 'clear') + size = os.get_terminal_size(sys.__stdout__.fileno()) + time_elapsed = '' + if show_timer: + time_elapsed = '{:.1f}s'.format(time.time() - start) + time_progress = f'{time_color}{time_elapsed}{reset}' + if style_simple: + spin = spinner_color + next( + spinner + ) + reset + time_color + ' kitty-scrollback.nvim' + reset + ll = f'{time_progress} {spin} ' + line = ll.rjust(size.columns + (len(time_color + reset)) + + (len(time_color + reset)) + + (len(spinner_color + reset))) + + else: + spin = spinner_color + next(spinner) + reset + msg = f'{kitty} {heart} {vim} ' + line = f'{time_progress} {spin} {msg}'.rjust( + size.columns + (len(time_color + reset)) + + (len(spinner_color + reset)) + (len(kitty_color + reset)) + + (len(heart_color + reset)) + (len(nvim_color + reset))) print(line) time.sleep(0.08) diff --git a/scripts/init.lua b/scripts/init.lua index 6f4285f4..c4b66b41 100644 --- a/scripts/init.lua +++ b/scripts/init.lua @@ -6,7 +6,7 @@ vim.cmd('set packpath=' .. packpath) local mini_opts = { status_window = { - style_simple = not require('kitty-scrollback.kitty_commands').try_detect_nerd_font(), + style_simple = true, -- user may not have Nerd Fonts installed }, } require('kitty-scrollback').setup({