Module: Portless::Banner

Defined in:
lib/portless/banner.rb

Overview

The "where is my app" banner printed to stderr when a dev server starts through rb-portless — so you see the named URL, not just 127.0.0.1:port. Vite-ish layout; colours are stripped when stderr isn't a TTY. Mirrors the spirit of portless's run output.

Class Method Summary collapse

Class Method Details

.app(rows:, backend_port:, proxy_version: nil) ⇒ Object

rows: ordered [label, value, color] for the reachable URLs (Local, Network, Public, …); backend is the real 127.0.0.1:port behind the proxy.



13
14
15
16
17
18
19
20
21
# File 'lib/portless/banner.rb', line 13

def app(rows:, backend_port:, proxy_version: nil)
  out = [ "", "  #{bold('rb-portless')} #{dim(versions(proxy_version))}", "" ]
  rows.each { |label, value, paint| out << row(label, send(paint || :cyan, value)) }
  out << row("Backend", dim("127.0.0.1:#{backend_port}"))
  out << ""
  out << "  #{dim('ready — press Ctrl-C to stop')}"
  out << ""
  warn out.join("\n")
end

.bold(str) ⇒ Object

── colours (target stderr, where the banner is printed) ──



44
# File 'lib/portless/banner.rb', line 44

def bold(str)  = Colors.bold(str, io: $stderr)

.cyan(str) ⇒ Object



46
# File 'lib/portless/banner.rb', line 46

def cyan(str)  = Colors.cyan(str, io: $stderr)

.dim(str) ⇒ Object



45
# File 'lib/portless/banner.rb', line 45

def dim(str)   = Colors.dim(str, io: $stderr)

.green(str) ⇒ Object



47
# File 'lib/portless/banner.rb', line 47

def green(str) = Colors.green(str, io: $stderr)

.multi(apps:, proxy_version: nil) ⇒ Object

Multi-app: one row per app (name → URL).



24
25
26
27
28
29
30
31
# File 'lib/portless/banner.rb', line 24

def multi(apps:, proxy_version: nil)
  out = [ "", "  #{bold('rb-portless')} #{dim(versions(proxy_version))}", "" ]
  apps.each { |app| out << row(app.name, cyan(app.url)) }
  out << ""
  out << "  #{dim('ready — press Ctrl-C to stop')}"
  out << ""
  warn out.join("\n")
end

.row(label, value) ⇒ Object



41
# File 'lib/portless/banner.rb', line 41

def row(label, value) = "  #{green('')}  #{label.to_s.ljust(8)}#{value}"

.versions(proxy_version) ⇒ Object

Always show both sides of the version handshake — a stale daemon is invisible otherwise (it keeps last week's code in memory across updates).



35
36
37
38
39
# File 'lib/portless/banner.rb', line 35

def versions(proxy_version)
  return "v#{VERSION}" unless proxy_version

  "v#{VERSION} · proxy v#{proxy_version}"
end