Sha256: f37e2c16f5febc42f70271d71d32c85b6ccc1cc746cee47332c4780225387854
Contents?: true
Size: 1.13 KB
Versions: 4
Compression:
Stored size: 1.13 KB
Contents
# frozen_string_literal: true # Provides methods for colored console output and user interaction. # # The Console module contains methods for printing colored text to the terminal using # ANSI escape codes. It also includes utility methods for prompting user input. module Console # ANSI colors RED = 1 GREEN = 2 YELLOW = 3 PURPLE = 4 def self.color_puts(lines, color_code:) puts "\x1b[3#{color_code}m#{lines}\x1b[0m" end def self.header(title) color_puts(">>> #{title}", color_code: GREEN) # green end def self.info(text) color_puts(text, color_code: YELLOW) # yellow end def self.warning(text) color_puts(text, color_code: RED) # red end def self.print_indented_lines(lines) color_puts(lines.map { |l| "| #{l}" }.join, color_code: YELLOW) end def self.prompt(text, default_value) color_puts("#{text}? [default: #{default_value}] ", color_code: GREEN) answer = $stdin.gets.chomp answer = default_value if answer.empty? answer end def self.confirm(text) color_puts("#{text} [y/n]?", color_code: GREEN) answer = $stdin.gets.chomp answer.downcase == 'y' end end
Version data entries
4 entries across 4 versions & 1 rubygems