aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--spec/04-term_spec.lua32
-rw-r--r--src/term.c10
2 files changed, 28 insertions, 14 deletions
diff --git a/spec/04-term_spec.lua b/spec/04-term_spec.lua
index ee4145a..487a0ce 100644
--- a/spec/04-term_spec.lua
+++ b/spec/04-term_spec.lua
@@ -106,21 +106,29 @@ describe("Terminal:", function()
106 106
107 107
108 108
109 pending("getconsoleflags()", function() 109 describe("getconsoleflags()", function()
110
111 pending("returns the consoleflags, if called without flags", function()
112print"1"
113package.loaded["system"] = nil
114package.loaded["system.core"] = nil
115print"2"
116local system = require "system"
117print"3"
118for k,v in pairs(system) do print(k,v) end
119for k,v in pairs(debug.getinfo(system.isatty)) do print(k,v) end
120 110
111 win_it("returns the consoleflags #manual", function()
121 local flags, err = system.getconsoleflags(io.stdin) 112 local flags, err = system.getconsoleflags(io.stdin)
122 assert.is_nil(err) 113 assert.is_nil(err)
123 assert.is_integer(flags) 114 assert.is_userdata(flags)
115 assert.equals("bitflags:", tostring(flags):sub(1,9))
116 end)
117
118
119 nix_it("returns the consoleflags, as value 0", function()
120 local flags, err = system.getconsoleflags(io.stdin)
121 assert.is_nil(err)
122 assert.is_userdata(flags)
123 assert.equals("bitflags:", tostring(flags):sub(1,9))
124 assert.equals(0, flags:value())
125 end)
126
127
128 it("returns an error if called with an invalid argument", function()
129 assert.has.error(function()
130 system.getconsoleflags("invalid")
131 end, "bad argument #1 to 'getconsoleflags' (FILE* expected, got string)")
124 end) 132 end)
125 133
126 end) 134 end)
diff --git a/src/term.c b/src/term.c
index e557a11..10b3e25 100644
--- a/src/term.c
+++ b/src/term.c
@@ -309,6 +309,7 @@ static HANDLE get_console_handle(lua_State *L, int flags_optional)
309// Lua error if the file is not one of these. 309// Lua error if the file is not one of these.
310static int get_console_handle(lua_State *L) 310static int get_console_handle(lua_State *L)
311{ 311{
312printf("get_console_handle\n");
312 FILE **file = (FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE); 313 FILE **file = (FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE);
313 if (file == NULL || *file == NULL) { 314 if (file == NULL || *file == NULL) {
314 return luaL_argerror(L, 1, "expected file handle"); // call doesn't return 315 return luaL_argerror(L, 1, "expected file handle"); // call doesn't return
@@ -375,9 +376,12 @@ static int lst_setconsoleflags(lua_State *L)
375 return 2; 376 return 2;
376 } 377 }
377 378
378#endif 379#else
379 lua_pushboolean(L, 1); 380 get_console_handle(L); // to validate args
381 lua_pushboolean(L, 1); // always return true on Posix
380 return 1; 382 return 1;
383
384#endif
381} 385}
382 386
383 387
@@ -417,6 +421,8 @@ static int lst_getconsoleflags(lua_State *L)
417 lua_pushliteral(L, "failed to get console mode"); 421 lua_pushliteral(L, "failed to get console mode");
418 return 2; 422 return 2;
419 } 423 }
424#else
425 get_console_handle(L); // to validate args
420 426
421#endif 427#endif
422 lsbf_pushbitflags(L, console_mode); 428 lsbf_pushbitflags(L, console_mode);