From 1d571e79f34b29d08f6fe91b685fcefab07f99a0 Mon Sep 17 00:00:00 2001 From: Braiden Vasco Date: Wed, 26 Jul 2017 07:19:33 +0000 Subject: [PATCH] Align history messages --- lib/widgets/chat/history.rb | 48 +++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/lib/widgets/chat/history.rb b/lib/widgets/chat/history.rb index 1daa6f7..a051c07 100644 --- a/lib/widgets/chat/history.rb +++ b/lib/widgets/chat/history.rb @@ -19,24 +19,48 @@ module Widgets end end - def draw_message(offset, _out, time, name, text) - setpos 0, offset + def draw_message(offset, out, time, name, text) + if out + setpos props[:width] - name.length - time.length - 1, offset - Style.default.message_time window do - addstr time + Style.default.message_author window do + addstr name + end + + addstr ' ' + + Style.default.message_time window do + addstr time + end + else + setpos 0, offset + + Style.default.message_time window do + addstr time + end + + addstr ' ' + + Style.default.message_author window do + addstr name + end end - addstr ' ' + width = props[:width] / 3 * 2 + left = out ? props[:width] - width : 0 - Style.default.message_author window do - addstr name - end - - lines = (text.length / props[:width].to_f).ceil + lines = (text.length / width.to_f).ceil 1.upto lines do |line| - setpos 0, offset + line - addstr text[(props[:width] * (line - 1))...(props[:width] * 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