Module: Omnibar::ANSI
- Defined in:
- lib/omnibar/ansi.rb
Overview
This module contains helpers for various ansi-code operations
Constant Summary collapse
- COLORS =
ANSI color escape codes set the foreground and background colors. Forground color is a number between 30 and 37. Background color is a number between 40 and 47. The ones place represents the same color for both.
[:black, :red, :green, :yellow, :blue, :magenta, :cyan, 'white', nil, :white].freeze
Class Method Summary collapse
- .clear_screen ⇒ Object
- .color(text, fg: :white, bg: :black) ⇒ Object
- .move_cursor(row, col) ⇒ Object
- .reset ⇒ Object
- .size ⇒ Object
Class Method Details
.clear_screen ⇒ Object
10 11 12 |
# File 'lib/omnibar/ansi.rb', line 10 def self.clear_screen $stdout.write "\e[2J" end |
.color(text, fg: :white, bg: :black) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/omnibar/ansi.rb', line 18 def self.color(text, fg: :white, bg: :black) fg = COLORS.index(fg) + 30 bg = COLORS.index(bg) + 40 code = "\e[#{[fg, bg].compact.join(';')}m" "#{code}#{text}\e[0m" end |
.move_cursor(row, col) ⇒ Object
14 15 16 |
# File 'lib/omnibar/ansi.rb', line 14 def self.move_cursor(row, col) $stdout.write "\e[#{row + 1};#{col + 1}H" end |
.reset ⇒ Object
25 26 27 |
# File 'lib/omnibar/ansi.rb', line 25 def self.reset "\e[0m" end |
.size ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/omnibar/ansi.rb', line 29 def self.size win = IO.console.winsize { height: win[0], width: win[1] } end |