Module: Railstart::UI
- Defined in:
- lib/railstart/ui.rb
Overview
Provides UI enhancement utilities for the Railstart CLI.
Handles ASCII art headers, styled boxes, and visual polish to create a Laravel-like installer experience.
Defined Under Namespace
Classes: NullPastel
Constant Summary collapse
- LOGO =
ASCII art logo for Railstart
<<~LOGO ╔═╗┌─┐┬┬ ┌─┐┌┬┐┌─┐┬─┐┌┬┐ ╠╦╝├─┤││ └─┐ │ ├─┤├┬┘ │ ╩╚═┴ ┴┴┴─┘└─┘ ┴ ┴ ┴┴└─ ┴ LOGO
Class Method Summary collapse
-
.error(message) ⇒ void
Display an error message with icon.
-
.info(message) ⇒ void
Display an info message with icon.
-
.pastel ⇒ Pastel
Lazy-load Pastel for color formatting.
-
.rails_version ⇒ String
Detect the installed Rails version.
-
.section(title, separator: true) ⇒ void
Display a section header with optional separator line.
-
.show_logo(color: :cyan) ⇒ void
Display the Railstart ASCII art logo with version and optional color.
-
.show_welcome(message = nil) ⇒ void
Display a styled welcome message in a box.
-
.success(message) ⇒ void
Display a success message with checkmark.
-
.warning(message) ⇒ void
Display a warning message with icon.
Instance Method Summary collapse
-
#error(message) ⇒ void
private
Display an error message with icon.
-
#info(message) ⇒ void
private
Display an info message with icon.
-
#pastel ⇒ Pastel
private
Lazy-load Pastel for color formatting.
-
#rails_version ⇒ String
private
Detect the installed Rails version.
-
#section(title, separator: true) ⇒ void
private
Display a section header with optional separator line.
-
#show_logo(color: :cyan) ⇒ void
private
Display the Railstart ASCII art logo with version and optional color.
-
#show_welcome(message = nil) ⇒ void
private
Display a styled welcome message in a box.
-
#success(message) ⇒ void
private
Display a success message with checkmark.
-
#warning(message) ⇒ void
private
Display a warning message with icon.
Class Method Details
.error(message) ⇒ void
This method returns an undefined value.
Display an error message with icon.
104 105 106 |
# File 'lib/railstart/ui.rb', line 104 def error() puts pastel.red("✗ #{}") end |
.info(message) ⇒ void
This method returns an undefined value.
Display an info message with icon.
113 114 115 |
# File 'lib/railstart/ui.rb', line 113 def info() puts pastel.blue("ℹ #{}") end |
.pastel ⇒ Pastel
Lazy-load Pastel for color formatting.
121 122 123 124 125 126 127 128 129 130 |
# File 'lib/railstart/ui.rb', line 121 def pastel @pastel ||= begin require "pastel" Pastel.new rescue LoadError # Fallback to no-op if pastel is not available # (tty-prompt depends on pastel, so this should never happen) NullPastel.new end end |
.rails_version ⇒ String
Detect the installed Rails version.
60 61 62 63 64 65 66 67 68 |
# File 'lib/railstart/ui.rb', line 60 def rails_version require "bundler" Bundler.with_unbundled_env do version_output = `rails --version 2>/dev/null`.strip version_output[/Rails (\d+\.\d+\.\d+)/, 1] || "Unknown" end rescue StandardError "Unknown" end |
.section(title, separator: true) ⇒ void
This method returns an undefined value.
Display a section header with optional separator line.
76 77 78 79 |
# File 'lib/railstart/ui.rb', line 76 def section(title, separator: true) puts pastel.cyan.bold(title.to_s) puts pastel.dim("─" * 60) if separator end |
.show_logo(color: :cyan) ⇒ void
This method returns an undefined value.
Display the Railstart ASCII art logo with version and optional color.
25 26 27 28 29 30 |
# File 'lib/railstart/ui.rb', line 25 def show_logo(color: :cyan) require_relative "version" puts pastel.send(color, LOGO) puts pastel.dim(" v#{Railstart::VERSION}") puts end |
.show_welcome(message = nil) ⇒ void
This method returns an undefined value.
Display a styled welcome message in a box.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/railstart/ui.rb', line 37 def show_welcome( = nil) ||= "Interactive Rails #{rails_version} Application Generator" box = TTY::Box.frame( width: 60, height: 3, align: :center, padding: [0, 1], border: :thick, style: { fg: :cyan, border: { fg: :cyan } } ) { } puts box puts # blank line end |
.success(message) ⇒ void
This method returns an undefined value.
Display a success message with checkmark.
86 87 88 |
# File 'lib/railstart/ui.rb', line 86 def success() puts pastel.green("✓ #{}") end |
.warning(message) ⇒ void
This method returns an undefined value.
Display a warning message with icon.
95 96 97 |
# File 'lib/railstart/ui.rb', line 95 def warning() puts pastel.yellow("⚠ #{}") end |
Instance Method Details
#error(message) ⇒ void (private)
This method returns an undefined value.
Display an error message with icon.
104 105 106 |
# File 'lib/railstart/ui.rb', line 104 def error() puts pastel.red("✗ #{}") end |
#info(message) ⇒ void (private)
This method returns an undefined value.
Display an info message with icon.
113 114 115 |
# File 'lib/railstart/ui.rb', line 113 def info() puts pastel.blue("ℹ #{}") end |
#pastel ⇒ Pastel (private)
Lazy-load Pastel for color formatting.
121 122 123 124 125 126 127 128 129 130 |
# File 'lib/railstart/ui.rb', line 121 def pastel @pastel ||= begin require "pastel" Pastel.new rescue LoadError # Fallback to no-op if pastel is not available # (tty-prompt depends on pastel, so this should never happen) NullPastel.new end end |
#rails_version ⇒ String (private)
Detect the installed Rails version.
60 61 62 63 64 65 66 67 68 |
# File 'lib/railstart/ui.rb', line 60 def rails_version require "bundler" Bundler.with_unbundled_env do version_output = `rails --version 2>/dev/null`.strip version_output[/Rails (\d+\.\d+\.\d+)/, 1] || "Unknown" end rescue StandardError "Unknown" end |
#section(title, separator: true) ⇒ void (private)
This method returns an undefined value.
Display a section header with optional separator line.
76 77 78 79 |
# File 'lib/railstart/ui.rb', line 76 def section(title, separator: true) puts pastel.cyan.bold(title.to_s) puts pastel.dim("─" * 60) if separator end |
#show_logo(color: :cyan) ⇒ void (private)
This method returns an undefined value.
Display the Railstart ASCII art logo with version and optional color.
25 26 27 28 29 30 |
# File 'lib/railstart/ui.rb', line 25 def show_logo(color: :cyan) require_relative "version" puts pastel.send(color, LOGO) puts pastel.dim(" v#{Railstart::VERSION}") puts end |
#show_welcome(message = nil) ⇒ void (private)
This method returns an undefined value.
Display a styled welcome message in a box.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/railstart/ui.rb', line 37 def show_welcome( = nil) ||= "Interactive Rails #{rails_version} Application Generator" box = TTY::Box.frame( width: 60, height: 3, align: :center, padding: [0, 1], border: :thick, style: { fg: :cyan, border: { fg: :cyan } } ) { } puts box puts # blank line end |
#success(message) ⇒ void (private)
This method returns an undefined value.
Display a success message with checkmark.
86 87 88 |
# File 'lib/railstart/ui.rb', line 86 def success() puts pastel.green("✓ #{}") end |
#warning(message) ⇒ void (private)
This method returns an undefined value.
Display a warning message with icon.
95 96 97 |
# File 'lib/railstart/ui.rb', line 95 def warning() puts pastel.yellow("⚠ #{}") end |