Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change: Add support for more ncurses functions #5

Merged
merged 6 commits into from
Aug 31, 2018
Merged
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
1 change: 1 addition & 0 deletions src/ncurses.cr
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ module NCurses

defwrapper raw, noraw, echo, noecho, cbreak, nocbreak, start_color, nl, nonl

delegate curs_set, to: stdscr
delegate keypad, to: stdscr
delegate notimeout, to: stdscr
delegate nodelay, to: stdscr
Expand Down
5 changes: 5 additions & 0 deletions src/ncurses/libncurses.cr
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ lib LibNCurses

enum KeyCode : LibC::Int
ESC = 27
RETURN = 10
CODE_YES = 0o400
MIN = 0o401
BREAK = 0o401
Expand Down Expand Up @@ -200,6 +201,8 @@ lib LibNCurses
fun wborder(w : Window, ls : Chtype, rs : Chtype, ts : Chtype, bs : Chtype,
tl : Chtype, tr : Chtype, bl : Chtype, br : Chtype) : Result
fun touchwin(w : Window) : Result
fun subwin(parent : Window, height : LibC::Int, width : LibC::Int, y : LibC::Int, x : LibC::Int) : Window
fun derwin(parent : Window, height : LibC::Int, width : LibC::Int, y : LibC::Int, x : LibC::Int) : Window

# Pad
fun newpad(height : LibC::Int, width : LibC::Int) : Window
Expand All @@ -208,6 +211,7 @@ lib LibNCurses
smaxrow : LibC::Int, smaxcol : LibC::Int) : Result

# Cursor
fun curs_set(i : LibC::Int) : Result
fun wmove(w : Window, y : LibC::Int, x : LibC::Int) : Result

# mv prefix
Expand All @@ -219,6 +223,7 @@ lib LibNCurses
# Size
fun getmaxx(w : Window) : LibC::Int
fun getmaxy(w : Window) : LibC::Int
fun wresize(w : Window, height : LibC::Int, width : LibC::Int) : Result

fun delwin(w : Window)

Expand Down
14 changes: 13 additions & 1 deletion src/ncurses/raw_window.cr
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ module NCurses
check_error(LibNCurses.werase(raw_win), "werase")
end

def curs_set(value : Int)
check_error(LibNCurses.curs_set(value), "curs_set")
end

private def to_chtype(x : Char | Attribute | Int)
case x
when Char
Expand Down Expand Up @@ -78,7 +82,11 @@ module NCurses
end

def addstr(s)
check_error(LibNCurses.waddnstr(raw_win, s.to_unsafe, s.bytesize), "waddnstr")
addnstr(s, s.bytesize)
end

def addnstr(s, i : Int32)
check_error(LibNCurses.waddnstr(raw_win, s.to_unsafe, i), "waddnstr")
end

def mvaddstr(s, y, x)
Expand Down Expand Up @@ -149,5 +157,9 @@ module NCurses
def maxyx
{ maxy, maxx }
end

def resize(height, width)
check_error(LibNCurses.wresize(raw_win, height, width), "wresize")
end
end
end
18 changes: 18 additions & 0 deletions src/ncurses/window.cr
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ module NCurses
end
end

def self.subwin(height, width, y, x, parent, &blk)
win = new(LibNCurses.subwin(parent, height, width, y, x))
begin
yield win
ensure
win.close
end
end

def self.derwin(height, width, y, x, parent, &blk)
win = new(LibNCurses.derwin(parent, height, width, y, x))
begin
yield win
ensure
win.close
end
end

def finalize
close
end
Expand Down