Archived
1
0
Fork 0

Add method Widgets::Base#setpos

This commit is contained in:
Braiden Vasco 2017-07-22 14:27:14 +00:00
parent bc25b2de92
commit db45c20724
7 changed files with 14 additions and 10 deletions

View file

@ -24,5 +24,9 @@ module Widgets
def draw def draw
raise NotImplementedError, "#{self.class}#draw" raise NotImplementedError, "#{self.class}#draw"
end end
def setpos(x, y)
Curses.setpos y, x
end
end end
end end

View file

@ -32,7 +32,7 @@ module Widgets
end end
def draw_message(offset, time, name, text) def draw_message(offset, time, name, text)
Curses.setpos y + offset, x setpos x, y + offset
info_length = time.length + 1 + name.length + 2 info_length = time.length + 1 + name.length + 2
head_length = width - info_length head_length = width - info_length
@ -58,7 +58,7 @@ module Widgets
lines = (tail_length / width.to_f).ceil lines = (tail_length / width.to_f).ceil
1.upto lines do |line| 1.upto lines do |line|
Curses.setpos y + offset + line, x setpos x, y + offset + line
Curses.addstr tail[(width * (line - 1))...(width * line)] Curses.addstr tail[(width * (line - 1))...(width * line)]
end end

View file

@ -13,7 +13,7 @@ module Widgets
end end
def draw def draw
Curses.setpos y, x setpos x, y
Style.default.online_mark do Style.default.online_mark do
Curses.addstr '[Online]' Curses.addstr '[Online]'
end end
@ -22,7 +22,7 @@ module Widgets
Curses.addstr name Curses.addstr name
end end
Curses.setpos y + 1, x setpos x, y + 1
Curses.addstr 'Public key: ' Curses.addstr 'Public key: '
Curses.addstr public_key Curses.addstr public_key
end end

View file

@ -21,13 +21,13 @@ module Widgets
ITEMS.each_with_index do |item, index| ITEMS.each_with_index do |item, index|
Style.default.menu_item do Style.default.menu_item do
Curses.setpos 0 + list_y + index * 4, 2 setpos 2, 0 + list_y + index * 4
Curses.addstr ' ' * (width - 4) Curses.addstr ' ' * (width - 4)
Curses.setpos 1 + list_y + index * 4, 2 setpos 2, 1 + list_y + index * 4
Curses.addstr " #{item}".ljust width - 4 Curses.addstr " #{item}".ljust width - 4
Curses.setpos 2 + list_y + index * 4, 2 setpos 2, 2 + list_y + index * 4
Curses.addstr ' ' * (width - 4) Curses.addstr ' ' * (width - 4)
end end
end end

View file

@ -22,7 +22,7 @@ module Widgets
def draw def draw
Style.default.logo do Style.default.logo do
LOGO.each_with_index do |s, index| LOGO.each_with_index do |s, index|
Curses.setpos y + index, x setpos x, y + index
Curses.addstr s Curses.addstr s
end end
end end

View file

@ -23,7 +23,7 @@ module Widgets
items[top...(top + height)].each_with_index.each do |item, offset| items[top...(top + height)].each_with_index.each do |item, offset|
index = top + offset index = top + offset
Curses.setpos y + offset, x setpos x, y + offset
if item[:online] if item[:online]
Style.default.online_mark do Style.default.online_mark do

View file

@ -17,7 +17,7 @@ module Widgets
cut = text[start...start + total] cut = text[start...start + total]
Curses.setpos y, x setpos x, y
before_cursor = cut[0...cursor_pos] before_cursor = cut[0...cursor_pos]
under_cursor = cut[cursor_pos] || ' ' under_cursor = cut[cursor_pos] || ' '