From db45c20724a7a23defe7816dc014f77e03a435c7 Mon Sep 17 00:00:00 2001 From: Braiden Vasco Date: Sat, 22 Jul 2017 14:27:14 +0000 Subject: [PATCH] Add method Widgets::Base#setpos --- lib/widgets/base.rb | 4 ++++ lib/widgets/chat/history.rb | 4 ++-- lib/widgets/chat/info.rb | 4 ++-- lib/widgets/menu.rb | 6 +++--- lib/widgets/menu/logo.rb | 2 +- lib/widgets/peers/list.rb | 2 +- lib/widgets/text.rb | 2 +- 7 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/widgets/base.rb b/lib/widgets/base.rb index 5d6c6ac..3c5cc73 100644 --- a/lib/widgets/base.rb +++ b/lib/widgets/base.rb @@ -24,5 +24,9 @@ module Widgets def draw raise NotImplementedError, "#{self.class}#draw" end + + def setpos(x, y) + Curses.setpos y, x + end end end diff --git a/lib/widgets/chat/history.rb b/lib/widgets/chat/history.rb index 6679a08..9882781 100644 --- a/lib/widgets/chat/history.rb +++ b/lib/widgets/chat/history.rb @@ -32,7 +32,7 @@ module Widgets end def draw_message(offset, time, name, text) - Curses.setpos y + offset, x + setpos x, y + offset info_length = time.length + 1 + name.length + 2 head_length = width - info_length @@ -58,7 +58,7 @@ module Widgets lines = (tail_length / width.to_f).ceil 1.upto lines do |line| - Curses.setpos y + offset + line, x + setpos x, y + offset + line Curses.addstr tail[(width * (line - 1))...(width * line)] end diff --git a/lib/widgets/chat/info.rb b/lib/widgets/chat/info.rb index 95dd918..6716214 100644 --- a/lib/widgets/chat/info.rb +++ b/lib/widgets/chat/info.rb @@ -13,7 +13,7 @@ module Widgets end def draw - Curses.setpos y, x + setpos x, y Style.default.online_mark do Curses.addstr '[Online]' end @@ -22,7 +22,7 @@ module Widgets Curses.addstr name end - Curses.setpos y + 1, x + setpos x, y + 1 Curses.addstr 'Public key: ' Curses.addstr public_key end diff --git a/lib/widgets/menu.rb b/lib/widgets/menu.rb index b71dd2e..b4b98d7 100644 --- a/lib/widgets/menu.rb +++ b/lib/widgets/menu.rb @@ -21,13 +21,13 @@ module Widgets ITEMS.each_with_index do |item, index| 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.setpos 1 + list_y + index * 4, 2 + setpos 2, 1 + list_y + index * 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) end end diff --git a/lib/widgets/menu/logo.rb b/lib/widgets/menu/logo.rb index 16c46a8..e5b38cb 100644 --- a/lib/widgets/menu/logo.rb +++ b/lib/widgets/menu/logo.rb @@ -22,7 +22,7 @@ module Widgets def draw Style.default.logo do LOGO.each_with_index do |s, index| - Curses.setpos y + index, x + setpos x, y + index Curses.addstr s end end diff --git a/lib/widgets/peers/list.rb b/lib/widgets/peers/list.rb index 9e9cf9a..a8ab70c 100644 --- a/lib/widgets/peers/list.rb +++ b/lib/widgets/peers/list.rb @@ -23,7 +23,7 @@ module Widgets items[top...(top + height)].each_with_index.each do |item, offset| index = top + offset - Curses.setpos y + offset, x + setpos x, y + offset if item[:online] Style.default.online_mark do diff --git a/lib/widgets/text.rb b/lib/widgets/text.rb index 0276753..7b7c2e6 100644 --- a/lib/widgets/text.rb +++ b/lib/widgets/text.rb @@ -17,7 +17,7 @@ module Widgets cut = text[start...start + total] - Curses.setpos y, x + setpos x, y before_cursor = cut[0...cursor_pos] under_cursor = cut[cursor_pos] || ' '