Class: GitJump::Utils::Output
- Inherits:
-
Object
- Object
- GitJump::Utils::Output
- Defined in:
- lib/git_jump/utils/output.rb
Overview
Handles formatted console output with colors and tables
Instance Attribute Summary collapse
-
#quiet ⇒ Object
readonly
Returns the value of attribute quiet.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Instance Method Summary collapse
- #branch_list(branches, current_branch) ⇒ Object
- #debug(message) ⇒ Object
- #error(message) ⇒ Object
- #heading(message) ⇒ Object
- #info(message) ⇒ Object
-
#initialize(quiet: false, verbose: false) ⇒ Output
constructor
A new instance of Output.
- #prompt(message, _default: "N") ⇒ Object
- #success(message) ⇒ Object
- #table(headers, rows) ⇒ Object
- #warning(message) ⇒ Object
Constructor Details
#initialize(quiet: false, verbose: false) ⇒ Output
Returns a new instance of Output.
11 12 13 14 |
# File 'lib/git_jump/utils/output.rb', line 11 def initialize(quiet: false, verbose: false) @quiet = quiet @verbose = verbose end |
Instance Attribute Details
#quiet ⇒ Object (readonly)
Returns the value of attribute quiet.
9 10 11 |
# File 'lib/git_jump/utils/output.rb', line 9 def quiet @quiet end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
9 10 11 |
# File 'lib/git_jump/utils/output.rb', line 9 def verbose @verbose end |
Instance Method Details
#branch_list(branches, current_branch) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/git_jump/utils/output.rb', line 50 def branch_list(branches, current_branch) return if quiet || branches.empty? heading("Tracked Branches") rows = branches.map.with_index(1) do |branch, index| name = branch["name"] marker = name == current_branch ? Colors.green("→") : " " styled_name = name == current_branch ? Colors.green(name, bold: true) : name last_visited = format_time(branch["last_visited_at"]) ["#{marker} #{index}", styled_name, last_visited] end table(["#", "Branch", "Last Visited"], rows) end |
#debug(message) ⇒ Object
32 33 34 |
# File 'lib/git_jump/utils/output.rb', line 32 def debug() puts Colors.dim() if verbose end |
#error(message) ⇒ Object
20 21 22 |
# File 'lib/git_jump/utils/output.rb', line 20 def error() warn Colors.red("✗ #{}") end |
#heading(message) ⇒ Object
36 37 38 39 40 |
# File 'lib/git_jump/utils/output.rb', line 36 def heading() puts unless quiet puts Colors.cyan(, bold: true) unless quiet puts Colors.dim("─" * .length) unless quiet end |
#info(message) ⇒ Object
28 29 30 |
# File 'lib/git_jump/utils/output.rb', line 28 def info() puts Colors.blue("ℹ #{}") unless quiet end |
#prompt(message, _default: "N") ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/git_jump/utils/output.rb', line 67 def prompt(, _default: "N") return true if quiet # Auto-confirm in quiet mode print Colors.yellow("#{} [y/N] ") answer = $stdin.gets&.chomp&.downcase %w[y yes].include?(answer) end |
#success(message) ⇒ Object
16 17 18 |
# File 'lib/git_jump/utils/output.rb', line 16 def success() puts Colors.green("✓ #{}") unless quiet end |
#table(headers, rows) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/git_jump/utils/output.rb', line 42 def table(headers, rows) return if quiet require "terminal-table" unless defined?(Terminal::Table) table = Terminal::Table.new(headings: headers, rows: rows) puts table end |