aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam Harrison <adamdharrison@gmail.com>2024-03-05 12:22:07 -0500
committerAdam Harrison <adamdharrison@gmail.com>2024-03-05 12:22:07 -0500
commit389fe57a9fcd4c9971bb9cebc8dfeb67cac6498a (patch)
tree744bbd7f550d175604f64595f89008b7760f686d /src
parent4ac6bf5a4b4728abfcae7b06b30a0dd17f8735c0 (diff)
downloadlite-xl-plugin-manager-389fe57a9fcd4c9971bb9cebc8dfeb67cac6498a.tar.gz
lite-xl-plugin-manager-389fe57a9fcd4c9971bb9cebc8dfeb67cac6498a.zip
Flush input buffer before prompt.
Diffstat (limited to 'src')
-rw-r--r--src/lpm.c11
-rw-r--r--src/lpm.lua1
2 files changed, 12 insertions, 0 deletions
diff --git a/src/lpm.c b/src/lpm.c
index ba228a9..17054e4 100644
--- a/src/lpm.c
+++ b/src/lpm.c
@@ -8,6 +8,7 @@
#include <sys/socket.h>
#include <arpa/inet.h>
#include <libgen.h>
+ #include <termios.h>
#define MAX_PATH PATH_MAX
#endif
@@ -155,6 +156,15 @@ static int lpm_hash(lua_State* L) {
return 1;
}
+static int lpm_tcflush(lua_State* L) {
+ int stream = luaL_checkinteger(L, 1);
+ #ifndef _WIN32
+ if (isatty(stream))
+ tcflush(stream, TCIOFLUSH);
+ #endif
+ return 0;
+}
+
static int lpm_symlink(lua_State* L) {
#ifndef _WIN32
@@ -1279,6 +1289,7 @@ static const luaL_Reg system_lib[] = {
{ "mkdir", lpm_mkdir }, // Makes a directory.
{ "rmdir", lpm_rmdir }, // Removes a directory.
{ "hash", lpm_hash }, // Returns a hex sha256 hash.
+ { "tcflush", lpm_tcflush }, // Flushes an terminal stream.
{ "symlink", lpm_symlink }, // Creates a symlink.
{ "chmod", lpm_chmod }, // Chmod's a file.
{ "init", lpm_init }, // Initializes a git repository with the specified remote.
diff --git a/src/lpm.lua b/src/lpm.lua
index 5307a0a..c990407 100644
--- a/src/lpm.lua
+++ b/src/lpm.lua
@@ -524,6 +524,7 @@ local function log_progress_action(message)
end
end
local function prompt(message)
+ system.tcflush(0)
if not ASSUME_YES or not JSON then
io.stderr:write(colorize(message .. " [Y/n]: ", "cyan"))
if ASSUME_YES then io.stderr:write("Y\n") end