From cebb280fe546190e55e071b6adbf37cd47950f34 Mon Sep 17 00:00:00 2001 From: Collin Williams <96917990+bluedragon1221@users.noreply.github.com> Date: Mon, 11 May 2026 15:07:55 -0500 Subject: initial commit --- runtime/lua/core/cmdline.lua | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 runtime/lua/core/cmdline.lua (limited to 'runtime/lua/core/cmdline.lua') 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 -- cgit v1.3.1