From fe08446d84e0aa939780ad013f0545778703da6d Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Fri, 19 Jul 2019 14:10:39 -0400 Subject: MBS as default shell --- .mbs/modules/readline.lua | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .mbs/modules/readline.lua (limited to '.mbs/modules/readline.lua') diff --git a/.mbs/modules/readline.lua b/.mbs/modules/readline.lua new file mode 100644 index 0000000..4dea9eb --- /dev/null +++ b/.mbs/modules/readline.lua @@ -0,0 +1,66 @@ +--- Additional readline + +local function lib_load(path, name) + if not _G[name] then + os.loadAPI(fs.combine(path, "lib/" .. name .. ".lua")) + if not _G[name] then _G[name] = _G[name .. ".lua"] end + end +end + +return { + description = + "This module extends the default read function, adding keybindings similar to " .. + "those provided by Emacs or GNU readline as well as additional configuration options.", + + dependencies = { + "lib/readline.lua", + }, + + settings = { + { + name = "mbs.readline.enabled", + description = "Whether the readline module is enabled.", + default = true, + }, + { + name = "mbs.readline.complete_bg", + description = "The background colour for completions.", + default = "none", + }, + { + name = "mbs.readline.complete_fg", + description = "The foreground colour for completions.", + default = "grey", + } + }, + + enabled = function() return settings.get("mbs.readline.enabled") end, + + setup = function(path) + lib_load(path, "readline") + + -- Replace the default read function + _G.read = function(replace_char, history, complete, default) + if replace_char ~= nil and type(replace_char) ~= "string" then + error("bad argument #1 (expected string, got " .. type(replace_char) .. ")", 2) + end + if history ~= nil and type(history) ~= "table" then + error("bad argument #2 (expected table, got " .. type(history) .. ")", 2) + end + if complete ~= nil and type(complete) ~= "function" then + error("bad argument #3 (expected function, got " .. type(complete) .. ")", 2) + end + if default ~= nil and type(default) ~= "string" then + error("bad argument #4 (expected string, got " .. type(default) .. ")", 2) + end + + return readline.read { + replace_char = replace_char, + history = history, + complete = complete, + default = default, + } + end + + end, +} \ No newline at end of file -- cgit v1.2.3