Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib_ncurses.cr
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ lib LibNCurses
fun wtimeout(window : Window, timeout : LibC::Int)

# Input functions
fun wgetch(window : Window) : LibC::Int
fun wget_wch(window : Window, wch : LibC::UInt*) : LibC::Int
fun flushinp : LibC::Int

# Mouse functions
Expand Down
5 changes: 3 additions & 2 deletions src/ncurses.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ module NCurses
alias Color = LibNCurses::Color

# Possible integer result values
ERR = -1
OK = 0
ERR = -1
OK = 0
KEY_CODE_YES = 0o400

BORDER_DEFAULT = 0.chr

Expand Down
12 changes: 9 additions & 3 deletions src/ncurses/window.cr
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,16 @@ module NCurses
#
# Returned as `Key` if recognised, `Char` otherwise
#
# Wrapper for `wgetch()` (`getch()`)
# Wrapper for `wget_wch()` (`get_wch()`)
def get_char : Key | Char | Nil
return nil if (key = LibNCurses.wgetch(self)) == ERR
return Key.from_value?(key) || key.chr
case LibNCurses.wget_wch(self, out key)
when OK # key is a character
key.chr
when KEY_CODE_YES # key is a special key
Key.from_value?(key)
else # ERR or something else unexpected
nil
end
end

# Get a character input for main loop
Expand Down