diff options
author | Adam Harrison <adamdharrison@gmail.com> | 2024-03-06 17:40:40 -0500 |
---|---|---|
committer | Adam Harrison <adamdharrison@gmail.com> | 2024-03-06 17:40:40 -0500 |
commit | d236f64d08d33c77ba317964f86e0547092a8493 (patch) | |
tree | 5b194e25c67a687b8a7715506b2e15912d2b121a /src/lpm.c | |
parent | 389fe57a9fcd4c9971bb9cebc8dfeb67cac6498a (diff) | |
download | lite-xl-plugin-manager-d236f64d08d33c77ba317964f86e0547092a8493.tar.gz lite-xl-plugin-manager-d236f64d08d33c77ba317964f86e0547092a8493.zip |
Fixed a minor bug with downloading when downloads get aborted, and also ensured that download messages on small terminals don't go nuts.
Diffstat (limited to 'src/lpm.c')
-rw-r--r-- | src/lpm.c | 26 |
1 files changed, 24 insertions, 2 deletions
@@ -6,6 +6,7 @@ #else #include <netdb.h> #include <sys/socket.h> + #include <sys/ioctl.h> #include <arpa/inet.h> #include <libgen.h> #include <termios.h> @@ -165,6 +166,25 @@ static int lpm_tcflush(lua_State* L) { return 0; } +static int lpm_tcwidth(lua_State* L) { + int stream = luaL_checkinteger(L, 1); + #ifndef _WIN32 + if (isatty(stream)) { + struct winsize ws={0}; + ioctl(stream, TIOCGWINSZ, &ws); + lua_pushinteger(L, ws.ws_col); + return 1; + } + #else + CONSOLE_SCREEN_BUFFER_INFO csbi; + int columns, rows; + if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) { + lua_pushinteger(L, csbi.srWindow.Right - csbi.srWindow.Left + 1); + return 1; + } + #endif + return 0; +} static int lpm_symlink(lua_State* L) { #ifndef _WIN32 @@ -872,10 +892,11 @@ static int lpm_extract(lua_State* L) { while (remaining > 0) { int read_size = remaining < sizeof(buffer) ? remaining : sizeof(buffer); - if (mtar_read_data(&tar, buffer, read_size) != MTAR_ESUCCESS) { + int err = mtar_read_data(&tar, buffer, read_size); + if (err != MTAR_ESUCCESS) { fclose(file); mtar_close(&tar); - return luaL_error(L, "can't write file %s: %s", target, strerror(errno)); + return luaL_error(L, "can't read file %s: %s", target, mtar_strerror(err)); } fwrite(buffer, sizeof(char), read_size, file); @@ -1290,6 +1311,7 @@ static const luaL_Reg system_lib[] = { { "rmdir", lpm_rmdir }, // Removes a directory. { "hash", lpm_hash }, // Returns a hex sha256 hash. { "tcflush", lpm_tcflush }, // Flushes an terminal stream. + { "tcwidth", lpm_tcwidth }, // Gets the terminal width in columns. { "symlink", lpm_symlink }, // Creates a symlink. { "chmod", lpm_chmod }, // Chmod's a file. { "init", lpm_init }, // Initializes a git repository with the specified remote. |