module WhirledPeas::Utils::Ansi
Helper module for working with ANSI escape codes. The most useful ANSI escape codes relate to text formatting.
Constants
- BLACK
Text and background color constants
- BLUE
- BOLD
Text formatting constants
- BRIGHT_OFFSET
Bright colors are offset by this much from their standard versions
- CYAN
- END_FORMATTING
- ESC
- GREEN
- MAGENTA
- RED
- UNDERLINE
- WHITE
- YELLOW
Public Class Methods
clear()
click to toggle source
# File lib/whirled_peas/utils/ansi.rb, line 58 def clear esc_seq(END_FORMATTING) end
clear_down()
click to toggle source
# File lib/whirled_peas/utils/ansi.rb, line 54 def clear_down "#{ESC}[J" end
cursor_pos(left:, top:)
click to toggle source
# File lib/whirled_peas/utils/ansi.rb, line 46 def cursor_pos(left:, top:) "#{ESC}[#{top + 1};#{left + 1}H" end
cursor_visible(visible)
click to toggle source
# File lib/whirled_peas/utils/ansi.rb, line 50 def cursor_visible(visible) visible ? "#{ESC}[?25h" : "#{ESC}[?25l" end
esc_seq(code)
click to toggle source
# File lib/whirled_peas/utils/ansi.rb, line 62 def esc_seq(code) "#{ESC}[#{code}m" end
with_screen(output=STDOUT, width: nil, height: nil) { |width, height| ... }
click to toggle source
# File lib/whirled_peas/utils/ansi.rb, line 31 def with_screen(output=STDOUT, width: nil, height: nil, &block) require 'highline' unless width && height width, height = HighLine.new.terminal.terminal_size end output.print cursor_visible(false) output.flush yield width, height ensure output.print clear output.print cursor_pos(left: 0, top: height - 1) output.print cursor_visible(true) output.flush end