diff options
| author | Andrew Lee <alee14498@gmail.com> | 2019-07-19 14:10:39 -0400 |
|---|---|---|
| committer | Andrew Lee <alee14498@gmail.com> | 2019-07-19 14:10:39 -0400 |
| commit | fe08446d84e0aa939780ad013f0545778703da6d (patch) | |
| tree | f45358ae6470dc894c41abcb278c4898c7ef1b18 /.mbs/modules/readline.lua | |
| parent | 21446806b264d8fd6694b1495f0c51bf24d26b35 (diff) | |
| download | bits-UI-fe08446d84e0aa939780ad013f0545778703da6d.tar.gz bits-UI-fe08446d84e0aa939780ad013f0545778703da6d.tar.bz2 bits-UI-fe08446d84e0aa939780ad013f0545778703da6d.zip | |
MBS as default shell
Diffstat (limited to '.mbs/modules/readline.lua')
| -rw-r--r-- | .mbs/modules/readline.lua | 66 |
1 files changed, 66 insertions, 0 deletions
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 |
