Module: LanguageOperator::CLI::Helpers::UxHelper
- Included in:
- BaseCommand, Commands::Agent::Base, Commands::Cluster, Commands::Persona, Commands::Status, Commands::Use, Errors::Handler, Errors::Suggestions, Formatters::CodeFormatter, Formatters::LogFormatter, Formatters::ProgressFormatter, Formatters::StatusFormatter, Formatters::TableFormatter, Main, Wizards::AgentWizard, Wizards::ModelWizard
- Defined in:
- lib/language_operator/cli/helpers/ux_helper.rb
Overview
Provides unified access to TTY UI components across all CLI commands, formatters, wizards, and error handlers.
This module consolidates TTY initialization that was previously duplicated across multiple files. It provides memoized instances to avoid unnecessary object allocation.
Available helpers:
pastel- Terminal colors and stylesprompt- Interactive user inputspinner- Loading/progress spinnerstable- Formatted table displaybox- Framed messages
Instance Method Summary collapse
-
#box(message, title: nil, border: :light, padding: 1) ⇒ String
Creates a framed box around a message.
-
#highlight_ruby_code(code_content) ⇒ String
Highlights Ruby code with syntax highlighting for terminal display.
- #logo(title: nil, sparkle: false) ⇒ Object
-
#pastel ⇒ Pastel
Returns a memoized Pastel instance for colorizing terminal output.
-
#prompt ⇒ TTY::Prompt
Returns a memoized TTY::Prompt instance for interactive input.
-
#spinner(message, format: :dots) ⇒ TTY::Spinner
Creates a new spinner for long-running operations.
-
#table(header, rows, style: :unicode) ⇒ TTY::Table
Creates a formatted table for structured data display.
Instance Method Details
#box(message, title: nil, border: :light, padding: 1) ⇒ String
Creates a framed box around a message
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/language_operator/cli/helpers/ux_helper.rb', line 123 def box(, title: nil, border: :light, padding: 1) require 'tty-box' = { padding: padding, border: border } [:title] = { top_left: " #{title} " } if title TTY::Box.frame(, **) end |
#highlight_ruby_code(code_content) ⇒ String
Highlights Ruby code with syntax highlighting for terminal display
141 142 143 |
# File 'lib/language_operator/cli/helpers/ux_helper.rb', line 141 def highlight_ruby_code(code_content) rouge_formatter.format(rouge_lexer.lex(code_content)) end |
#logo(title: nil, sparkle: false) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/language_operator/cli/helpers/ux_helper.rb', line 145 def logo(title: nil, sparkle: false) puts if sparkle animate_sparkle_logo else puts "#{pastel.bold.green('LANGUAGE OPERATOR')} v#{pastel.bold(LanguageOperator::VERSION)}" end puts pastel.dim("#{pastel.bold('↪')} #{title}") if title puts end |
#pastel ⇒ Pastel
Returns a memoized Pastel instance for colorizing terminal output
54 55 56 |
# File 'lib/language_operator/cli/helpers/ux_helper.rb', line 54 def pastel @pastel ||= Pastel.new end |
#prompt ⇒ TTY::Prompt
Returns a memoized TTY::Prompt instance for interactive input
65 66 67 |
# File 'lib/language_operator/cli/helpers/ux_helper.rb', line 65 def prompt @prompt ||= TTY::Prompt.new end |
#spinner(message, format: :dots) ⇒ TTY::Spinner
Creates a new spinner for long-running operations
82 83 84 85 86 87 88 89 90 |
# File 'lib/language_operator/cli/helpers/ux_helper.rb', line 82 def spinner(, format: :dots) require 'tty-spinner' TTY::Spinner.new( "[:spinner] #{}", format: format, success_mark: pastel.green('✓'), error_mark: pastel.red('✗') ) end |
#table(header, rows, style: :unicode) ⇒ TTY::Table
Creates a formatted table for structured data display
104 105 106 107 108 |
# File 'lib/language_operator/cli/helpers/ux_helper.rb', line 104 def table(header, rows, style: :unicode) require 'tty-table' tbl = TTY::Table.new(header, rows) tbl.render(style, padding: [0, 1]) end |