Skip to content

Commit

Permalink
update error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed Apr 29, 2024
1 parent f9ccc60 commit 885cbad
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/term.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
#endif

#ifdef _WIN32
// TODO: align the two calls to be similar, and use a single name for the function

// after an error is returned, GetLastError() result can be passed to this function to get a string
// representation of the error on the stack.
// result will be nil+error on the stack, always 2 results.
Expand Down Expand Up @@ -754,12 +752,10 @@ Get the size of the terminal in columns and rows.
static int lst_termsize(lua_State *L) {
int columns, rows;

// TODO: integrate error handling with helper functions at the top
#ifdef _WIN32
CONSOLE_SCREEN_BUFFER_INFO csbi;
if (!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) {
lua_pushnil(L);
lua_pushstring(L, "Failed to get terminal size.");
termFormatError(L, GetLastError(), "Failed to get terminal size.");
return 2;
}
columns = csbi.srWindow.Right - csbi.srWindow.Left + 1;
Expand All @@ -768,9 +764,7 @@ static int lst_termsize(lua_State *L) {
#else
struct winsize ws;
if (ioctl(1, TIOCGWINSZ, &ws) == -1) {
lua_pushnil(L);
lua_pushstring(L, "Failed to get terminal size.");
return 2;
return pusherror(L, "Failed to get terminal size.");
}
columns = ws.ws_col;
rows = ws.ws_row;
Expand Down

0 comments on commit 885cbad

Please sign in to comment.