Module: Pbx::Views::Header
- Defined in:
- lib/pbx/views/header.rb
Constant Summary collapse
- TITLE_STYLE =
Lipgloss::Style.new .bold(true) .foreground("#7c3aed") .padding(0, 1)
- STATUS_DISCONNECTED_STYLE =
Lipgloss::Style.new.foreground("#6b7280").italic(true)
- STATUS_CONNECTING_STYLE =
Lipgloss::Style.new.foreground("#f59e0b").italic(true)
- STATUS_CONNECTED_STYLE =
Lipgloss::Style.new.foreground("#22c55e").bold(true)
- STATUS_LOST_STYLE =
Lipgloss::Style.new.foreground("#ef4444").bold(true)
- SEPARATOR_STYLE =
Lipgloss::Style.new.foreground("#4b5563")
- SYSINFO_STYLE =
Lipgloss::Style.new.foreground("#6b7280")
Class Method Summary collapse
Class Method Details
.build_sysinfo(state) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/pbx/views/header.rb', line 41 def self.build_sysinfo(state) return nil unless state.system_boot_at || state.last_reload_at parts = [] parts << "Up #{format_duration((Time.now - state.system_boot_at).to_i)}" if state.system_boot_at parts << "Reload #{format_duration((Time.now - state.last_reload_at).to_i)}" if state.last_reload_at SYSINFO_STYLE.render(parts.join(" · ")) end |
.call(state) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pbx/views/header.rb', line 21 def self.call(state) title = TITLE_STYLE.render("PBX Monitor") remote = "#{state.config.host}:#{state.config.port}" status = case state.status when :disconnected then STATUS_DISCONNECTED_STYLE.render("◌ Disconnected") when :connecting then STATUS_CONNECTING_STYLE.render("#{state.spinner_view} Connecting to #{remote}…") when :connected then STATUS_CONNECTED_STYLE.render("● #{remote}") when :lost then STATUS_LOST_STYLE.render("✗ #{remote} #{state.error}") end sysinfo = build_sysinfo(state) line = if sysinfo Lipgloss.join_horizontal(:center, title, " ", status, " ", sysinfo) else Lipgloss.join_horizontal(:center, title, " ", status) end sep = SEPARATOR_STYLE.render("─" * ((state.width > 0) ? state.width : 80)) Lipgloss.join_vertical(:left, line, sep) end |
.format_duration(secs) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/pbx/views/header.rb', line 50 def self.format_duration(secs) d = secs / 86_400 h = (secs % 86_400) / 3_600 m = (secs % 3_600) / 60 parts = [] parts << "#{d}d" if d > 0 parts << "#{h}h" if h > 0 || d > 0 parts << "#{m}m" parts.join(" ") end |