Class: Muxr::CommandDispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/muxr/command_dispatcher.rb

Overview

Parses “:”-prefixed commands typed at the command prompt and routes them to the Application. Unknown commands result in a flashed status message rather than a hard error so the user never gets dropped out of the multiplexer for a typo.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ CommandDispatcher

Returns a new instance of CommandDispatcher.



7
8
9
# File 'lib/muxr/command_dispatcher.rb', line 7

def initialize(app)
  @app = app
end

Instance Method Details

#dispatch(line) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/muxr/command_dispatcher.rb', line 11

def dispatch(line)
  parts = line.to_s.strip.split(/\s+/)
  return if parts.empty?

  cmd, *args = parts
  case cmd
  when "layout"  then handle_layout(args)
  when "drawer"  then handle_drawer(args)
  when "save"    then @app.save_session
  when "restore" then @app.restore_session
  when "sessions", "ls" then @app.list_sessions
  when "quit", "q", "exit"
    @app.quit
  when "new", "c"
    @app.new_pane
  when "close", "kill", "k"
    @app.close_focused
  when "next"    then @app.focus_next
  when "prev"    then @app.focus_prev
  when "master"  then @app.promote_master
  when "help"    then @app.show_help
  when "detach"  then @app.detach
  else
    @app.flash("unknown command: #{cmd}")
  end
end