From ad31d7f808723f102871263acb687c9b123164cb Mon Sep 17 00:00:00 2001 From: Braiden Vasco Date: Wed, 26 Jul 2017 07:27:17 +0000 Subject: [PATCH] Add method Widgets::Chat::History#draw_header --- lib/widgets/chat/history.rb | 42 ++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/lib/widgets/chat/history.rb b/lib/widgets/chat/history.rb index a051c07..c49577e 100644 --- a/lib/widgets/chat/history.rb +++ b/lib/widgets/chat/history.rb @@ -20,6 +20,29 @@ module Widgets end def draw_message(offset, out, time, name, text) + draw_header offset, out, time, name + + width = props[:width] / 3 * 2 + left = out ? props[:width] - width : 0 + + lines = (text.length / width.to_f).ceil + + 1.upto lines do |line| + s = text[(width * (line - 1))...(width * line)] + + if out && s.length != width + setpos left + width - s.length, offset + line + else + setpos left, offset + line + end + + addstr s + end + + 1 + lines + end + + def draw_header(offset, out, name, time) if out setpos props[:width] - name.length - time.length - 1, offset @@ -45,25 +68,6 @@ module Widgets addstr name end end - - width = props[:width] / 3 * 2 - left = out ? props[:width] - width : 0 - - lines = (text.length / width.to_f).ceil - - 1.upto lines do |line| - s = text[(width * (line - 1))...(width * line)] - - if out && s.length != width - setpos left + width - s.length, offset + line - else - setpos left, offset + line - end - - addstr s - end - - 1 + lines end end end