Class: Mxup::Runner
- Inherits:
-
Object
- Object
- Mxup::Runner
- Defined in:
- lib/mxup/runner.rb
Overview
Public programmatic API. Composes the focused helpers — nothing here should contain real business logic, only wiring and delegation.
Constant Summary collapse
- DEFAULT_INTERRUPT_DELAY =
Delay (seconds) between the two Ctrl-C presses during a restart, and between Ctrl-C and sending the new command. In production 1s is enough to let the pane’s shell redraw its prompt; tests shorten this to avoid paying multi-second waits for a purely cosmetic settle.
1.0
Class Attribute Summary collapse
Instance Method Summary collapse
- #down ⇒ Object
- #exec(target_spec, command, lines: 50, timeout: nil, force: false, quiet: false) ⇒ Object
-
#initialize(config, dry_run: false, layout: nil) ⇒ Runner
constructor
A new instance of Runner.
- #restart(window_names) ⇒ Object
- #show_layouts ⇒ Object
- #status(lines:) ⇒ Object
- #switch_layout(target_layout) ⇒ Object
- #target(window_names) ⇒ Object
-
#up ⇒ Object
— primary commands ————————————————–.
Constructor Details
#initialize(config, dry_run: false, layout: nil) ⇒ Runner
Returns a new instance of Runner.
21 22 23 24 25 26 |
# File 'lib/mxup/runner.rb', line 21 def initialize(config, dry_run: false, layout: nil) @config = config @session = config.session @dry_run = dry_run @layout = layout end |
Class Attribute Details
.interrupt_delay ⇒ Object
16 17 18 |
# File 'lib/mxup/runner.rb', line 16 def interrupt_delay @interrupt_delay || DEFAULT_INTERRUPT_DELAY end |
Instance Method Details
#down ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mxup/runner.rb', line 39 def down unless Tmux.has_session?(@session) $stdout.puts "Session #{@session} is not running." return end if @dry_run $stdout.puts "[dry-run] Would gracefully stop session #{@session}" return end graceful_stop.call Tmux.kill_session(@session) launcher.cleanup $stdout.puts "Session #{@session} killed." end |
#exec(target_spec, command, lines: 50, timeout: nil, force: false, quiet: false) ⇒ Object
94 95 96 97 98 |
# File 'lib/mxup/runner.rb', line 94 def exec(target_spec, command, lines: 50, timeout: nil, force: false, quiet: false) exec_runner.run(target_spec, command, lines: lines, timeout: timeout, force: force, quiet: quiet) end |
#restart(window_names) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/mxup/runner.rb', line 56 def restart(window_names) abort "Session #{@session} is not running." unless Tmux.has_session?(@session) launcher.write_all unless @dry_run targets = resolve_restart_targets(window_names) targets.each do |win| target_ref = resolver.pane_target(win.name) if target_ref restart_existing(win, target_ref) else create_missing(win) end end end |
#show_layouts ⇒ Object
76 77 78 79 80 |
# File 'lib/mxup/runner.rb', line 76 def show_layouts layout_manager.show( active: Tmux.has_session?(@session) ? resolver.stored_layout : nil ) end |
#status(lines:) ⇒ Object
35 36 37 |
# File 'lib/mxup/runner.rb', line 35 def status(lines:) status_view.render(lines: lines) end |
#switch_layout(target_layout) ⇒ Object
72 73 74 |
# File 'lib/mxup/runner.rb', line 72 def switch_layout(target_layout) layout_manager.switch(target_layout) end |
#target(window_names) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/mxup/runner.rb', line 82 def target(window_names) abort "Session #{@session} is not running." unless Tmux.has_session?(@session) requested = Array(window_names).flat_map { |n| n.split(',') }.reject(&:empty?) if requested.empty? print_all_targets else print_requested_targets(requested) end end |
#up ⇒ Object
— primary commands ————————————————–
30 31 32 33 |
# File 'lib/mxup/runner.rb', line 30 def up handle_profile_switch reconciler.up end |