From a1cdb80a68ed8821c2ed9f22f520cc4e6df8a626 Mon Sep 17 00:00:00 2001 From: BanceDev Date: Tue, 11 Feb 2025 14:38:35 -0500 Subject: add api method to enable/disable inline suggestions --- src/lua_api.c | 10 ++++++++++ src/lush.c | 3 ++- src/lush.h | 6 ++++++ 3 files changed, 18 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/lua_api.c b/src/lua_api.c index e9473a0..ae5decf 100644 --- a/src/lua_api.c +++ b/src/lua_api.c @@ -32,6 +32,7 @@ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // globals static bool debug_mode = false; +bool suggestion_enable = true; // -- script execution -- int lua_load_script(lua_State *L, const char *script, char **args) { @@ -175,6 +176,13 @@ static int l_get_cwd(lua_State *L) { return 1; } +static int l_suggestions(lua_State *L) { + if (lua_isboolean(L, 1)) { + suggestion_enable = lua_toboolean(L, 1); + } + return 0; +} + static int l_debug(lua_State *L) { if (lua_isboolean(L, 1)) { debug_mode = lua_toboolean(L, 1); @@ -426,6 +434,8 @@ void lua_register_api(lua_State *L) { lua_setfield(L, -2, "getcwd"); lua_pushcfunction(L, l_debug); lua_setfield(L, -2, "debug"); + lua_pushcfunction(L, l_suggestions); + lua_setfield(L, -2, "suggestions"); lua_pushcfunction(L, l_cd); lua_setfield(L, -2, "cd"); lua_pushcfunction(L, l_exists); diff --git a/src/lush.c b/src/lush.c index 2925272..f815fa5 100644 --- a/src/lush.c +++ b/src/lush.c @@ -617,7 +617,8 @@ static void reprint_buffer(char *buffer, int *last_lines, int *pos, printf("\r\033[K"); printf("%s ", prompt); printf("%s", buffer); - printf("\033[0;33m%s\033[0m ", suggestion); + if (suggestion_enable) + printf("\033[0;33m%s\033[0m ", suggestion); // move cursor up and to the right to be in correct position if (cursor_pos > 0) diff --git a/src/lush.h b/src/lush.h index d067b36..9ca9722 100644 --- a/src/lush.h +++ b/src/lush.h @@ -19,6 +19,8 @@ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. #define LUSH_H #include +#include + #define LUSH_LUA 5 // alias @@ -53,6 +55,10 @@ int lush_execute_chain(lua_State *L, char ***commands, int num_commands); void lush_format_prompt(const char *prompt_format); +// enable for autocomplete text set in init.lua +// initialized in the lua_api +extern bool suggestion_enable; + // format spec for the prompt extern char *prompt_format; -- cgit v1.2.3-59-g8ed1b