Class: Mxup::StatusView

Inherits:
Object
  • Object
show all
Defined in:
lib/mxup/status_view.rb

Overview

Renders mxup status output.

Constant Summary collapse

INDENT =
'    '
STATUS_COMMAND_MAX =

Max length for the command: line in mxup status (long JVM -cp, etc.).

256

Instance Method Summary collapse

Constructor Details

#initialize(config, resolver:, out: nil) ⇒ StatusView

Returns a new instance of StatusView.



13
14
15
16
17
18
# File 'lib/mxup/status_view.rb', line 13

def initialize(config, resolver:, out: nil)
  @config       = config
  @session      = config.session
  @resolver     = resolver
  @out_override = out
end

Instance Method Details

#outObject



20
21
22
# File 'lib/mxup/status_view.rb', line 20

def out
  @out_override || $stdout
end

#render(lines:) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/mxup/status_view.rb', line 24

def render(lines:)
  unless Tmux.has_session?(@session)
    out.puts "SESSION: #{@session} — NOT RUNNING"
    out.puts "Start with: mxup up #{@session}"
    return
  end

  active       = @resolver.active_layout
  created      = Tmux.session_created(@session)
  created_at   = Time.at(created.to_i).strftime('%Y-%m-%d %H:%M:%S')
  stored_prof  = Tmux.show_environment(@session, 'MXUP_PROFILE')
  bits         = []
  bits << "profile: #{stored_prof}"       if stored_prof
  bits << "layout: #{active}"             if active
  suffix       = bits.empty? ? '' : " (#{bits.join(', ')})"
  out.puts "SESSION: #{@session} — up since #{created_at}#{suffix}"
  render_watcher_line
  out.puts

  panes           = Tmux.list_panes(@session)
  declared_names  = @config.windows.map(&:name)
  printed         = Set.new
  order           = @config.effective_window_order(active)

  order.each do |entry|
    if entry[:type] == :group
      render_group(entry[:group], panes, lines, printed)
    else
      render_standalone(entry[:name], panes, lines, declared_names, printed)
    end
  end

  render_extras(panes, lines, printed)
end