Module: Pbx::Views::ExtensionTable
- Defined in:
- lib/pbx/views/extension_table.rb
Constant Summary collapse
- COLUMNS =
[ {title: "Peer", width: 16}, {title: "Status", width: 14}, {title: "IP Address", width: 17}, {title: "Port", width: 6}, {title: "Type", width: 8}, {title: "RTT (ms)", width: 9}, {title: "Changed", width: 12} ].freeze
- HEADER_STYLE =
Lipgloss::Style.new.bold(true).foreground("#a78bfa")
- SELECTED_STYLE =
Lipgloss::Style.new.bold(true).foreground("#ffffff").background("#7c3aed")
- EMPTY_STYLE =
Lipgloss::Style.new.foreground("#6b7280").italic(true).padding(2, 4)
- STATUS_DOTS =
{ "registered" => "●", "reachable" => "●", "lagged" => "◑", "unreachable" => "○", "unregistered" => "·", "unmonitored" => "·", "unknown" => "·" }.freeze
Class Method Summary collapse
- .build(peers, table_height) ⇒ Object
-
.colorized_status(status) ⇒ Object
ANSI-colored status for use outside the table (info panels, etc.).
- .render_empty ⇒ Object
- .since(time) ⇒ Object
-
.status_text(status) ⇒ Object
Plain-text status for table cells — ANSI codes break Bubbles::Table width math.
Class Method Details
.build(peers, table_height) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/pbx/views/extension_table.rb', line 35 def self.build(peers, table_height) rows = peers.values.sort_by(&:name).map { |peer| [ peer.name, status_text(peer.status), peer.ip_address || "—", peer.ip_port&.to_s || "—", peer.type || "—", peer.rtt_ms&.to_s || "—", since(peer.last_change_at) ] } Bubbles::Table.new(columns: COLUMNS, rows: rows, height: table_height).tap do |t| t.header_style = HEADER_STYLE t.selected_style = SELECTED_STYLE end end |
.colorized_status(status) ⇒ Object
ANSI-colored status for use outside the table (info panels, etc.).
66 67 68 69 70 |
# File 'lib/pbx/views/extension_table.rb', line 66 def self.colorized_status(status) color = Status.color(status) label = Status.describe(status) Lipgloss::Style.new.foreground(color).bold(true).render(label) end |
.render_empty ⇒ Object
54 55 56 |
# File 'lib/pbx/views/extension_table.rb', line 54 def self.render_empty EMPTY_STYLE.render("No SIP peers discovered yet…") end |
.since(time) ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/pbx/views/extension_table.rb', line 72 def self.since(time) return "—" unless time secs = (Time.now - time).to_i return "Just now" if secs < 5 return "#{secs}s ago" if secs < 60 return "#{secs / 60}m ago" if secs < 3600 "#{secs / 3600}h ago" end |
.status_text(status) ⇒ Object
Plain-text status for table cells — ANSI codes break Bubbles::Table width math.
59 60 61 62 63 |
# File 'lib/pbx/views/extension_table.rb', line 59 def self.status_text(status) dot = STATUS_DOTS.fetch(status.to_s, "·") label = Status.describe(status) "#{dot} #{label}" end |