Allow to apply style to any window
This commit is contained in:
parent
abbbebf325
commit
1256a97479
8 changed files with 51 additions and 47 deletions
66
lib/style.rb
66
lib/style.rb
|
@ -24,81 +24,81 @@ class Style
|
|||
Curses.init_pair peer_info_name_id, peer_info_name_color, peer_info_name_bg
|
||||
end
|
||||
|
||||
def logo
|
||||
Curses.attron logo_attr
|
||||
def logo(window)
|
||||
window.attron logo_attr
|
||||
yield
|
||||
ensure
|
||||
Curses.attroff logo_attr
|
||||
window.attroff logo_attr
|
||||
end
|
||||
|
||||
def text
|
||||
Curses.attron text_attr
|
||||
def text(window)
|
||||
window.attron text_attr
|
||||
yield
|
||||
ensure
|
||||
Curses.attroff text_attr
|
||||
window.attroff text_attr
|
||||
end
|
||||
|
||||
def selection
|
||||
Curses.attron selection_attr
|
||||
def selection(window)
|
||||
window.attron selection_attr
|
||||
yield
|
||||
ensure
|
||||
Curses.attroff selection_attr
|
||||
window.attroff selection_attr
|
||||
end
|
||||
|
||||
def editing_text
|
||||
Curses.attron editing_text_attr
|
||||
def editing_text(window)
|
||||
window.attron editing_text_attr
|
||||
yield
|
||||
ensure
|
||||
Curses.attroff editing_text_attr
|
||||
window.attroff editing_text_attr
|
||||
end
|
||||
|
||||
def cursor
|
||||
Curses.attron cursor_attr
|
||||
def cursor(window)
|
||||
window.attron cursor_attr
|
||||
yield
|
||||
ensure
|
||||
Curses.attroff cursor_attr
|
||||
window.attroff cursor_attr
|
||||
end
|
||||
|
||||
def menu_item
|
||||
Curses.attron menu_item_attr
|
||||
def menu_item(window)
|
||||
window.attron menu_item_attr
|
||||
yield
|
||||
ensure
|
||||
Curses.attroff menu_item_attr
|
||||
window.attroff menu_item_attr
|
||||
end
|
||||
|
||||
def active_menu_item
|
||||
Curses.attron active_menu_item_attr
|
||||
def active_menu_item(window)
|
||||
window.attron active_menu_item_attr
|
||||
yield
|
||||
ensure
|
||||
Curses.attroff active_menu_item_attr
|
||||
window.attroff active_menu_item_attr
|
||||
end
|
||||
|
||||
def message_time
|
||||
Curses.attron message_time_attr
|
||||
def message_time(window)
|
||||
window.attron message_time_attr
|
||||
yield
|
||||
ensure
|
||||
Curses.attroff message_time_attr
|
||||
window.attroff message_time_attr
|
||||
end
|
||||
|
||||
def message_author
|
||||
Curses.attron message_author_attr
|
||||
def message_author(window)
|
||||
window.attron message_author_attr
|
||||
yield
|
||||
ensure
|
||||
Curses.attroff message_author_attr
|
||||
window.attroff message_author_attr
|
||||
end
|
||||
|
||||
def online_mark
|
||||
Curses.attron online_mark_attr
|
||||
def online_mark(window)
|
||||
window.attron online_mark_attr
|
||||
yield
|
||||
ensure
|
||||
Curses.attroff online_mark_attr
|
||||
window.attroff online_mark_attr
|
||||
end
|
||||
|
||||
def peer_info_name
|
||||
Curses.attron peer_info_name_attr
|
||||
def peer_info_name(window)
|
||||
window.attron peer_info_name_attr
|
||||
yield
|
||||
ensure
|
||||
Curses.attroff peer_info_name_attr
|
||||
window.attroff peer_info_name_attr
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -15,6 +15,10 @@ module Widgets
|
|||
@focused = false
|
||||
end
|
||||
|
||||
def window
|
||||
Curses
|
||||
end
|
||||
|
||||
def trigger(event); end
|
||||
|
||||
def render
|
||||
|
@ -26,11 +30,11 @@ module Widgets
|
|||
end
|
||||
|
||||
def setpos(x, y)
|
||||
Curses.setpos self.y + y, self.x + x
|
||||
window.setpos self.y + y, self.x + x
|
||||
end
|
||||
|
||||
def addstr(s)
|
||||
Curses.addstr s
|
||||
window.addstr s
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -38,18 +38,18 @@ module Widgets
|
|||
head_length = width - info_length
|
||||
head = text[0...head_length]
|
||||
|
||||
Style.default.message_time do
|
||||
Style.default.message_time window do
|
||||
addstr time
|
||||
end
|
||||
|
||||
addstr ' '
|
||||
|
||||
Style.default.message_author do
|
||||
Style.default.message_author window do
|
||||
addstr name
|
||||
addstr ': '
|
||||
end
|
||||
|
||||
Style.default.text do
|
||||
Style.default.text window do
|
||||
addstr head
|
||||
end
|
||||
|
||||
|
|
|
@ -14,11 +14,11 @@ module Widgets
|
|||
|
||||
def draw
|
||||
setpos 0, 0
|
||||
Style.default.online_mark do
|
||||
Style.default.online_mark window do
|
||||
addstr '[Online]'
|
||||
end
|
||||
addstr ' '
|
||||
Style.default.peer_info_name do
|
||||
Style.default.peer_info_name window do
|
||||
addstr name
|
||||
end
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ module Widgets
|
|||
end
|
||||
|
||||
def draw_item(index, name)
|
||||
Style.default.public_send(index == active ? :active_menu_item : :menu_item) do
|
||||
Style.default.public_send(index == active ? :active_menu_item : :menu_item, window) do
|
||||
setpos SIDE_PADDING, 4 * index + 0
|
||||
addstr ' ' * (width - 2 * SIDE_PADDING)
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ module Widgets
|
|||
end
|
||||
|
||||
def draw
|
||||
Style.default.logo do
|
||||
Style.default.logo window do
|
||||
LOGO.each_with_index do |s, index|
|
||||
setpos 0, index
|
||||
addstr s
|
||||
|
|
|
@ -26,7 +26,7 @@ module Widgets
|
|||
setpos 0, offset
|
||||
|
||||
if item[:online]
|
||||
Style.default.online_mark do
|
||||
Style.default.online_mark window do
|
||||
addstr '*'
|
||||
end
|
||||
else
|
||||
|
@ -35,7 +35,7 @@ module Widgets
|
|||
|
||||
addstr ' '
|
||||
|
||||
Style.default.public_send(index == active && focused ? :selection : :text) do
|
||||
Style.default.public_send(index == active && focused ? :selection : :text, window) do
|
||||
if item[:name].length <= width - 2
|
||||
addstr item[:name].ljust width - 2
|
||||
else
|
||||
|
|
|
@ -23,15 +23,15 @@ module Widgets
|
|||
under_cursor = cut[cursor_pos] || ' '
|
||||
after_cursor = cut[(1 + cursor_pos)..-1] || ''
|
||||
|
||||
Style.default.editing_text do
|
||||
Style.default.editing_text window do
|
||||
addstr before_cursor
|
||||
end
|
||||
|
||||
Style.default.public_send focused ? :cursor : :editing_text do
|
||||
Style.default.public_send focused ? :cursor : :editing_text, window do
|
||||
addstr under_cursor
|
||||
end
|
||||
|
||||
Style.default.editing_text do
|
||||
Style.default.editing_text window do
|
||||
addstr after_cursor
|
||||
end
|
||||
end
|
||||
|
|
Reference in a new issue