Class: Meshchat::Ui::CLI
- Inherits:
-
Object
- Object
- Meshchat::Ui::CLI
- Extended by:
- ActiveSupport::Autoload
- Defined in:
- lib/meshchat/ui/cli.rb,
lib/meshchat/ui/cli/base.rb,
lib/meshchat/ui/cli/input_factory.rb,
lib/meshchat/ui/cli/readline_input.rb,
lib/meshchat/ui/cli/keyboard_line_input.rb
Overview
A user interface is responsible for for creating a client and sending messages to that client
Defined Under Namespace
Classes: Base, InputFactory, KeyboardLineInput, ReadlineInput
Constant Summary collapse
- AWAY_TIMEOUT =
60 seconds times 5 minutes
60 * 5
Instance Attribute Summary collapse
-
#_command_factory ⇒ Object
readonly
Returns the value of attribute _command_factory.
-
#_last_input_received_at ⇒ Object
Returns the value of attribute _last_input_received_at.
-
#_message_dispatcher ⇒ Object
readonly
Returns the value of attribute _message_dispatcher.
-
#_message_factory ⇒ Object
readonly
Returns the value of attribute _message_factory.
-
#_sent_idle_message ⇒ Object
Returns the value of attribute _sent_idle_message.
Instance Method Summary collapse
- #activity_timeout_triggred? ⇒ Boolean
- #away_timeout ⇒ Object
- #create_input(msg) ⇒ Object
-
#initialize(dispatcher, message_factory, _display) ⇒ CLI
constructor
A new instance of CLI.
- #reset_timeout_timer ⇒ Object
- #send_disconnect ⇒ Object
-
#shutdown ⇒ Object
save config and exit.
Constructor Details
#initialize(dispatcher, message_factory, _display) ⇒ CLI
Returns a new instance of CLI.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/meshchat/ui/cli.rb', line 23 def initialize(dispatcher, , _display) @_message_dispatcher = dispatcher @_message_factory = @_command_factory = InputFactory.new(dispatcher, , self) self. = false self._last_input_received_at = Time.now # only check for timeout once a minute EM.add_periodic_timer(60) { away_timeout } end |
Instance Attribute Details
#_command_factory ⇒ Object (readonly)
Returns the value of attribute _command_factory.
19 20 21 |
# File 'lib/meshchat/ui/cli.rb', line 19 def _command_factory @_command_factory end |
#_last_input_received_at ⇒ Object
Returns the value of attribute _last_input_received_at.
20 21 22 |
# File 'lib/meshchat/ui/cli.rb', line 20 def _last_input_received_at @_last_input_received_at end |
#_message_dispatcher ⇒ Object (readonly)
Returns the value of attribute _message_dispatcher.
19 20 21 |
# File 'lib/meshchat/ui/cli.rb', line 19 def @_message_dispatcher end |
#_message_factory ⇒ Object (readonly)
Returns the value of attribute _message_factory.
19 20 21 |
# File 'lib/meshchat/ui/cli.rb', line 19 def @_message_factory end |
#_sent_idle_message ⇒ Object
Returns the value of attribute _sent_idle_message.
21 22 23 |
# File 'lib/meshchat/ui/cli.rb', line 21 def @_sent_idle_message end |
Instance Method Details
#activity_timeout_triggred? ⇒ Boolean
45 46 47 48 49 |
# File 'lib/meshchat/ui/cli.rb', line 45 def activity_timeout_triggred? return false if seconds_passed = Time.now - _last_input_received_at seconds_passed > AWAY_TIMEOUT end |
#away_timeout ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/meshchat/ui/cli.rb', line 34 def away_timeout return unless activity_timeout_triggred? = .create(Network::Message::EMOTE, data: { message: 'has become idle' }) .send_to_all() self. = true end |
#create_input(msg) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/meshchat/ui/cli.rb', line 56 def create_input(msg) reset_timeout_timer handler = _command_factory.create(for_input: msg) handler.handle rescue => e Debug.creating_input_failed(e) end |
#reset_timeout_timer ⇒ Object
51 52 53 54 |
# File 'lib/meshchat/ui/cli.rb', line 51 def reset_timeout_timer self._last_input_received_at = Time.now self. = false end |
#send_disconnect ⇒ Object
75 76 77 78 79 |
# File 'lib/meshchat/ui/cli.rb', line 75 def send_disconnect klass = Command::SendDisconnect command = _command_factory.create(with_class: klass) command.handle end |
#shutdown ⇒ Object
save config and exit
65 66 67 68 69 70 71 72 73 |
# File 'lib/meshchat/ui/cli.rb', line 65 def shutdown # close_server Display.info 'saving config...' APP_CONFIG.user.save Display.info 'notifying of disconnection...' send_disconnect Display.alert "\n\nGoodbye. \n\nThank you for using #{Meshchat.name}" exit end |