Add basic window management code for NCurses.cr
This commit is contained in:
parent
0c412c10e4
commit
bd8ad00026
1 changed files with 39 additions and 36 deletions
|
@ -16,7 +16,7 @@ module Noozoid
|
||||||
NCurses.start_color
|
NCurses.start_color
|
||||||
|
|
||||||
# define background color
|
# define background color
|
||||||
pair = NCurses::ColorPair.new(1).init(NCurses::Color::RED, NCurses::Color::BLACK)
|
pair = NCurses::ColorPair.new(1).init(NCurses::Color::WHITE, NCurses::Color::BLACK)
|
||||||
NCurses.bkgd(pair)
|
NCurses.bkgd(pair)
|
||||||
NCurses.curs_set(0)
|
NCurses.curs_set(0)
|
||||||
|
|
||||||
|
@ -30,17 +30,47 @@ module Noozoid
|
||||||
NCurses.move(x:0, y: 2)
|
NCurses.move(x:0, y: 2)
|
||||||
NCurses.addstr(NCurses.curses_version)
|
NCurses.addstr(NCurses.curses_version)
|
||||||
|
|
||||||
|
|
||||||
# attach models to views
|
|
||||||
#@main_window = MainView.new(self)
|
|
||||||
#@main_window.draw
|
|
||||||
#@main_window.wait
|
|
||||||
|
|
||||||
NCurses.notimeout(true)
|
NCurses.notimeout(true)
|
||||||
|
|
||||||
x = NCurses.maxx / 2
|
x = NCurses.maxx / 2
|
||||||
y = NCurses.maxy / 2
|
y = NCurses.maxy / 2
|
||||||
|
|
||||||
|
# NCurses.box(v: '|', h: '=')
|
||||||
|
|
||||||
|
routes = {
|
||||||
|
'q'.ord => -> do
|
||||||
|
NCurses.endwin
|
||||||
|
exit 0
|
||||||
|
return nil
|
||||||
|
end,
|
||||||
|
|
||||||
|
NCurses::KeyCode::ESC => -> do
|
||||||
|
NCurses.endwin
|
||||||
|
exit 0
|
||||||
|
return nil
|
||||||
|
end,
|
||||||
|
|
||||||
|
NCurses::KeyCode::LEFT => -> do
|
||||||
|
x -= 1
|
||||||
|
x = 0 if x < 0
|
||||||
|
end,
|
||||||
|
|
||||||
|
NCurses::KeyCode::RIGHT => -> do
|
||||||
|
x += 1
|
||||||
|
x = NCurses.maxx - 1 if x >= NCurses.maxx
|
||||||
|
end,
|
||||||
|
|
||||||
|
NCurses::KeyCode::UP => -> do
|
||||||
|
y -= 1
|
||||||
|
y = 0 if y < 0
|
||||||
|
end,
|
||||||
|
|
||||||
|
NCurses::KeyCode::DOWN => -> do
|
||||||
|
y += 1
|
||||||
|
y = NCurses.maxy - 2 if y >= NCurses.maxy - 1
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
loop do
|
loop do
|
||||||
NCurses.erase
|
NCurses.erase
|
||||||
NCurses.move(x: x, y: y)
|
NCurses.move(x: x, y: y)
|
||||||
|
@ -48,36 +78,9 @@ module Noozoid
|
||||||
NCurses.refresh
|
NCurses.refresh
|
||||||
|
|
||||||
key = NCurses.getch
|
key = NCurses.getch
|
||||||
|
routes[key].call if routes.keys.includes? key
|
||||||
case key
|
# ctx = { a: 1 }
|
||||||
when 'q', NCurses::KeyCode::ESC
|
|
||||||
break
|
|
||||||
|
|
||||||
when NCurses::KeyCode::LEFT
|
|
||||||
x -= 1
|
|
||||||
x = 0 if x < 0
|
|
||||||
|
|
||||||
when NCurses::KeyCode::RIGHT
|
|
||||||
x += 1
|
|
||||||
x = NCurses.maxx - 1 if x >= NCurses.maxx
|
|
||||||
|
|
||||||
when NCurses::KeyCode::UP
|
|
||||||
y -= 1
|
|
||||||
y = 0 if y < 0
|
|
||||||
|
|
||||||
when NCurses::KeyCode::DOWN
|
|
||||||
y += 1
|
|
||||||
y = NCurses.maxy - 2 if y >= NCurses.maxy - 1
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
NCurses.endwin
|
|
||||||
|
|
||||||
#rescue StandardError => e
|
|
||||||
#Curses.close_screen
|
|
||||||
#warn e.message unless e.nil?
|
|
||||||
#warn e.backtrace unless e.nil?
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue