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
|
Curses.init_pair peer_info_name_id, peer_info_name_color, peer_info_name_bg
|
||||||
end
|
end
|
||||||
|
|
||||||
def logo
|
def logo(window)
|
||||||
Curses.attron logo_attr
|
window.attron logo_attr
|
||||||
yield
|
yield
|
||||||
ensure
|
ensure
|
||||||
Curses.attroff logo_attr
|
window.attroff logo_attr
|
||||||
end
|
end
|
||||||
|
|
||||||
def text
|
def text(window)
|
||||||
Curses.attron text_attr
|
window.attron text_attr
|
||||||
yield
|
yield
|
||||||
ensure
|
ensure
|
||||||
Curses.attroff text_attr
|
window.attroff text_attr
|
||||||
end
|
end
|
||||||
|
|
||||||
def selection
|
def selection(window)
|
||||||
Curses.attron selection_attr
|
window.attron selection_attr
|
||||||
yield
|
yield
|
||||||
ensure
|
ensure
|
||||||
Curses.attroff selection_attr
|
window.attroff selection_attr
|
||||||
end
|
end
|
||||||
|
|
||||||
def editing_text
|
def editing_text(window)
|
||||||
Curses.attron editing_text_attr
|
window.attron editing_text_attr
|
||||||
yield
|
yield
|
||||||
ensure
|
ensure
|
||||||
Curses.attroff editing_text_attr
|
window.attroff editing_text_attr
|
||||||
end
|
end
|
||||||
|
|
||||||
def cursor
|
def cursor(window)
|
||||||
Curses.attron cursor_attr
|
window.attron cursor_attr
|
||||||
yield
|
yield
|
||||||
ensure
|
ensure
|
||||||
Curses.attroff cursor_attr
|
window.attroff cursor_attr
|
||||||
end
|
end
|
||||||
|
|
||||||
def menu_item
|
def menu_item(window)
|
||||||
Curses.attron menu_item_attr
|
window.attron menu_item_attr
|
||||||
yield
|
yield
|
||||||
ensure
|
ensure
|
||||||
Curses.attroff menu_item_attr
|
window.attroff menu_item_attr
|
||||||
end
|
end
|
||||||
|
|
||||||
def active_menu_item
|
def active_menu_item(window)
|
||||||
Curses.attron active_menu_item_attr
|
window.attron active_menu_item_attr
|
||||||
yield
|
yield
|
||||||
ensure
|
ensure
|
||||||
Curses.attroff active_menu_item_attr
|
window.attroff active_menu_item_attr
|
||||||
end
|
end
|
||||||
|
|
||||||
def message_time
|
def message_time(window)
|
||||||
Curses.attron message_time_attr
|
window.attron message_time_attr
|
||||||
yield
|
yield
|
||||||
ensure
|
ensure
|
||||||
Curses.attroff message_time_attr
|
window.attroff message_time_attr
|
||||||
end
|
end
|
||||||
|
|
||||||
def message_author
|
def message_author(window)
|
||||||
Curses.attron message_author_attr
|
window.attron message_author_attr
|
||||||
yield
|
yield
|
||||||
ensure
|
ensure
|
||||||
Curses.attroff message_author_attr
|
window.attroff message_author_attr
|
||||||
end
|
end
|
||||||
|
|
||||||
def online_mark
|
def online_mark(window)
|
||||||
Curses.attron online_mark_attr
|
window.attron online_mark_attr
|
||||||
yield
|
yield
|
||||||
ensure
|
ensure
|
||||||
Curses.attroff online_mark_attr
|
window.attroff online_mark_attr
|
||||||
end
|
end
|
||||||
|
|
||||||
def peer_info_name
|
def peer_info_name(window)
|
||||||
Curses.attron peer_info_name_attr
|
window.attron peer_info_name_attr
|
||||||
yield
|
yield
|
||||||
ensure
|
ensure
|
||||||
Curses.attroff peer_info_name_attr
|
window.attroff peer_info_name_attr
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -15,6 +15,10 @@ module Widgets
|
||||||
@focused = false
|
@focused = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def window
|
||||||
|
Curses
|
||||||
|
end
|
||||||
|
|
||||||
def trigger(event); end
|
def trigger(event); end
|
||||||
|
|
||||||
def render
|
def render
|
||||||
|
@ -26,11 +30,11 @@ module Widgets
|
||||||
end
|
end
|
||||||
|
|
||||||
def setpos(x, y)
|
def setpos(x, y)
|
||||||
Curses.setpos self.y + y, self.x + x
|
window.setpos self.y + y, self.x + x
|
||||||
end
|
end
|
||||||
|
|
||||||
def addstr(s)
|
def addstr(s)
|
||||||
Curses.addstr s
|
window.addstr s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,18 +38,18 @@ module Widgets
|
||||||
head_length = width - info_length
|
head_length = width - info_length
|
||||||
head = text[0...head_length]
|
head = text[0...head_length]
|
||||||
|
|
||||||
Style.default.message_time do
|
Style.default.message_time window do
|
||||||
addstr time
|
addstr time
|
||||||
end
|
end
|
||||||
|
|
||||||
addstr ' '
|
addstr ' '
|
||||||
|
|
||||||
Style.default.message_author do
|
Style.default.message_author window do
|
||||||
addstr name
|
addstr name
|
||||||
addstr ': '
|
addstr ': '
|
||||||
end
|
end
|
||||||
|
|
||||||
Style.default.text do
|
Style.default.text window do
|
||||||
addstr head
|
addstr head
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -14,11 +14,11 @@ module Widgets
|
||||||
|
|
||||||
def draw
|
def draw
|
||||||
setpos 0, 0
|
setpos 0, 0
|
||||||
Style.default.online_mark do
|
Style.default.online_mark window do
|
||||||
addstr '[Online]'
|
addstr '[Online]'
|
||||||
end
|
end
|
||||||
addstr ' '
|
addstr ' '
|
||||||
Style.default.peer_info_name do
|
Style.default.peer_info_name window do
|
||||||
addstr name
|
addstr name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ module Widgets
|
||||||
end
|
end
|
||||||
|
|
||||||
def draw_item(index, name)
|
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
|
setpos SIDE_PADDING, 4 * index + 0
|
||||||
addstr ' ' * (width - 2 * SIDE_PADDING)
|
addstr ' ' * (width - 2 * SIDE_PADDING)
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ module Widgets
|
||||||
end
|
end
|
||||||
|
|
||||||
def draw
|
def draw
|
||||||
Style.default.logo do
|
Style.default.logo window do
|
||||||
LOGO.each_with_index do |s, index|
|
LOGO.each_with_index do |s, index|
|
||||||
setpos 0, index
|
setpos 0, index
|
||||||
addstr s
|
addstr s
|
||||||
|
|
|
@ -26,7 +26,7 @@ module Widgets
|
||||||
setpos 0, offset
|
setpos 0, offset
|
||||||
|
|
||||||
if item[:online]
|
if item[:online]
|
||||||
Style.default.online_mark do
|
Style.default.online_mark window do
|
||||||
addstr '*'
|
addstr '*'
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
@ -35,7 +35,7 @@ module Widgets
|
||||||
|
|
||||||
addstr ' '
|
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
|
if item[:name].length <= width - 2
|
||||||
addstr item[:name].ljust width - 2
|
addstr item[:name].ljust width - 2
|
||||||
else
|
else
|
||||||
|
|
|
@ -23,15 +23,15 @@ module Widgets
|
||||||
under_cursor = cut[cursor_pos] || ' '
|
under_cursor = cut[cursor_pos] || ' '
|
||||||
after_cursor = cut[(1 + cursor_pos)..-1] || ''
|
after_cursor = cut[(1 + cursor_pos)..-1] || ''
|
||||||
|
|
||||||
Style.default.editing_text do
|
Style.default.editing_text window do
|
||||||
addstr before_cursor
|
addstr before_cursor
|
||||||
end
|
end
|
||||||
|
|
||||||
Style.default.public_send focused ? :cursor : :editing_text do
|
Style.default.public_send focused ? :cursor : :editing_text, window do
|
||||||
addstr under_cursor
|
addstr under_cursor
|
||||||
end
|
end
|
||||||
|
|
||||||
Style.default.editing_text do
|
Style.default.editing_text window do
|
||||||
addstr after_cursor
|
addstr after_cursor
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Reference in a new issue