From 34bfb32ecf2cea5e5de95980beedb681139d9c01 Mon Sep 17 00:00:00 2001 From: hut Date: Fri, 10 Apr 2009 00:00:00 +0200 Subject: new minor version --- interface/ncurses.rb | 68 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 13 deletions(-) (limited to 'interface/ncurses.rb') diff --git a/interface/ncurses.rb b/interface/ncurses.rb index 0d2659e4..a383a570 100644 --- a/interface/ncurses.rb +++ b/interface/ncurses.rb @@ -9,8 +9,18 @@ module Interface '' when ?\b, Ncurses::KEY_BACKSPACE '' + when Ncurses::KEY_RIGHT + '' + when Ncurses::KEY_LEFT + '' + when Ncurses::KEY_UP + '' + when Ncurses::KEY_DOWN + '' when ?\e '' +# when ?\s +# '' when ?\t '' when 32 @@ -18,6 +28,7 @@ module Interface when 0..127 key.chr else + log(key) '' end end @@ -83,10 +94,9 @@ module Interface Ncurses.start_color Ncurses.use_default_colors -# Ncurses.cbreak Ncurses.noecho Ncurses.curs_set 0 - Ncurses.halfdelay(1000) + Ncurses.halfdelay(10000) @@colortable = [] end @@ -97,15 +107,16 @@ module Interface Ncurses.endwin end + def cleari + Ncurses.mvaddstr(0, 0, ' ' * (lines * cols)) + end + def geti Interface::keytable(Ncurses.getch) end def set_title(x) -# closei - print "\e]2;#{x}\007" -# system('echo', '-n', '-e', '"\e2;' + x + '\007"') -# starti + print "\e]2;#{x}\b" end def lines @@ -135,22 +146,53 @@ module Interface end def color(fg = -1, bg = -1) - Ncurses.color_set(get_color(fg,bg), nil) + if OPTIONS['color'] + Ncurses.color_set(get_color(fg,bg), nil) + end end def color_at y, x=0, len=-1, fg=-1, bg=-1 - if y < 0 then y += Ncurses.LINES end - Ncurses.mvchgat(y, x, len, 0, get_color(fg, bg), nil) + if OPTIONS['color'] + if y < 0 then y += Ncurses.LINES end + Ncurses.mvchgat(y, x, len, 0, get_color(fg, bg), nil) + end end def color_bold_at y, x=0, len=-1, fg=-1, bg=-1 - if y < 0 then y += Ncurses.LINES end - Ncurses.mvchgat(y, x, len, Ncurses::A_BOLD, get_color(fg, bg), nil) + if OPTIONS['color'] + if y < 0 then y += Ncurses.LINES end + Ncurses.mvchgat(y, x, len, Ncurses::A_BOLD, get_color(fg, bg), nil) + end end def color_reverse_at y, x=0, len=-1, fg=-1, bg=-1 - if y < 0 then y += Ncurses.LINES end - Ncurses.mvchgat(y, x, len, Ncurses::A_REVERSE, get_color(fg, bg), nil) + if OPTIONS['color'] + if y < 0 then y += Ncurses.LINES end + Ncurses.mvchgat(y, x, len, Ncurses::A_REVERSE, get_color(fg, bg), nil) + else + Ncurses.mvchgat(y, x, len, Ncurses::A_REVERSE, 0, nil) + end + end + +# runi(:command => String/Array, :wait=>false) +# runi('ä́', 'b', 'c') + def runi(hash, *args) + wait = false + if Array === hash + command = hash + elsif String === hash + command = [hash, *args] + else + command = hash[:command] or return false + wait = hash[:wait] if hash.has_key? :wait + end + + closei + + system(*command) + gets if wait + + starti end def get_color(fg, bg) -- cgit 1.4.1-2-gfad0