diff options
| author | 2025-02-11 14:38:35 -0500 | |
|---|---|---|
| committer | 2025-02-11 14:38:35 -0500 | |
| commit | a1cdb80a68ed8821c2ed9f22f520cc4e6df8a626 (patch) | |
| tree | ebe6869df98e954b9453f5d2c7b0f5aee18fa3a2 | |
| parent | v0.3.0 (diff) | |
add api method to enable/disable inline suggestions
| -rw-r--r-- | .lush/init.lua | 3 | ||||
| -rw-r--r-- | src/lua_api.c | 10 | ||||
| -rw-r--r-- | src/lush.c | 3 | ||||
| -rw-r--r-- | src/lush.h | 6 |
4 files changed, 21 insertions, 1 deletions
diff --git a/.lush/init.lua b/.lush/init.lua index d3166d7..a6b5911 100644 --- a/.lush/init.lua +++ b/.lush/init.lua @@ -22,6 +22,9 @@ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. local path = lush.getenv("HOME") .. "/bin:" .. lush.getenv("PATH") lush.setenv("PATH", path) +-- you can choose to enable/disable inline suggestions +lush.suggestions(true) + -- the prompt can be customized here too -- %u is username, %h is hostname, %w is current working directory -- %t is current time in hr:min:sec, %d is date in MM/DD/YYYY 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); @@ -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) @@ -19,6 +19,8 @@ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. #define LUSH_H #include <lua.h> +#include <stdbool.h> + #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; |
