Commit 9ed2826

HPCesia <me@hpcesia.com>
2025-05-31 17:21:14
feat(app): WezTerm config files
1 parent 4f4ce02
Changed files (4)
home
home/base/gui/terminals/wezterm/config/module/appearance.lua
@@ -0,0 +1,129 @@
+local wezterm = require 'wezterm'
+local module = {}
+
+module.status_override = nil
+
+--- 获取当前是否为暗黑模式
+--- @return boolean
+function is_dark_mode()
+    if wezterm.gui then
+        return wezterm.gui.get_appearance():find("Dark")
+    end
+    return true
+end
+
+-- 绘制右侧状态栏
+function draw_right_status(window)
+    -- 默认显示主机名
+    local center_text = wezterm.hostname()
+    -- Leader 键按下时进行提示
+    if module.status_override ~= nil then
+        center_text = module.status_override
+    elseif window:leader_is_active() then
+        center_text = 'Leader Key'
+    end
+
+    -- 实心左箭头符号
+    local SOLID_LEFT_ARROW = utf8.char(0xe0b2)
+
+    -- 获取当前窗口的配置,并从中获取配色方案
+    local color_scheme     = window:effective_config().resolved_palette
+    local bg               = color_scheme.background
+    local fg               = color_scheme.foreground
+
+    -- 获取当前窗口顶栏配色
+    local frame_scheme     = window:effective_config().window_frame
+    local tbar_inact_bg    = frame_scheme.inactive_titlebar_bg
+    local tbar_act_bg      = frame_scheme.active_titlebar_bg
+    local tbar_bg          = ''
+    if window:is_focused() then
+        tbar_bg = tbar_act_bg
+    else
+        tbar_bg = tbar_inact_bg
+    end
+
+    local right_status = {
+        { Background = { Color = 'none' } },
+        { Foreground = { Color = bg } },
+        { Text = SOLID_LEFT_ARROW },
+        { Background = { Color = bg } },
+        { Foreground = { Color = fg } },
+        { Text = ' ' .. center_text },
+    }
+
+    -- 制作渐变配色,仅在 Windows 下使用,用于与右上按钮过渡
+    if wezterm.target_triple == 'x86_64-pc-windows-msvc' then
+        local gradient_step = 10
+        local gradient_bgs = wezterm.color.gradient({ colors = { bg, tbar_bg } }, gradient_step)
+        for i = 1, #gradient_bgs do
+            table.insert(right_status, { Background = { Color = gradient_bgs[i] }, })
+            table.insert(right_status, { Foreground = { Color = 'none' }, })
+            table.insert(right_status, { Text = ' ' })
+        end
+    else
+        table.insert(right_status, { Background = { Color = bg }, })
+        table.insert(right_status, { Foreground = { Color = 'none' }, })
+        table.insert(right_status, { Text = '  ' })
+
+    end
+
+    window:set_right_status(wezterm.format(right_status))
+end
+
+--- 获取正确的标签页标题
+function tab_title(tab_info)
+    local title = tab_info.tab_title
+    if title and #title > 0 then
+        return title
+    end
+    return tab_info.active_pane.title
+end
+
+function module.apply(config)
+    -- 设置字体
+    config.font = wezterm.font { family = 'Maple Mono NF CN' }
+
+    -- 启用滚动条
+    config.enable_scroll_bar = true
+
+    -- 配色方案
+    if is_dark_mode() then
+        config.color_scheme = 'Catppuccin Macchiato'
+    else
+        config.color_scheme = 'Catppuccin Latte'
+    end
+
+    -- 初始窗口大小
+    config.initial_cols = 128
+    config.initial_rows = 32
+
+    -- 背景透明度
+    config.window_background_opacity = 0.4
+    config.win32_system_backdrop = 'Acrylic'
+    config.macos_window_background_blur = 20
+    config.kde_window_background_blur = true
+
+    -- 调整窗口边距
+    config.window_padding = {
+        left = "5pt",
+        right = "5pt",
+        top = "5pt",
+        bottom = "5pt",
+    }
+
+
+    if wezterm.target_triple == 'x86_64-pc-windows-msvc' then
+        -- 改为嵌入式顶栏
+        config.window_decorations = 'INTEGRATED_BUTTONS|RESIZE'
+    end
+
+    -- 定制顶栏
+    wezterm.on('update-right-status', draw_right_status)
+
+    config.window_frame = {
+        font = wezterm.font { family = 'Noto Sans SC', weight = 'Bold' },
+        font_size = 10.0,
+    }
+end
+
+return module
home/base/gui/terminals/wezterm/config/module/keybindings.lua
@@ -0,0 +1,39 @@
+local wezterm = require 'wezterm'
+local module = {}
+
+function module.apply(config)
+    -- 禁用默认键绑定
+    config.disable_default_key_bindings = true
+
+    config.keys = {}
+    local act = wezterm.action
+    -- #===# 常规按键绑定 #===#
+    -- 复制
+    table.insert(config.keys,
+        { key = 'c', mods = 'CTRL|SHIFT', action = act.CopyTo "Clipboard" }
+    )
+    table.insert(config.keys,
+        { key = 'Copy', action = act.CopyTo "Clipboard" }
+    )
+    -- 粘贴
+    table.insert(config.keys,
+        { key = 'v', mods = 'CTRL|SHIFT', action = act.PasteFrom "Clipboard" }
+    )
+    table.insert(config.keys,
+        { key = 'Paste', action = act.PasteFrom "Clipboard" }
+    )
+    -- Lua 配置 Debug 叠加层
+    table.insert(config.keys,
+        { key = 'l', mods = 'CTRL|SHIFT', action = act.ShowDebugOverlay }
+    )
+    -- 命令面板
+    table.insert(config.keys,
+        { key = 'p', mods = 'CTRL|SHIFT', action = act.ActivateCommandPalette }
+    )
+    -- 搜索
+    table.insert(config.keys,
+        { key = 'f', mods = 'CTRL|SHIFT', action = act.Search { CaseSensitiveString = "" } }
+    )
+end
+
+return module
home/base/gui/terminals/wezterm/config/wezterm.lua
@@ -0,0 +1,23 @@
+local wezterm = require 'wezterm'
+local config = {}
+
+if wezterm.config_builder then
+    config = wezterm.config_builder()
+end
+
+local appears = require 'module.appearance'
+appears.apply(config)
+
+local keybindings = require 'module.keybindings'
+keybindings.apply(config)
+
+-- 关闭窗口时无提示
+config.window_close_confirmation = 'NeverPrompt'
+
+if wezterm.target_triple == 'x86_64-pc-windows-msvc' then
+    config.default_prog = { 'pwsh' }
+else
+    config.default_prog = { 'bash' }
+end
+
+return config
\ No newline at end of file
home/base/gui/terminals/wezterm/default.nix
@@ -1,7 +1,14 @@
-{...}: {
-  catppuccin.wezterm.enable = true;
+{
+  config,
+  pkgs-unstable,
+  ...
+}: let
+  configPath = "${config.home.homeDirectory}/nix-config/home/base/gui/terminals/wezterm/config";
+in {
+  home.file.".config/wezterm".source = config.lib.file.mkOutOfStoreSymlink configPath;
 
   programs.wezterm = {
     enable = true;
+    package = pkgs-unstable.wezterm;
   };
 }