Skip to content

Commit 6c4b737

Browse files
feat: Use proper guard icon for the topbar
1 parent 09c33d5 commit 6c4b737

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

lua/opencode/ui/icons.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ local presets = {
2525
-- statuses
2626
status_on = '🟢',
2727
status_off = '',
28+
guard_on = '🚫',
2829
-- borders and misc
2930
border = '',
3031
},
@@ -49,6 +50,7 @@ local presets = {
4950
-- statuses
5051
status_on = '',
5152
status_off = '',
53+
guard_on = '',
5254
-- borders and misc
5355
border = '',
5456
},
@@ -73,6 +75,7 @@ local presets = {
7375
-- statuses
7476
status_on = 'ON',
7577
status_off = 'OFF',
78+
guard_on = 'X',
7679
-- borders and misc
7780
border = '',
7881
},

lua/opencode/ui/prompt_guard_indicator.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function M.get_formatted()
3030
end
3131

3232
-- Prompts will be denied - show red indicator
33-
local icon = icons.get('status_off')
33+
local icon = icons.get('guard_on')
3434
return string.format('%%#OpencodeGuardDenied#%s%%*', icon)
3535
end
3636

lua/opencode/ui/topbar.lua

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ local M = {}
33
local state = require('opencode.state')
44
local config_file = require('opencode.config_file')
55
local prompt_guard_indicator = require('opencode.ui.prompt_guard_indicator')
6-
local icons = require('opencode.ui.icons')
76

87
local LABELS = {
98
NEW_SESSION_TITLE = 'New session',
@@ -44,41 +43,38 @@ end
4443

4544
local function create_winbar_text(description, model_info, mode_info, show_guard_indicator, win_width)
4645
-- Calculate how many visible characters we have
47-
-- Format: " [GUARD] description padding model_info MODE "
48-
-- Where [GUARD] is optional (1 char + 1 space = 2 visible chars)
46+
-- Format: " [GUARD ]description padding model_info MODE "
47+
-- Where [GUARD ] is optional
4948

50-
local guard_icon = ''
49+
local guard_info = ''
5150
local guard_visible_width = 0
5251
if show_guard_indicator then
53-
guard_icon = prompt_guard_indicator.get_formatted()
52+
guard_info = prompt_guard_indicator.get_formatted()
5453
guard_visible_width = 2 -- icon + space
5554
end
5655

57-
-- Total available width for all content
58-
local total_width = win_width
59-
6056
-- Calculate used width: leading space + guard + trailing space + model + mode
6157
local mode_info_str = get_mode_highlight() .. mode_info .. '%*'
6258
local mode_visible_width = #mode_info
6359
local model_visible_width = #model_info
6460

65-
-- Reserve space: 1 (leading) + guard_visible_width + 1 (space before description) + 1 (space before model) + model + mode
66-
local reserved_width = 1 + guard_visible_width + 1 + 1 + model_visible_width + mode_visible_width
61+
-- Reserve space: 1 (padding) + guard_visible_width (with padding) + model + 1 (space before mode) + mode + 1 (padding)
62+
local reserved_width = 1 + guard_visible_width + model_visible_width + 1 + mode_visible_width + 1
6763

6864
-- Available width for description and padding
69-
local available_for_desc = total_width - reserved_width
65+
local available_for_desc = win_width - reserved_width
7066

7167
-- Truncate description if needed
7268
if #description > available_for_desc then
73-
description = description:sub(1, math.max(1, available_for_desc - 4)) .. '...'
69+
local space_for_desc = available_for_desc - 4 -- -4 for "... "
70+
description = description:sub(1, space_for_desc) .. '...'
7471
end
7572

7673
-- Calculate padding to right-align model and mode
77-
local desc_and_padding_width = available_for_desc
78-
local padding_width = desc_and_padding_width - #description
74+
local padding_width = available_for_desc - #description
7975
local padding = string.rep(' ', math.max(0, padding_width))
8076

81-
return string.format(' %s%s%s%s %s', guard_icon, description, padding, model_info, get_mode_highlight() .. mode_info .. '%*')
77+
return string.format(' %s %s%s%s %s ', guard_info, description, padding, model_info, mode_info_str)
8278
end
8379

8480
local function update_winbar_highlights(win_id)

0 commit comments

Comments
 (0)