diff options
Diffstat (limited to 'code/cli.rb')
-rw-r--r-- | code/cli.rb | 108 |
1 files changed, 63 insertions, 45 deletions
diff --git a/code/cli.rb b/code/cli.rb index 0f915634..12561e36 100644 --- a/code/cli.rb +++ b/code/cli.rb @@ -104,39 +104,57 @@ module CLI end end - def color(fg = -1, bg = -1) - 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, attributes=0 - if OPTIONS['color'] - if y < 0 then y += Ncurses.LINES end - Ncurses.mvchgat(y, x, len, attributes, get_color(fg, bg), nil) - end - end - - def color_bold_at y, x=0, len=-1, fg=-1, bg=-1 - color_at(y, x, len, fg, bg, attributes = Ncurses::A_BOLD) - end - - def color_reverse_bold_at y, x=0, len=-1, fg=-1, bg=-1 - if OPTIONS['color'] - color_at(y, x, len, fg, bg, Ncurses::A_REVERSE | Ncurses::A_BOLD) + def attr_set(fg=-1, bg=-1, attr = nil) + fg, bg, attr = fg if fg.is_a? Array + if attr + Ncurses.attrset(attr | Ncurses.COLOR_PAIR(get_color(fg, bg))) else - Ncurses.mvchgat(y, x, len, Ncurses::A_REVERSE | Ncurses::A_BOLD, 0, nil) + Ncurses.color_set(get_color(fg, bg), nil) end end - alias color_bold_reverse_at color_reverse_bold_at - def color_reverse_at y, x=0, len=-1, fg=-1, bg=-1 - if OPTIONS['color'] - color_at(y, x, len, fg, bg, Ncurses::A_REVERSE) - else - Ncurses.mvchgat(y, x, len, Ncurses::A_REVERSE, 0, nil) - end - end + def attr_at(y=0, x=0, len=-1, fg=-1, bg=-1, attr=0) + fg, bg, attr = fg if fg.is_a? Array + y += lines if y < 0 + x += cols if x < 0 + attr ||= 0 + + Ncurses.mvchgat(y, x, len, attr, get_color(fg, bg), nil) + end + +# def color(fg = -1, bg = -1) +# 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, attributes=0 +# if OPTIONS['color'] +# if y < 0 then y += Ncurses.LINES end +# Ncurses.mvchgat(y, x, len, attributes, get_color(fg, bg), nil) +# end +# end +# +# def color_bold_at y, x=0, len=-1, fg=-1, bg=-1 +# color_at(y, x, len, fg, bg, attributes = Ncurses::A_BOLD) +# end +# +# def color_reverse_bold_at y, x=0, len=-1, fg=-1, bg=-1 +# if OPTIONS['color'] +# color_at(y, x, len, fg, bg, Ncurses::A_REVERSE | Ncurses::A_BOLD) +# else +# Ncurses.mvchgat(y, x, len, Ncurses::A_REVERSE | Ncurses::A_BOLD, 0, nil) +# end +# end +# alias color_bold_reverse_at color_reverse_bold_at +# +# def color_reverse_at y, x=0, len=-1, fg=-1, bg=-1 +# if OPTIONS['color'] +# color_at(y, x, len, fg, bg, Ncurses::A_REVERSE) +# else +# Ncurses.mvchgat(y, x, len, Ncurses::A_REVERSE, 0, nil) +# end +# end def get_color(fg, bg) n = bg+2 + 9*(fg+2) @@ -149,20 +167,20 @@ module CLI end return color end - - def bold(b = true) - if b - Ncurses.attron(Ncurses::A_BOLD) - else - Ncurses.attroff(Ncurses::A_BOLD) - end - end - - def reverse(b = true) - if b - Ncurses.attron(Ncurses::A_REVERSE) - else - Ncurses.attroff(Ncurses::A_REVERSE) - end - end +# +# def bold(b = true) +# if b +# Ncurses.attron(Ncurses::A_BOLD) +# else +# Ncurses.attroff(Ncurses::A_BOLD) +# end +# end +# +# def reverse(b = true) +# if b +# Ncurses.attron(Ncurses::A_REVERSE) +# else +# Ncurses.attroff(Ncurses::A_REVERSE) +# end +# end end |