Skip to content

Commit

Permalink
remove enable/disable; use bitlfags objects instead
Browse files Browse the repository at this point in the history
Simplifies the interface, less methods
  • Loading branch information
Tieske committed Apr 21, 2024
1 parent b9ac485 commit 9d6e9dc
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 317 deletions.
14 changes: 7 additions & 7 deletions examples/password_input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ local function read_secret(...)

if sys.isatty(io.stdin) then
-- backup settings, configure echo flags
w_oldflags = sys.disableconsoleflags(io.stdin, sys.CIF_ECHO_INPUT)
w_oldflags = sys.getconsoleflags(io.stdin)
p_oldflags = sys.tcgetattr(io.stdin)
sys.tcdisableattr(io.stdin, sys.TCSANOW, {
lflag = sys.L_ECHO, -- echo is off to not show password on screen
})
sys.tcenableattr(io.stdin, sys.TCSANOW, {
lflag = sys.L_ECHONL, -- echo is off, but we still echo the final newline
})
-- Windows: echo is off to not show password on screen (has no L_ECHONL option)
assert(sys.setconsoleflags(io.stdin, w_oldflags - sys.CIF_ECHO_INPUT))
-- Posix: echo is off to not show password on screen, but we still echo the final newline
assert(sys.tcsetattr(io.stdin, sys.TCSANOW, {
lflag = p_oldflags.lflag - sys.L_ECHO + sys.L_ECHONL
}))
end

local secret, err = io.stdin:read(...)
Expand Down
1 change: 1 addition & 0 deletions src/bitflags.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

// Validates that the given index is a bitflag object and returns its value.
// If the index is not a bitflag object, a Lua error is raised.
// The value will be left on the stack.
LSBF_FLAGTYPE lsbf_checkbitflags(lua_State *L, int index);

// Pushes a new bitflag object with the given value onto the stack.
Expand Down
2 changes: 1 addition & 1 deletion src/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ LUAEXPORT int luaopen_system_core(lua_State *L) {
lua_pushboolean(L, 0);
#endif
lua_rawset(L, -3);
bitflags_open(L); // must be first, used by others
time_open(L);
random_open(L);
term_open(L);
environment_open(L);
bitflags_open(L);
return 1;
}
Loading

0 comments on commit 9d6e9dc

Please sign in to comment.