Highlight active menu item
This commit is contained in:
parent
7859e7949d
commit
570319627a
2 changed files with 43 additions and 11 deletions
24
lib/style.rb
24
lib/style.rb
|
@ -17,6 +17,7 @@ class Style
|
|||
Curses.init_pair editing_text_id, editing_text_color, editing_text_bg
|
||||
Curses.init_pair cursor_id, cursor_color, cursor_bg
|
||||
Curses.init_pair menu_item_id, menu_item_color, menu_item_bg
|
||||
Curses.init_pair active_menu_item_id, active_menu_item_color, active_menu_item_bg
|
||||
Curses.init_pair message_time_id, message_time_color, message_time_bg
|
||||
Curses.init_pair message_author_id, message_author_color, message_author_bg
|
||||
Curses.init_pair online_mark_id, online_mark_color, online_mark_bg
|
||||
|
@ -65,6 +66,13 @@ class Style
|
|||
Curses.attroff menu_item_attr
|
||||
end
|
||||
|
||||
def active_menu_item
|
||||
Curses.attron active_menu_item_attr
|
||||
yield
|
||||
ensure
|
||||
Curses.attroff active_menu_item_attr
|
||||
end
|
||||
|
||||
def message_time
|
||||
Curses.attron message_time_attr
|
||||
yield
|
||||
|
@ -119,6 +127,10 @@ private
|
|||
Curses.color_pair menu_item_id
|
||||
end
|
||||
|
||||
def active_menu_item_attr
|
||||
Curses.color_pair active_menu_item_id
|
||||
end
|
||||
|
||||
def message_time_attr
|
||||
Curses.color_pair message_time_id
|
||||
end
|
||||
|
@ -159,6 +171,10 @@ private
|
|||
@menu_item_id ||= self.class.counter
|
||||
end
|
||||
|
||||
def active_menu_item_id
|
||||
@active_menu_item_id ||= self.class.counter
|
||||
end
|
||||
|
||||
def message_time_id
|
||||
@message_time_id ||= self.class.counter
|
||||
end
|
||||
|
@ -223,6 +239,14 @@ private
|
|||
Curses::COLOR_CYAN
|
||||
end
|
||||
|
||||
def active_menu_item_color
|
||||
Curses::COLOR_BLACK
|
||||
end
|
||||
|
||||
def active_menu_item_bg
|
||||
Curses::COLOR_BLUE
|
||||
end
|
||||
|
||||
def message_time_color
|
||||
Curses::COLOR_CYAN
|
||||
end
|
||||
|
|
|
@ -11,6 +11,14 @@ module Widgets
|
|||
|
||||
SIDE_PADDING = 3
|
||||
|
||||
attr_reader :active
|
||||
|
||||
def initialize(*)
|
||||
super
|
||||
|
||||
@active = 0
|
||||
end
|
||||
|
||||
def draw
|
||||
ITEMS.each_with_index do |item, index|
|
||||
draw_item index, item
|
||||
|
@ -18,7 +26,7 @@ module Widgets
|
|||
end
|
||||
|
||||
def draw_item(index, name)
|
||||
Style.default.menu_item do
|
||||
Style.default.public_send(index == active ? :active_menu_item : :menu_item) do
|
||||
setpos SIDE_PADDING, 4 * index + 0
|
||||
Curses.addstr ' ' * (width - 2 * SIDE_PADDING)
|
||||
|
||||
|
|
Reference in a new issue