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
-
.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.
- .bold(str) ⇒ Object
- .cyan(str) ⇒ Object
- .dim(str) ⇒ Object
- .green(str) ⇒ Object
-
.multi(apps:) ⇒ Object
Multi-app: one row per app (name → URL).
-
.paint(code, str) ⇒ Object
── colours (no-op unless stderr is a TTY) ──.
- .row(label, value) ⇒ Object
- .tty? ⇒ Boolean
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
37 |
# File 'lib/portless/banner.rb', line 37 def bold(str) = paint("1", str) |
.cyan(str) ⇒ Object
39 |
# File 'lib/portless/banner.rb', line 39 def cyan(str) = paint("36", str) |
.dim(str) ⇒ Object
38 |
# File 'lib/portless/banner.rb', line 38 def dim(str) = paint("90", str) |
.green(str) ⇒ Object
40 |
# File 'lib/portless/banner.rb', line 40 def green(str) = paint("32", str) |
.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 |
.paint(code, str) ⇒ Object
── colours (no-op unless stderr is a TTY) ──
36 |
# File 'lib/portless/banner.rb', line 36 def paint(code, str) = tty? ? "\e[#{code}m#{str}\e[0m" : str |
.row(label, value) ⇒ Object
33 |
# File 'lib/portless/banner.rb', line 33 def row(label, value) = " #{green('➜')} #{label.to_s.ljust(8)}#{value}" |
.tty? ⇒ Boolean
41 |
# File 'lib/portless/banner.rb', line 41 def tty? = $stderr.tty? |