Skip to content

Commit

Permalink
feat(icons): use wezterm.nerdfonts as default (#8)
Browse files Browse the repository at this point in the history
feat(icons): break out spacing for separator to it's own option
  • Loading branch information
adriankarlen authored Sep 9, 2024
1 parent 8c64844 commit b78a6ff
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 35 deletions.
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,23 @@ bar.apply_to_config(
> NOTE: The default config requires that you are using a Nerd Font or has "Symbols Nerd Font" installed on your system so wezterm can default to it.
```lua
{
local config = {
position = "bottom",
max_width = 32,
left_separator = "",
right_separator = "",
field_separator = " | ",
leader_icon = "",
workspace_icon = "",
pane_icon = "",
user_icon = "",
hostname_icon = "󰒋",
clock_icon = "󰃰",
cwd_icon = "",
separator_space = 1,
left_separator = wez.nerdfonts.fa_long_arrow_right,
right_separator = wez.nerdfonts.fa_long_arrow_left,
field_separator = wez.nerdfonts.indent_line,
leader_icon = wez.nerdfonts.oct_rocket,
workspace_icon = wez.nerdfonts.cod_window,
pane_icon = wez.nerdfonts.cod_multiple_windows,
user_icon = wez.nerdfonts.fa_user,
hostname_icon = wez.nerdfonts.cod_server,
clock_icon = wez.nerdfonts.md_calendar_clock,
cwd_icon = wez.nerdfonts.oct_file_directory,
enabled_modules = {
workspace = true,
pane = true,
username = true,
hostname = true,
clock = true,
Expand Down
60 changes: 36 additions & 24 deletions plugin/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ local wez = require "wezterm"
local config = {
position = "bottom",
max_width = 32,
left_separator = "",
right_separator = "",
field_separator = " | ",
leader_icon = "",
workspace_icon = "",
pane_icon = "",
user_icon = "",
hostname_icon = "󰒋",
clock_icon = "󰃰",
cwd_icon = "",
separator_space = 1,
left_separator = wez.nerdfonts.fa_long_arrow_right,
right_separator = wez.nerdfonts.fa_long_arrow_left,
field_separator = wez.nerdfonts.indent_line,
leader_icon = wez.nerdfonts.oct_rocket,
workspace_icon = wez.nerdfonts.cod_window,
pane_icon = wez.nerdfonts.cod_multiple_windows,
user_icon = wez.nerdfonts.fa_user,
hostname_icon = wez.nerdfonts.cod_server,
clock_icon = wez.nerdfonts.md_calendar_clock,
cwd_icon = wez.nerdfonts.oct_file_directory,
enabled_modules = {
workspace = true,
pane = true,
Expand Down Expand Up @@ -145,21 +146,20 @@ end

local get_leader = function(prev)
local leader = config.leader_icon

wez.log_info("prev: " .. prev)
wez.log_info("prev size: " .. #prev)
wez.log_info("leader: " .. leader)
wez.log_info("leader size: " .. #leader)

local spacing = #prev - #leader
local first_half = math.floor(spacing / 2)
local second_half = math.ceil(spacing / 2)
wez.log_info("spacing: " .. spacing)
wez.log_info("first_half: " .. first_half)
wez.log_info("second_half: " .. second_half)
return string.rep(" ", first_half) .. leader .. string.rep(" ", second_half)
end

local with_spaces = function(icon, space)
if type(icon) ~= "string" or type(space) ~= "number" then
return ""
end
local spaces = string.rep(" ", space)
return spaces .. icon .. spaces
end

-- conforming to https://github.com/wez/wezterm/commit/e4ae8a844d8feaa43e1de34c5cc8b4f07ce525dd
-- exporting an apply_to_config function, even though we don't change the users config
M.apply_to_config = function(c, opts)
Expand Down Expand Up @@ -201,8 +201,9 @@ wez.on("format-tab-title", function(tab, _, _, conf, _, _)
local palette = conf.resolved_palette

local index = tab.tab_index + 1
local offset = #tostring(index) + #config.left_separator + 2
local title = index .. config.left_separator .. tab_title(tab)
local offset = #tostring(index) + #config.left_separator + (2 * config.separator_space) + 2
wez.log_info(offset)
local title = index .. with_spaces(config.left_separator, config.separator_space) .. tab_title(tab)

local width = conf.tab_max_width - offset
if #title > conf.tab_max_width then
Expand Down Expand Up @@ -272,22 +273,33 @@ wez.on("update-status", function(window, pane)
table.insert(right_cells, { Foreground = { Color = palette.ansi[config.ansi_colors.username] } })
table.insert(right_cells, { Text = username })
table.insert(right_cells, { Foreground = { Color = palette.brights[1] } })
table.insert(right_cells, { Text = config.right_separator .. config.user_icon .. config.field_separator })
table.insert(right_cells, {
Text = with_spaces(config.right_separator, config.separator_space)
.. config.user_icon
.. with_spaces(config.field_separator, config.separator_space),
})
end

local cwd, hostname = get_cwd_hostname(pane, true)
if enabled_modules.hostname then
table.insert(right_cells, { Foreground = { Color = palette.ansi[config.ansi_colors.hostname] } })
table.insert(right_cells, { Text = hostname })
table.insert(right_cells, { Foreground = { Color = palette.brights[1] } })
table.insert(right_cells, { Text = config.right_separator .. config.hostname_icon .. config.field_separator })
table.insert(right_cells, {
Text = with_spaces(config.right_separator, config.separator_space)
.. config.hostname_icon
.. with_spaces(config.field_separator, config.separator_space),
})
end

if enabled_modules.clock then
table.insert(right_cells, { Foreground = { Color = palette.ansi[config.ansi_colors.clock] } })
table.insert(right_cells, { Text = wez.time.now():format "%H:%M" })
table.insert(right_cells, { Foreground = { Color = palette.brights[1] } })
table.insert(right_cells, { Text = config.right_separator .. config.clock_icon .. " " })
table.insert(
right_cells,
{ Text = with_spaces(config.right_separator, config.separator_space) .. config.clock_icon .. " " }
)
end

if enabled_modules.cwd then
Expand Down

0 comments on commit b78a6ff

Please sign in to comment.