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/cmdline.lua | |
initial commit
Diffstat (limited to 'runtime/lua/core/cmdline.lua')
| -rw-r--r-- | runtime/lua/core/cmdline.lua | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/runtime/lua/core/cmdline.lua b/runtime/lua/core/cmdline.lua new file mode 100644 index 0000000..4d7e44a --- /dev/null +++ b/runtime/lua/core/cmdline.lua @@ -0,0 +1,63 @@ +local M = {} + +function M.eval_line(line) + local chunk, load_err = load("return " .. line, "=lemacs-cmd", "t", _G) + if not chunk then + chunk, load_err = load(line, "=lemacs-cmd", "t", _G) + end + + if not chunk then + return false, "lua compile error: " .. tostring(load_err) + end + + local ok, result = pcall(chunk) + if not ok then + return false, "lua runtime error: " .. tostring(result) + end + + if result ~= nil then + return true, "=> " .. tostring(result) + end + + return true, "lua ok" +end + +function M.eval_command(state, line) + local name = (line or ""):gsub("^%s+", ""):gsub("%s+$", "") + if name == "" then + return false, "command prompt empty" + end + + local app = require("core.app") + if app.try_named_command_extension(name) then + return true, nil + end + + local command = require("core.commands") + local ok, err = command.call(state, name) + if not ok then + return false, err + end + + return true, nil +end + +function M.enter(state, ui, palette, kind) + state.command_mode = true + state.command_kind = kind or "lua" + state.command_text = "" + ui.update_commandline_buffer(state) + ui.update_modeline(state) + ui.setup_layout(state, palette) +end + +function M.exit(state, ui, palette) + state.command_mode = false + state.command_kind = "lua" + state.command_text = "" + ui.update_commandline_buffer(state) + ui.update_modeline(state) + ui.setup_layout(state, palette) +end + +return M |
