diff options
| author | Collin Williams <96917990+bluedragon1221@users.noreply.github.com> | 2026-05-11 15:07:55 -0500 |
|---|---|---|
| committer | Collin Williams <96917990+bluedragon1221@users.noreply.github.com> | 2026-05-11 15:07:55 -0500 |
| commit | cebb280fe546190e55e071b6adbf37cd47950f34 (patch) | |
| tree | 6e7a7605f8832b1c1bd7e467884a8792a5e1fab4 /runtime/lua/core/ui.lua | |
initial commit
Diffstat (limited to 'runtime/lua/core/ui.lua')
| -rw-r--r-- | runtime/lua/core/ui.lua | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/runtime/lua/core/ui.lua b/runtime/lua/core/ui.lua new file mode 100644 index 0000000..9ef25d1 --- /dev/null +++ b/runtime/lua/core/ui.lua @@ -0,0 +1,84 @@ +local M = {} + +local function hex_to_rgba(hex) + local h = hex:gsub("#", "") + if #h ~= 6 then + return 0, 0, 0, 255 + end + + local r = tonumber(h:sub(1, 2), 16) or 0 + local g = tonumber(h:sub(3, 4), 16) or 0 + local b = tonumber(h:sub(5, 6), 16) or 0 + return r, g, b, 255 +end + +local function current_buffer_label() + local path = editor.buffer_path() + if not path then + return "*scratch*" + end + return path +end + +function M.update_modeline(state) + if not state.mode_line_buffer then + return + end + + local dirty = editor.buffer_modified() and "*" or "-" + local cmd_mode = string.format("[%s-cmd]", state.command_kind or "lua") + local mode = state.command_mode and cmd_mode or string.format("[%s]", state.mode or "normal") + local leader = state.leader_pending and " [leader]" or "" + local text = string.format("lemacs %s | %s | %s %s%s", dirty, current_buffer_label(), state.current_theme, mode, leader) + editor.aux_buffer_set_text(state.mode_line_buffer, text) +end + +function M.set_message(state, text) + state.message_text = text + if state.message_buffer then + editor.aux_buffer_set_text(state.message_buffer, text) + end +end + +function M.update_commandline_buffer(state) + if not state.command_buffer then + return + end + local prefix = (state.command_kind == "command") and ":" or ":lua " + editor.aux_buffer_set_text(state.command_buffer, prefix .. state.command_text) +end + +function M.setup_layout(state, palette) + local width = editor.screen_width() + local height = editor.screen_height() + local mode_h = 28 + local msg_h = 24 + local cmd_h = state.command_mode and 24 or 0 + local body_h = height - mode_h - msg_h - cmd_h + if body_h < 1 then + body_h = 1 + end + + local base00_r, base00_g, base00_b = hex_to_rgba(palette.base00) + local base01_r, base01_g, base01_b = hex_to_rgba(palette.base01) + local base02_r, base02_g, base02_b = hex_to_rgba(palette.base02) + local base03_r, base03_g, base03_b = hex_to_rgba(palette.base03) + local base05_r, base05_g, base05_b = hex_to_rgba(palette.base05) + local base06_r, base06_g, base06_b = hex_to_rgba(palette.base06) + local base09_r, base09_g, base09_b = hex_to_rgba(palette.base09) + + editor.layout_reset() + editor.layout_add_view(0, 0, 0, 0, width, body_h, true, base00_r, base00_g, base00_b, 255, base05_r, base05_g, base05_b, 255) + editor.layout_add_view(1, state.mode_line_buffer, 0, body_h, width, mode_h, false, base02_r, base02_g, base02_b, 235, base06_r, base06_g, base06_b, 255) + editor.layout_add_view(1, state.message_buffer, 0, body_h + mode_h, width, msg_h, false, base01_r, base01_g, base01_b, 240, base09_r, base09_g, base09_b, 255) + + if state.command_mode then + editor.layout_add_view(1, state.command_buffer, 0, body_h + mode_h + msg_h, width, cmd_h, false, base03_r, base03_g, base03_b, 245, base06_r, base06_g, base06_b, 255) + end +end + +function M.current_buffer_label() + return current_buffer_label() +end + +return M |
