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:) ⇒ 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:)
  out = [ "", "  #{bold('rb-portless')} #{dim("v#{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) ──



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

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

.cyan(str) ⇒ Object



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

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

.dim(str) ⇒ Object



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

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

.green(str) ⇒ Object



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

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

.multi(apps:) ⇒ 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:)
  out = [ "", "  #{bold('rb-portless')} #{dim("v#{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



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

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