1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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
|