Handle Tox::Friend#send_message exceptions
This commit is contained in:
parent
b3d653c982
commit
8e064c8ac0
4 changed files with 109 additions and 58 deletions
|
@ -23,6 +23,9 @@ Metrics/LineLength:
|
||||||
Metrics/MethodLength:
|
Metrics/MethodLength:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
|
Metrics/ParameterLists:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
Metrics/PerceivedComplexity:
|
Metrics/PerceivedComplexity:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
|
|
17
lib/main.rb
17
lib/main.rb
|
@ -263,7 +263,13 @@ private
|
||||||
|
|
||||||
return if text.empty?
|
return if text.empty?
|
||||||
|
|
||||||
@tox_client.friend(friend_number).send_message text
|
error = false
|
||||||
|
|
||||||
|
begin
|
||||||
|
@tox_client.friend(friend_number).send_message text
|
||||||
|
rescue
|
||||||
|
error = true
|
||||||
|
end
|
||||||
|
|
||||||
@state = state.merge(
|
@state = state.merge(
|
||||||
friends: state[:friends].merge(
|
friends: state[:friends].merge(
|
||||||
|
@ -274,10 +280,11 @@ private
|
||||||
),
|
),
|
||||||
|
|
||||||
history: (state[:friends][friend_number][:history] + [
|
history: (state[:friends][friend_number][:history] + [
|
||||||
out: true,
|
error: error,
|
||||||
time: Time.now.utc.freeze,
|
out: true,
|
||||||
name: @tox_client.name.freeze,
|
time: Time.now.utc.freeze,
|
||||||
text: text,
|
name: @tox_client.name.freeze,
|
||||||
|
text: text,
|
||||||
]).freeze,
|
]).freeze,
|
||||||
).freeze,
|
).freeze,
|
||||||
).freeze,
|
).freeze,
|
||||||
|
|
121
lib/style.rb
121
lib/style.rb
|
@ -18,13 +18,15 @@ class Style
|
||||||
Curses.init_pair cursor_id, cursor_color, cursor_bg
|
Curses.init_pair cursor_id, cursor_color, cursor_bg
|
||||||
Curses.init_pair menu_item_id, menu_item_color, menu_item_bg
|
Curses.init_pair menu_item_id, menu_item_color, menu_item_bg
|
||||||
Curses.init_pair active_menu_item_id, active_menu_item_color, active_menu_item_bg
|
Curses.init_pair active_menu_item_id, active_menu_item_color, active_menu_item_bg
|
||||||
Curses.init_pair message_time_id, message_time_color, message_time_bg
|
|
||||||
Curses.init_pair message_author_id, message_author_color, message_author_bg
|
|
||||||
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
|
||||||
|
|
||||||
Curses.init_pair online_mark_id, online_mark_color, online_mark_bg
|
Curses.init_pair online_mark_id, online_mark_color, online_mark_bg
|
||||||
Curses.init_pair away_mark_id, away_mark_color, away_mark_bg
|
Curses.init_pair away_mark_id, away_mark_color, away_mark_bg
|
||||||
Curses.init_pair busy_mark_id, busy_mark_color, busy_mark_bg
|
Curses.init_pair busy_mark_id, busy_mark_color, busy_mark_bg
|
||||||
|
|
||||||
|
Curses.init_pair message_time_id, message_time_color, message_time_bg
|
||||||
|
Curses.init_pair message_author_id, message_author_color, message_author_bg
|
||||||
|
Curses.init_pair message_error_id, message_error_color, message_error_bg
|
||||||
end
|
end
|
||||||
|
|
||||||
def logo(window)
|
def logo(window)
|
||||||
|
@ -76,20 +78,6 @@ class Style
|
||||||
window.attroff active_menu_item_attr
|
window.attroff active_menu_item_attr
|
||||||
end
|
end
|
||||||
|
|
||||||
def message_time(window)
|
|
||||||
window.attron message_time_attr
|
|
||||||
yield
|
|
||||||
ensure
|
|
||||||
window.attroff message_time_attr
|
|
||||||
end
|
|
||||||
|
|
||||||
def message_author(window)
|
|
||||||
window.attron message_author_attr
|
|
||||||
yield
|
|
||||||
ensure
|
|
||||||
window.attroff message_author_attr
|
|
||||||
end
|
|
||||||
|
|
||||||
def peer_info_name(window)
|
def peer_info_name(window)
|
||||||
window.attron peer_info_name_attr
|
window.attron peer_info_name_attr
|
||||||
yield
|
yield
|
||||||
|
@ -118,6 +106,27 @@ class Style
|
||||||
window.attroff busy_mark_attr
|
window.attroff busy_mark_attr
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def message_time(window)
|
||||||
|
window.attron message_time_attr
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
window.attroff message_time_attr
|
||||||
|
end
|
||||||
|
|
||||||
|
def message_author(window)
|
||||||
|
window.attron message_author_attr
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
window.attroff message_author_attr
|
||||||
|
end
|
||||||
|
|
||||||
|
def message_error(window)
|
||||||
|
window.attron message_error_attr
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
window.attroff message_error_attr
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def logo_attr
|
def logo_attr
|
||||||
|
@ -148,14 +157,6 @@ private
|
||||||
Curses.color_pair active_menu_item_id
|
Curses.color_pair active_menu_item_id
|
||||||
end
|
end
|
||||||
|
|
||||||
def message_time_attr
|
|
||||||
Curses.color_pair message_time_id
|
|
||||||
end
|
|
||||||
|
|
||||||
def message_author_attr
|
|
||||||
Curses.color_pair(message_author_id) | Curses::A_BOLD
|
|
||||||
end
|
|
||||||
|
|
||||||
def peer_info_name_attr
|
def peer_info_name_attr
|
||||||
Curses.color_pair(peer_info_name_id) | Curses::A_BOLD
|
Curses.color_pair(peer_info_name_id) | Curses::A_BOLD
|
||||||
end
|
end
|
||||||
|
@ -172,6 +173,18 @@ private
|
||||||
Curses.color_pair busy_mark_id
|
Curses.color_pair busy_mark_id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def message_time_attr
|
||||||
|
Curses.color_pair message_time_id
|
||||||
|
end
|
||||||
|
|
||||||
|
def message_author_attr
|
||||||
|
Curses.color_pair(message_author_id) | Curses::A_BOLD
|
||||||
|
end
|
||||||
|
|
||||||
|
def message_error_attr
|
||||||
|
Curses.color_pair message_error_id
|
||||||
|
end
|
||||||
|
|
||||||
def logo_id
|
def logo_id
|
||||||
@logo_id ||= self.class.counter
|
@logo_id ||= self.class.counter
|
||||||
end
|
end
|
||||||
|
@ -200,14 +213,6 @@ private
|
||||||
@active_menu_item_id ||= self.class.counter
|
@active_menu_item_id ||= self.class.counter
|
||||||
end
|
end
|
||||||
|
|
||||||
def message_time_id
|
|
||||||
@message_time_id ||= self.class.counter
|
|
||||||
end
|
|
||||||
|
|
||||||
def message_author_id
|
|
||||||
@message_author_id ||= self.class.counter
|
|
||||||
end
|
|
||||||
|
|
||||||
def peer_info_name_id
|
def peer_info_name_id
|
||||||
@peer_info_name_id ||= self.class.counter
|
@peer_info_name_id ||= self.class.counter
|
||||||
end
|
end
|
||||||
|
@ -224,6 +229,18 @@ private
|
||||||
@busy_mark_id ||= self.class.counter
|
@busy_mark_id ||= self.class.counter
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def message_time_id
|
||||||
|
@message_time_id ||= self.class.counter
|
||||||
|
end
|
||||||
|
|
||||||
|
def message_author_id
|
||||||
|
@message_author_id ||= self.class.counter
|
||||||
|
end
|
||||||
|
|
||||||
|
def message_error_id
|
||||||
|
@message_error_id ||= self.class.counter
|
||||||
|
end
|
||||||
|
|
||||||
def logo_color
|
def logo_color
|
||||||
Curses::COLOR_BLUE
|
Curses::COLOR_BLUE
|
||||||
end
|
end
|
||||||
|
@ -280,22 +297,6 @@ private
|
||||||
Curses::COLOR_BLUE
|
Curses::COLOR_BLUE
|
||||||
end
|
end
|
||||||
|
|
||||||
def message_time_color
|
|
||||||
Curses::COLOR_CYAN
|
|
||||||
end
|
|
||||||
|
|
||||||
def message_time_bg
|
|
||||||
Curses::COLOR_BLACK
|
|
||||||
end
|
|
||||||
|
|
||||||
def message_author_color
|
|
||||||
Curses::COLOR_GREEN
|
|
||||||
end
|
|
||||||
|
|
||||||
def message_author_bg
|
|
||||||
Curses::COLOR_BLACK
|
|
||||||
end
|
|
||||||
|
|
||||||
def peer_info_name_color
|
def peer_info_name_color
|
||||||
Curses::COLOR_WHITE
|
Curses::COLOR_WHITE
|
||||||
end
|
end
|
||||||
|
@ -327,4 +328,28 @@ private
|
||||||
def busy_mark_bg
|
def busy_mark_bg
|
||||||
Curses::COLOR_BLACK
|
Curses::COLOR_BLACK
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def message_time_color
|
||||||
|
Curses::COLOR_CYAN
|
||||||
|
end
|
||||||
|
|
||||||
|
def message_time_bg
|
||||||
|
Curses::COLOR_BLACK
|
||||||
|
end
|
||||||
|
|
||||||
|
def message_author_color
|
||||||
|
Curses::COLOR_GREEN
|
||||||
|
end
|
||||||
|
|
||||||
|
def message_author_bg
|
||||||
|
Curses::COLOR_BLACK
|
||||||
|
end
|
||||||
|
|
||||||
|
def message_error_color
|
||||||
|
Curses::COLOR_RED
|
||||||
|
end
|
||||||
|
|
||||||
|
def message_error_bg
|
||||||
|
Curses::COLOR_BLACK
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,13 +13,13 @@ module Widgets
|
||||||
offset = 0
|
offset = 0
|
||||||
|
|
||||||
props[:messages].reverse_each do |msg|
|
props[:messages].reverse_each do |msg|
|
||||||
offset += draw_message offset, msg[:out], msg[:time].strftime('%H:%M:%S'), msg[:name], msg[:text]
|
offset += draw_message offset, msg[:error], msg[:out], msg[:time].strftime('%H:%M:%S'), msg[:name], msg[:text]
|
||||||
|
|
||||||
break if offset >= props[:height]
|
break if offset >= props[:height]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def draw_message(offset, out, time, name, text)
|
def draw_message(offset, error, out, time, name, text)
|
||||||
width = props[:width] / 3 * 2
|
width = props[:width] / 3 * 2
|
||||||
left = out ? props[:width] - width : 0
|
left = out ? props[:width] - width : 0
|
||||||
|
|
||||||
|
@ -37,14 +37,22 @@ module Widgets
|
||||||
addstr s
|
addstr s
|
||||||
end
|
end
|
||||||
|
|
||||||
draw_header props[:height] - offset - lines - 1, out, time, name
|
draw_header props[:height] - offset - lines - 1, error, out, time, name
|
||||||
|
|
||||||
1 + lines
|
1 + lines
|
||||||
end
|
end
|
||||||
|
|
||||||
def draw_header(y, out, name, time)
|
def draw_header(y, error, out, name, time)
|
||||||
if out
|
if out
|
||||||
setpos props[:width] - name.length - time.length - 1, y
|
setpos props[:width] - name.length - time.length - (error ? 3 : 1), y
|
||||||
|
|
||||||
|
if error
|
||||||
|
Style.default.message_error window do
|
||||||
|
addstr 'x'
|
||||||
|
end
|
||||||
|
|
||||||
|
addstr ' '
|
||||||
|
end
|
||||||
|
|
||||||
Style.default.message_time window do
|
Style.default.message_time window do
|
||||||
addstr time
|
addstr time
|
||||||
|
@ -67,6 +75,14 @@ module Widgets
|
||||||
Style.default.message_time window do
|
Style.default.message_time window do
|
||||||
addstr time
|
addstr time
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if error
|
||||||
|
addstr ' '
|
||||||
|
|
||||||
|
Style.default.message_error window do
|
||||||
|
addstr 'x'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Reference in a new issue