2017-07-21 02:48:04 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-25 19:06:37 -04:00
|
|
|
require 'tox'
|
|
|
|
|
2017-07-21 02:48:04 -04:00
|
|
|
require 'thread'
|
|
|
|
|
2017-07-27 19:18:28 -04:00
|
|
|
require 'helpers'
|
2017-07-24 08:48:22 -04:00
|
|
|
require 'screen'
|
2017-07-21 10:00:01 -04:00
|
|
|
|
2017-07-21 02:48:04 -04:00
|
|
|
class Main
|
2017-07-25 19:13:06 -04:00
|
|
|
SAVEDATA_FILENAME = File.expand_path '../savedata', __dir__
|
|
|
|
|
2017-07-21 02:48:04 -04:00
|
|
|
def self.inherited(_base)
|
|
|
|
raise "#{self} is final"
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.mutex
|
|
|
|
(@mutex ||= Mutex.new).tap { freeze }
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
raise "#{self.class} is singleton" unless self.class.mutex.try_lock
|
|
|
|
call
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def call
|
2017-07-25 19:13:06 -04:00
|
|
|
tox_options = Tox::Options.new
|
|
|
|
tox_options.savedata = File.binread SAVEDATA_FILENAME if File.exist? SAVEDATA_FILENAME
|
|
|
|
|
|
|
|
@tox_client = Tox::Client.new tox_options
|
2017-07-25 19:06:37 -04:00
|
|
|
|
2017-07-25 19:26:38 -04:00
|
|
|
on_friends_load @tox_client.friends
|
|
|
|
|
2017-07-25 22:19:57 -04:00
|
|
|
@tox_client.on_iteration(&method(:on_iteration))
|
2017-07-25 22:30:40 -04:00
|
|
|
@tox_client.on_friend_request(&method(:on_friend_request))
|
2017-07-25 21:17:18 -04:00
|
|
|
@tox_client.on_friend_message(&method(:on_friend_message))
|
2017-07-25 23:10:47 -04:00
|
|
|
@tox_client.on_friend_name_change(&method(:on_friend_name_change))
|
2017-07-25 23:26:50 -04:00
|
|
|
@tox_client.on_friend_status_message_change(&method(:on_friend_status_message_change))
|
2017-07-25 23:46:15 -04:00
|
|
|
@tox_client.on_friend_status_change(&method(:on_friend_status_change))
|
2017-07-25 21:17:18 -04:00
|
|
|
|
2017-07-24 08:48:22 -04:00
|
|
|
@screen = Screen.new
|
2017-07-22 05:46:15 -04:00
|
|
|
Style.default = Style.new
|
2017-07-21 02:48:04 -04:00
|
|
|
|
2017-07-25 22:13:11 -04:00
|
|
|
@tox_client.run
|
|
|
|
ensure
|
2017-07-25 19:13:06 -04:00
|
|
|
@screen&.close
|
|
|
|
File.binwrite SAVEDATA_FILENAME, @tox_client.savedata if @tox_client
|
2017-07-21 02:48:04 -04:00
|
|
|
end
|
|
|
|
|
2017-07-25 22:35:43 -04:00
|
|
|
#################
|
|
|
|
# Tox callbacks #
|
|
|
|
#################
|
|
|
|
|
2017-07-25 22:19:57 -04:00
|
|
|
def on_iteration
|
2017-07-24 08:48:22 -04:00
|
|
|
@screen.poll
|
2017-07-25 22:19:14 -04:00
|
|
|
@screen.props = state
|
|
|
|
@screen.render
|
2017-07-21 08:03:53 -04:00
|
|
|
end
|
2017-07-24 18:38:23 -04:00
|
|
|
|
2017-07-25 19:26:38 -04:00
|
|
|
def on_friends_load(friends)
|
|
|
|
@state = state.merge(
|
2017-07-26 01:35:05 -04:00
|
|
|
active_friend_index: friends.empty? ? nil : 0,
|
2017-07-25 22:09:36 -04:00
|
|
|
|
2017-07-25 21:40:19 -04:00
|
|
|
friends: friends.map do |friend|
|
|
|
|
[
|
|
|
|
friend.number,
|
|
|
|
public_key: friend.public_key.to_hex.freeze,
|
|
|
|
name: friend.name.freeze,
|
|
|
|
status: friend.status,
|
|
|
|
status_message: friend.status_message.freeze,
|
2017-07-25 22:09:36 -04:00
|
|
|
history: [].freeze,
|
2017-07-26 02:32:00 -04:00
|
|
|
new_message: {
|
|
|
|
text: '',
|
|
|
|
cursor_pos: 0,
|
|
|
|
}.freeze,
|
2017-07-25 21:40:19 -04:00
|
|
|
]
|
|
|
|
end.to_h.freeze,
|
2017-07-25 19:43:52 -04:00
|
|
|
).freeze
|
|
|
|
end
|
|
|
|
|
2017-07-25 22:30:40 -04:00
|
|
|
def on_friend_request(public_key, _text)
|
|
|
|
friend = @tox_client.friend_add_norequest public_key
|
|
|
|
|
2017-07-25 19:43:52 -04:00
|
|
|
@state = state.merge(
|
2017-07-26 01:35:05 -04:00
|
|
|
active_friend_index: state[:active_friend_index] || state[:friends].count,
|
2017-07-25 22:30:40 -04:00
|
|
|
|
2017-07-25 21:40:19 -04:00
|
|
|
friends: state[:friends].merge(
|
|
|
|
friend.number => {
|
|
|
|
public_key: friend.public_key.to_hex.freeze,
|
|
|
|
name: friend.name.freeze,
|
|
|
|
status: friend.status,
|
|
|
|
status_message: friend.status_message.freeze,
|
2017-07-25 22:09:36 -04:00
|
|
|
history: [].freeze,
|
2017-07-26 02:32:00 -04:00
|
|
|
new_message: {
|
|
|
|
text: '',
|
|
|
|
cursor_pos: 0,
|
|
|
|
}.freeze,
|
2017-07-25 21:40:19 -04:00
|
|
|
}.freeze,
|
2017-07-25 19:26:38 -04:00
|
|
|
).freeze,
|
|
|
|
).freeze
|
|
|
|
end
|
|
|
|
|
2017-07-25 21:17:18 -04:00
|
|
|
def on_friend_message(friend, text)
|
|
|
|
@state = state.merge(
|
2017-07-25 22:09:36 -04:00
|
|
|
friends: state[:friends].merge(
|
|
|
|
friend.number => state[:friends][friend.number].merge(
|
|
|
|
history: (state[:friends][friend.number][:history] + [
|
|
|
|
out: false,
|
|
|
|
time: Time.now.utc.freeze,
|
|
|
|
name: friend.name.freeze,
|
|
|
|
text: text.freeze,
|
2017-07-25 21:17:18 -04:00
|
|
|
]).freeze,
|
|
|
|
).freeze,
|
2017-07-25 23:10:47 -04:00
|
|
|
).freeze,
|
|
|
|
).freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_friend_name_change(friend, name)
|
|
|
|
@state = @state.merge(
|
|
|
|
friends: state[:friends].merge(
|
|
|
|
friend.number => state[:friends][friend.number].merge(
|
|
|
|
name: name.freeze,
|
|
|
|
).freeze,
|
2017-07-25 23:26:50 -04:00
|
|
|
).freeze,
|
|
|
|
).freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_friend_status_message_change(friend, status_message)
|
|
|
|
@state = @state.merge(
|
|
|
|
friends: state[:friends].merge(
|
|
|
|
friend.number => state[:friends][friend.number].merge(
|
|
|
|
status_message: status_message.freeze,
|
|
|
|
).freeze,
|
2017-07-25 23:46:15 -04:00
|
|
|
).freeze,
|
|
|
|
).freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_friend_status_change(friend, status)
|
|
|
|
@state = @state.merge(
|
|
|
|
friends: state[:friends].merge(
|
|
|
|
friend.number => state[:friends][friend.number].merge(
|
|
|
|
status: status,
|
|
|
|
).freeze,
|
2017-07-25 21:17:18 -04:00
|
|
|
).freeze,
|
|
|
|
).freeze
|
|
|
|
end
|
|
|
|
|
2017-07-25 22:35:43 -04:00
|
|
|
####################
|
|
|
|
# Screen callbacks #
|
|
|
|
####################
|
|
|
|
|
2017-07-25 12:03:32 -04:00
|
|
|
def on_window_left
|
|
|
|
@state = state.merge(
|
|
|
|
focus: :sidebar,
|
|
|
|
|
|
|
|
sidebar: state[:sidebar].merge(
|
|
|
|
focused: true,
|
|
|
|
|
|
|
|
logo: state[:sidebar][:logo].merge(focused: state[:sidebar][:focus] == :logo).freeze,
|
|
|
|
menu: state[:sidebar][:menu].merge(focused: state[:sidebar][:focus] == :menu).freeze,
|
|
|
|
).freeze,
|
|
|
|
|
|
|
|
chat: state[:chat].merge(
|
|
|
|
focused: false,
|
|
|
|
|
|
|
|
info: state[:chat][:info].merge(focused: false).freeze,
|
|
|
|
new_message: state[:chat][:new_message].merge(focused: false).freeze,
|
|
|
|
history: state[:chat][:history].merge(focused: false).freeze,
|
|
|
|
).freeze,
|
|
|
|
).freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_window_right
|
|
|
|
@state = state.merge(
|
2017-07-25 12:36:19 -04:00
|
|
|
focus: :chat,
|
2017-07-25 12:03:32 -04:00
|
|
|
|
|
|
|
sidebar: state[:sidebar].merge(
|
|
|
|
focused: true,
|
|
|
|
|
|
|
|
logo: state[:sidebar][:logo].merge(focused: false).freeze,
|
|
|
|
menu: state[:sidebar][:menu].merge(focused: false).freeze,
|
|
|
|
).freeze,
|
|
|
|
|
|
|
|
chat: state[:chat].merge(
|
|
|
|
focused: false,
|
|
|
|
|
|
|
|
info: state[:chat][:info].merge(focused: state[:chat][:focus] == :info).freeze,
|
|
|
|
new_message: state[:chat][:new_message].merge(focused: state[:chat][:focus] == :new_message).freeze,
|
|
|
|
history: state[:chat][:history].merge(focused: state[:chat][:focus] == :history).freeze,
|
|
|
|
).freeze,
|
|
|
|
).freeze
|
|
|
|
end
|
2017-07-25 12:22:38 -04:00
|
|
|
|
|
|
|
def on_menu_up
|
2017-07-26 01:35:05 -04:00
|
|
|
return if state[:active_friend_index].nil?
|
|
|
|
|
|
|
|
active_friend_index = state[:active_friend_index] + 1
|
|
|
|
top = state[:sidebar][:menu][:top]
|
|
|
|
|
|
|
|
if active_friend_index.negative?
|
|
|
|
active_friend_index = state[:friends].count - 1
|
|
|
|
elsif active_friend_index >= state[:friends].count
|
|
|
|
active_friend_index = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
if active_friend_index < top
|
|
|
|
top = active_friend_index
|
|
|
|
elsif active_friend_index >= top + state[:height]
|
|
|
|
top = active_friend_index - state[:height] + 1
|
|
|
|
end
|
|
|
|
|
2017-07-25 12:22:38 -04:00
|
|
|
@state = state.merge(
|
2017-07-26 01:35:05 -04:00
|
|
|
active_friend_index: active_friend_index,
|
|
|
|
|
2017-07-25 12:22:38 -04:00
|
|
|
sidebar: state[:sidebar].merge(
|
2017-07-26 01:35:05 -04:00
|
|
|
menu: state[:sidebar][:menu].merge(
|
|
|
|
top: top,
|
|
|
|
).freeze,
|
2017-07-25 12:22:38 -04:00
|
|
|
).freeze,
|
2017-07-26 01:35:05 -04:00
|
|
|
).freeze
|
2017-07-25 12:22:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def on_menu_down
|
2017-07-26 01:35:05 -04:00
|
|
|
return if state[:active_friend_index].nil?
|
|
|
|
|
|
|
|
active_friend_index = state[:active_friend_index] + 1
|
|
|
|
top = state[:sidebar][:menu][:top]
|
|
|
|
|
|
|
|
if active_friend_index.negative?
|
|
|
|
active_friend_index = state[:friends].count - 1
|
|
|
|
elsif active_friend_index >= state[:friends].count
|
|
|
|
active_friend_index = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
if active_friend_index < top
|
|
|
|
top = active_friend_index
|
|
|
|
elsif active_friend_index >= top + state[:height]
|
|
|
|
top = active_friend_index - state[:height] + 1
|
|
|
|
end
|
|
|
|
|
2017-07-25 12:22:38 -04:00
|
|
|
@state = state.merge(
|
2017-07-26 01:35:05 -04:00
|
|
|
active_friend_index: active_friend_index,
|
|
|
|
|
2017-07-25 12:22:38 -04:00
|
|
|
sidebar: state[:sidebar].merge(
|
2017-07-26 01:35:05 -04:00
|
|
|
menu: state[:sidebar][:menu].merge(
|
|
|
|
top: top,
|
|
|
|
).freeze,
|
2017-07-25 12:22:38 -04:00
|
|
|
).freeze,
|
2017-07-26 01:35:05 -04:00
|
|
|
).freeze
|
2017-07-25 12:22:38 -04:00
|
|
|
end
|
2017-07-25 12:36:19 -04:00
|
|
|
|
2017-07-26 04:07:36 -04:00
|
|
|
def on_new_message_enter
|
|
|
|
return if state[:active_friend_index].nil?
|
|
|
|
|
|
|
|
friend_number = state[:friends].keys[state[:active_friend_index]]
|
|
|
|
|
|
|
|
return if friend_number.nil?
|
|
|
|
|
|
|
|
text = state[:friends][friend_number][:new_message][:text].strip.freeze
|
|
|
|
|
|
|
|
return if text.empty?
|
|
|
|
|
2017-07-27 17:40:59 -04:00
|
|
|
error = false
|
|
|
|
|
|
|
|
begin
|
|
|
|
@tox_client.friend(friend_number).send_message text
|
|
|
|
rescue
|
|
|
|
error = true
|
|
|
|
end
|
2017-07-26 04:07:36 -04:00
|
|
|
|
|
|
|
@state = state.merge(
|
|
|
|
friends: state[:friends].merge(
|
|
|
|
friend_number => state[:friends][friend_number].merge(
|
|
|
|
new_message: state[:friends][friend_number][:new_message].merge(
|
|
|
|
text: '',
|
|
|
|
cursor_pos: 0,
|
|
|
|
),
|
|
|
|
|
|
|
|
history: (state[:friends][friend_number][:history] + [
|
2017-07-27 18:01:17 -04:00
|
|
|
error: error,
|
|
|
|
out: true,
|
|
|
|
received: false,
|
|
|
|
time: Time.now.utc.freeze,
|
|
|
|
name: @tox_client.name.freeze,
|
|
|
|
text: text,
|
2017-07-26 04:07:36 -04:00
|
|
|
]).freeze,
|
|
|
|
).freeze,
|
|
|
|
).freeze,
|
|
|
|
).freeze
|
|
|
|
end
|
|
|
|
|
2017-07-25 12:36:19 -04:00
|
|
|
def on_new_message_putc(char)
|
2017-07-26 02:32:00 -04:00
|
|
|
return if state[:active_friend_index].nil?
|
|
|
|
|
|
|
|
friend_number = state[:friends].keys[state[:active_friend_index]]
|
|
|
|
|
|
|
|
return if friend_number.nil?
|
|
|
|
|
|
|
|
friend = state[:friends][friend_number]
|
|
|
|
new_message = friend[:new_message]
|
|
|
|
|
|
|
|
text = new_message[:text]
|
|
|
|
cursor_pos = new_message[:cursor_pos]
|
|
|
|
|
|
|
|
text = "#{text[0...cursor_pos]}#{char}#{text[cursor_pos..-1]}"
|
|
|
|
cursor_pos += 1
|
2017-07-25 12:36:19 -04:00
|
|
|
|
|
|
|
@state = state.merge(
|
2017-07-26 02:32:00 -04:00
|
|
|
friends: state[:friends].merge(
|
|
|
|
friend_number => friend.merge(
|
|
|
|
new_message: new_message.merge(
|
|
|
|
text: text,
|
|
|
|
cursor_pos: cursor_pos,
|
|
|
|
).freeze,
|
|
|
|
).freeze,
|
2017-07-25 12:36:19 -04:00
|
|
|
).freeze,
|
|
|
|
).freeze
|
|
|
|
end
|
2017-07-25 13:21:15 -04:00
|
|
|
|
2017-07-25 13:36:05 -04:00
|
|
|
def on_new_message_left
|
2017-07-26 02:32:00 -04:00
|
|
|
return if state[:active_friend_index].nil?
|
|
|
|
|
|
|
|
friend_number = state[:friends].keys[state[:active_friend_index]]
|
|
|
|
|
|
|
|
return if friend_number.nil?
|
|
|
|
|
|
|
|
friend = state[:friends][friend_number]
|
|
|
|
new_message = friend[:new_message]
|
|
|
|
|
|
|
|
cursor_pos = new_message[:cursor_pos]
|
|
|
|
|
|
|
|
cursor_pos -= 1
|
|
|
|
|
|
|
|
cursor_pos = 0 if cursor_pos.negative?
|
|
|
|
|
2017-07-25 13:36:05 -04:00
|
|
|
@state = state.merge(
|
2017-07-26 02:32:00 -04:00
|
|
|
friends: state[:friends].merge(
|
|
|
|
friend_number => friend.merge(
|
|
|
|
new_message: new_message.merge(
|
|
|
|
cursor_pos: cursor_pos,
|
|
|
|
).freeze,
|
|
|
|
).freeze,
|
2017-07-25 13:36:05 -04:00
|
|
|
).freeze,
|
|
|
|
).freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_new_message_right
|
2017-07-26 02:32:00 -04:00
|
|
|
return if state[:active_friend_index].nil?
|
|
|
|
|
|
|
|
friend_number = state[:friends].keys[state[:active_friend_index]]
|
|
|
|
|
|
|
|
return if friend_number.nil?
|
|
|
|
|
|
|
|
friend = state[:friends][friend_number]
|
|
|
|
new_message = friend[:new_message]
|
|
|
|
|
|
|
|
text = new_message[:text]
|
|
|
|
cursor_pos = new_message[:cursor_pos]
|
|
|
|
|
|
|
|
cursor_pos += 1
|
|
|
|
|
|
|
|
cursor_pos = text.length if cursor_pos > text.length
|
|
|
|
|
2017-07-25 13:36:05 -04:00
|
|
|
@state = state.merge(
|
2017-07-26 02:32:00 -04:00
|
|
|
friends: state[:friends].merge(
|
|
|
|
friend_number => friend.merge(
|
|
|
|
new_message: new_message.merge(
|
|
|
|
cursor_pos: cursor_pos,
|
|
|
|
).freeze,
|
|
|
|
).freeze,
|
2017-07-25 13:36:05 -04:00
|
|
|
).freeze,
|
|
|
|
).freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_new_message_home
|
2017-07-26 02:32:00 -04:00
|
|
|
return if state[:active_friend_index].nil?
|
|
|
|
|
|
|
|
friend_number = state[:friends].keys[state[:active_friend_index]]
|
|
|
|
|
|
|
|
return if friend_number.nil?
|
|
|
|
|
|
|
|
friend = state[:friends][friend_number]
|
|
|
|
new_message = friend[:new_message]
|
|
|
|
|
2017-07-25 13:36:05 -04:00
|
|
|
@state = state.merge(
|
2017-07-26 02:32:00 -04:00
|
|
|
friends: state[:friends].merge(
|
|
|
|
friend_number => friend.merge(
|
|
|
|
new_message: new_message.merge(
|
|
|
|
cursor_pos: 0,
|
|
|
|
).freeze,
|
|
|
|
).freeze,
|
2017-07-25 13:36:05 -04:00
|
|
|
).freeze,
|
|
|
|
).freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_new_message_end
|
2017-07-26 02:32:00 -04:00
|
|
|
return if state[:active_friend_index].nil?
|
|
|
|
|
|
|
|
friend_number = state[:friends].keys[state[:active_friend_index]]
|
|
|
|
|
|
|
|
return if friend_number.nil?
|
|
|
|
|
|
|
|
friend = state[:friends][friend_number]
|
|
|
|
new_message = friend[:new_message]
|
|
|
|
|
2017-07-25 13:36:05 -04:00
|
|
|
@state = state.merge(
|
2017-07-26 02:32:00 -04:00
|
|
|
friends: state[:friends].merge(
|
|
|
|
friend_number => friend.merge(
|
|
|
|
new_message: new_message.merge(
|
|
|
|
cursor_pos: new_message[:text].length,
|
|
|
|
).freeze,
|
|
|
|
).freeze,
|
2017-07-25 13:36:05 -04:00
|
|
|
).freeze,
|
|
|
|
).freeze
|
|
|
|
end
|
|
|
|
|
2017-07-25 13:41:55 -04:00
|
|
|
def on_new_message_backspace
|
2017-07-26 02:32:00 -04:00
|
|
|
return if state[:active_friend_index].nil?
|
|
|
|
|
|
|
|
friend_number = state[:friends].keys[state[:active_friend_index]]
|
|
|
|
|
|
|
|
return if friend_number.nil?
|
|
|
|
|
|
|
|
friend = state[:friends][friend_number]
|
|
|
|
new_message = friend[:new_message]
|
|
|
|
|
|
|
|
text = new_message[:text]
|
|
|
|
cursor_pos = new_message[:cursor_pos]
|
2017-07-25 13:41:55 -04:00
|
|
|
|
|
|
|
return unless cursor_pos.positive?
|
|
|
|
|
2017-07-26 02:32:00 -04:00
|
|
|
text = "#{text[0...(cursor_pos - 1)]}#{text[cursor_pos..-1]}"
|
|
|
|
cursor_pos -= 1
|
|
|
|
|
2017-07-25 13:41:55 -04:00
|
|
|
@state = state.merge(
|
2017-07-26 02:32:00 -04:00
|
|
|
friends: state[:friends].merge(
|
|
|
|
friend_number => friend.merge(
|
|
|
|
new_message: new_message.merge(
|
|
|
|
text: text,
|
|
|
|
cursor_pos: cursor_pos,
|
|
|
|
).freeze,
|
|
|
|
).freeze,
|
2017-07-25 13:41:55 -04:00
|
|
|
).freeze,
|
|
|
|
).freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_new_message_delete
|
2017-07-26 02:32:00 -04:00
|
|
|
return if state[:active_friend_index].nil?
|
|
|
|
|
|
|
|
friend_number = state[:friends].keys[state[:active_friend_index]]
|
|
|
|
|
|
|
|
return if friend_number.nil?
|
|
|
|
|
|
|
|
friend = state[:friends][friend_number]
|
|
|
|
new_message = friend[:new_message]
|
|
|
|
|
|
|
|
text = new_message[:text]
|
|
|
|
cursor_pos = new_message[:cursor_pos]
|
2017-07-25 13:41:55 -04:00
|
|
|
|
|
|
|
return if cursor_pos > text.length
|
|
|
|
|
2017-07-26 02:32:00 -04:00
|
|
|
text = "#{text[0...cursor_pos]}#{text[(cursor_pos + 1)..-1]}"
|
|
|
|
|
2017-07-25 13:41:55 -04:00
|
|
|
@state = state.merge(
|
2017-07-26 02:32:00 -04:00
|
|
|
friends: state[:friends].merge(
|
|
|
|
friend_number => friend.merge(
|
|
|
|
new_message: new_message.merge(
|
|
|
|
text: text,
|
|
|
|
cursor_pos: cursor_pos,
|
|
|
|
).freeze,
|
|
|
|
).freeze,
|
2017-07-25 13:41:55 -04:00
|
|
|
).freeze,
|
|
|
|
).freeze
|
|
|
|
end
|
|
|
|
|
2017-07-25 22:35:43 -04:00
|
|
|
#########
|
|
|
|
# State #
|
|
|
|
#########
|
|
|
|
|
2017-07-25 22:33:15 -04:00
|
|
|
def state
|
|
|
|
@state ||= {
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
width: Curses.stdscr.maxx,
|
|
|
|
height: Curses.stdscr.maxy,
|
|
|
|
focus: :sidebar,
|
|
|
|
focused: true,
|
|
|
|
|
|
|
|
on_window_left: method(:on_window_left),
|
|
|
|
on_window_right: method(:on_window_right),
|
|
|
|
|
|
|
|
on_menu_up: method(:on_menu_up),
|
|
|
|
on_menu_down: method(:on_menu_down),
|
|
|
|
|
2017-07-26 04:07:36 -04:00
|
|
|
on_new_message_enter: method(:on_new_message_enter),
|
|
|
|
|
2017-07-25 22:33:15 -04:00
|
|
|
on_new_message_putc: method(:on_new_message_putc),
|
|
|
|
|
|
|
|
on_new_message_left: method(:on_new_message_left),
|
|
|
|
on_new_message_right: method(:on_new_message_right),
|
|
|
|
on_new_message_home: method(:on_new_message_home),
|
|
|
|
on_new_message_end: method(:on_new_message_end),
|
|
|
|
|
|
|
|
on_new_message_backspace: method(:on_new_message_backspace),
|
|
|
|
on_new_message_delete: method(:on_new_message_delete),
|
|
|
|
|
2017-07-26 10:31:17 -04:00
|
|
|
me: {
|
|
|
|
public_key: @tox_client.public_key,
|
|
|
|
name: @tox_client.name,
|
|
|
|
status: @tox_client.status,
|
|
|
|
status_message: @tox_client.status_message,
|
|
|
|
},
|
|
|
|
|
2017-07-26 01:35:05 -04:00
|
|
|
active_friend_index: nil,
|
2017-07-25 22:33:15 -04:00
|
|
|
|
|
|
|
friends: {}.freeze,
|
|
|
|
|
|
|
|
sidebar: {
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
width: Widgets::Logo::WIDTH,
|
|
|
|
height: Curses.stdscr.maxy,
|
|
|
|
focus: :menu,
|
|
|
|
focused: true,
|
|
|
|
|
|
|
|
logo: {
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
width: Widgets::Logo::WIDTH,
|
|
|
|
height: Widgets::Logo::HEIGHT,
|
|
|
|
}.freeze,
|
|
|
|
|
|
|
|
menu: {
|
|
|
|
x: 0,
|
|
|
|
y: Widgets::Logo::HEIGHT,
|
|
|
|
width: Widgets::Logo::WIDTH,
|
|
|
|
height: Curses.stdscr.maxy - Widgets::Logo::HEIGHT,
|
|
|
|
focused: true,
|
|
|
|
|
|
|
|
active: 0,
|
|
|
|
top: 0,
|
|
|
|
}.freeze,
|
|
|
|
}.freeze,
|
|
|
|
|
|
|
|
chat: {
|
2017-07-26 11:04:03 -04:00
|
|
|
x: Widgets::Logo::WIDTH + 1,
|
2017-07-25 22:33:15 -04:00
|
|
|
y: 0,
|
2017-07-26 11:04:03 -04:00
|
|
|
width: Curses.stdscr.maxx - Widgets::Logo::WIDTH - 1,
|
2017-07-25 22:33:15 -04:00
|
|
|
height: Curses.stdscr.maxy,
|
|
|
|
focus: :new_message,
|
|
|
|
focused: false,
|
|
|
|
|
|
|
|
info: {
|
2017-07-26 11:04:03 -04:00
|
|
|
x: Widgets::Logo::WIDTH + 1,
|
2017-07-25 22:33:15 -04:00
|
|
|
y: 0,
|
2017-07-26 11:04:03 -04:00
|
|
|
width: Curses.stdscr.maxx - Widgets::Logo::WIDTH - 1,
|
2017-07-25 22:33:15 -04:00
|
|
|
height: 2,
|
|
|
|
focused: false,
|
|
|
|
}.freeze,
|
|
|
|
|
|
|
|
new_message: {
|
2017-07-26 11:04:03 -04:00
|
|
|
x: Widgets::Logo::WIDTH + 1,
|
2017-07-25 22:33:15 -04:00
|
|
|
y: Curses.stdscr.maxy - 1,
|
2017-07-26 11:04:03 -04:00
|
|
|
width: Curses.stdscr.maxx - Widgets::Logo::WIDTH - 1,
|
2017-07-25 22:33:15 -04:00
|
|
|
height: 1,
|
|
|
|
focused: false,
|
|
|
|
}.freeze,
|
|
|
|
|
|
|
|
history: {
|
2017-07-26 11:04:03 -04:00
|
|
|
x: Widgets::Logo::WIDTH + 1,
|
|
|
|
y: 3,
|
|
|
|
width: Curses.stdscr.maxx - Widgets::Logo::WIDTH - 1,
|
|
|
|
height: Curses.stdscr.maxy - 5,
|
2017-07-25 22:33:15 -04:00
|
|
|
focused: true,
|
|
|
|
}.freeze,
|
|
|
|
}.freeze,
|
|
|
|
}.freeze
|
|
|
|
end
|
2017-07-21 08:38:11 -04:00
|
|
|
end
|