Class: Harnex::Pane

Inherits:
Object
  • Object
show all
Defined in:
lib/harnex/commands/pane.rb

Constant Summary collapse

FOLLOW_INTERVAL =
1.0

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Pane

Returns a new instance of Pane.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/harnex/commands/pane.rb', line 26

def initialize(argv)
  @argv = argv.dup
  @options = {
    id: nil,
    repo_path: Dir.pwd,
    repo_explicit: false,
    cli: nil,
    lines: nil,
    follow: false,
    interval: FOLLOW_INTERVAL,
    json: false,
    help: false
  }
end

Class Method Details

.usage(program_name = "harnex pane") ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/harnex/commands/pane.rb', line 10

def self.usage(program_name = "harnex pane")
  <<~TEXT
    Usage: #{program_name} [options]

    Options:
      --id ID       Session ID to inspect (required)
      --repo PATH   Resolve using PATH's repo root (default: current repo)
      --cli CLI     Filter the active session by CLI
      --lines N     Capture the last N lines instead of the full pane
      --follow      Refresh the pane snapshot every second until the session exits
      --interval N  Refresh interval in seconds for --follow (default: #{FOLLOW_INTERVAL.to_i})
      --json        Output JSON with capture metadata
      -h, --help    Show this help
  TEXT
end

Instance Method Details

#runObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/harnex/commands/pane.rb', line 41

def run
  parser.parse!(@argv)
  if @options[:help]
    puts self.class.usage
    return 0
  end

  raise "--id is required for harnex pane" unless @options[:id]
  if @options[:lines] && @options[:lines] < 1
    raise OptionParser::InvalidArgument, "--lines must be >= 1"
  end

  session = resolve_session
  return 1 unless session

  return 1 unless tmux_available?

  target = resolve_tmux_target(session)
  return 1 unless target
  return 1 unless tmux_target_exists?(session, target)

  if @options[:follow]
    follow(session, target)
  else
    text = capture(target)
    return 1 unless text

    emit_output(session.fetch("id"), text)
  end
  0
end