QianSong1 / wezterm-config

wezterm-config files
MIT License
99 stars 26 forks source link

About bar setting #4

Closed touero closed 6 months ago

touero commented 6 months ago

你好,我对于这个形式的配置有些疑惑,我想将你的bar的形状样式移到我的wezterm中,但是我看不出你是如何配置的,我是配置只有一个wezterm.lua

local wezterm = require("wezterm")
local config = {}
config.colors = {
    background = "#282828",
    foreground = "#fbf1c7",

    --         Black      Maroon     Green      Olive      Navy       Purple     Teal       Silver
    ansi = { "#282828", "#cc241d", "#98971a", "#d79921", "#458588", "#b16286", "#689d6a", "#a89984" },

    --             Grey       Red        Lime      Yellow      Blue      Fuchsia    Squa      White
    brights = { "#928374", "#fb4934", "#b8bb26", "#fabd2f", "#83a598", "#d3869b", "#8ec07c", "#ebdbb2" },

    tab_bar = {
        background = "#282828",
        active_tab = {
            bg_color = "#fe8019",
            fg_color = "#3c3836",
        },
        inactive_tab = {
            bg_color = "#d65d0e",
            fg_color = "#3c3836",
        },
        inactive_tab_hover = {
            bg_color = "#fe8019",
            fg_color = "#3c3836",
        },
        new_tab = {
            bg_color = "#fe8019",
            fg_color = "#3c3836",
        },
        new_tab_hover = {
            bg_color = "#181825",
            fg_color = "#cdd6f4",
            italic = true,
        },
    },
}
return config

上面我省略一部份,只是简单的设置了tab的背景字体颜色样式,我想将bar的样式设置成你的样式,请问如何在我的程序中修改。 感谢

QianSong1 commented 6 months ago

Well, I'm not the original author, but what you're looking for should be like this

AUTHOR =====###=====https://github.com/KevinSilvester/wezterm-config

local wezterm = require 'wezterm';
local config = {}
config.font = wezterm.font 'JetBrains Mono'

------------------------------config at above  -----------------------------------------------------------
--
--
--
------------------------------tab bar event at here-------------------------------------------------------
-- Inspired by https://github.com/wez/wezterm/discussions/628#discussioncomment-1874614

local GLYPH_SEMI_CIRCLE_LEFT = ""
-- local GLYPH_SEMI_CIRCLE_LEFT = utf8.char(0xe0b6)
local GLYPH_SEMI_CIRCLE_RIGHT = ""
-- local GLYPH_SEMI_CIRCLE_RIGHT = utf8.char(0xe0b4)
local GLYPH_CIRCLE = ""
-- local GLYPH_CIRCLE = utf8.char(0xf111)
local GLYPH_ADMIN = "ﱾ"
-- local GLYPH_ADMIN = utf8.char(0xfc7e)

local M = {}

M.cells = {}

M.colors = {
   default = {
      bg = "#85248C",
      fg = "#0F2536",
   },
   is_active = {
      bg = "#46A4A6",
      fg = "#0F2536",
   },

   hover = {
      bg = "#B531BF",
      fg = "#0F2536",
   },
}

M.set_process_name = function(s)
   local a = string.gsub(s, "(.*[/\\])(.*)", "%2")
   return a:gsub("%.exe$", "")
end

M.set_title = function(process_name, static_title, active_title, max_width, inset)
   local title
   inset = inset or 6

   if process_name:len() > 0 and static_title:len() == 0 then
      title = "  " .. process_name .. " ~ " .. " "
   elseif static_title:len() > 0 then
      title = "󰴈  " .. static_title .. " ~ " .. " "
   else
      title = "  " .. active_title .. " ~ " .. " "
   end

   if title:len() > max_width - inset then
      local diff = title:len() - max_width + inset
      title = wezterm.truncate_right(title, title:len() - diff)
   end

   return title
end

M.check_if_admin = function(p)
   if p:match("^Administrator: ") then
      return true
   end
   return false
end

---@param fg string
---@param bg string
---@param attribute table
---@param text string
M.push = function(bg, fg, attribute, text)
   table.insert(M.cells, { Background = { Color = bg } })
   table.insert(M.cells, { Foreground = { Color = fg } })
   table.insert(M.cells, { Attribute = attribute })
   table.insert(M.cells, { Text = text })
end

M.setup = function()
   wezterm.on("format-tab-title", function(tab, tabs, panes, config, hover, max_width)
      M.cells = {}

      local bg
      local fg
      local process_name = M.set_process_name(tab.active_pane.foreground_process_name)
      local is_admin = M.check_if_admin(tab.active_pane.title)
      local title = M.set_title(process_name, tab.tab_title, tab.active_pane.title, max_width, (is_admin and 8))

      if tab.is_active then
         bg = M.colors.is_active.bg
         fg = M.colors.is_active.fg
      elseif hover then
         bg = M.colors.hover.bg
         fg = M.colors.hover.fg
      else
         bg = M.colors.default.bg
         fg = M.colors.default.fg
      end

      local has_unseen_output = false
      for _, pane in ipairs(tab.panes) do
         if pane.has_unseen_output then
            has_unseen_output = true
            break
         end
      end

      -- Left semi-circle
      M.push(fg, bg, { Intensity = "Bold" }, GLYPH_SEMI_CIRCLE_LEFT)

      -- Admin Icon
      if is_admin then
         M.push(bg, fg, { Intensity = "Bold" }, " " .. GLYPH_ADMIN)
      end

      -- Title
      M.push(bg, fg, { Intensity = "Bold" }, " " .. title)

      -- Unseen output alert
      if has_unseen_output then
         M.push(bg, "#FF3B8B", { Intensity = "Bold" }, " " .. GLYPH_CIRCLE)
      end

      -- Right padding
      M.push(bg, fg, { Intensity = "Bold" }, " ")

      -- Right semi-circle
      M.push(fg, bg, { Intensity = "Bold" }, GLYPH_SEMI_CIRCLE_RIGHT)

      return M.cells
   end)
end

M.setup()
-----------------------------------tab bar config end-------------------------------------------------------

return config

-----------https://github.com/wez/wezterm/discussions/628#discussioncomment-3649195------------------------
--
--      THIS IS AUTHOR  ↑↑↑
--
-----------------------------------------------------------------------------------------------------------