module CLI::UI::ANSI
Constants
- ESC
Public Class Methods
clear_to_end_of_line()
click to toggle source
# File lib/cli/ui/ansi.rb, line 152 def self.clear_to_end_of_line control('', 'K') end
control(args, cmd)
click to toggle source
cursor_back(n = 1)
click to toggle source
cursor_down(n = 1)
click to toggle source
cursor_forward(n = 1)
click to toggle source
cursor_horizontal_absolute(n = 1)
click to toggle source
cursor_restore()
click to toggle source
Restore the saved cursor position
# File lib/cli/ui/ansi.rb, line 136 def self.cursor_restore control('', 'u') end
cursor_save()
click to toggle source
Save the cursor position
# File lib/cli/ui/ansi.rb, line 130 def self.cursor_save control('', 's') end
cursor_up(n = 1)
click to toggle source
hide_cursor()
click to toggle source
Hide the cursor
# File lib/cli/ui/ansi.rb, line 124 def self.hide_cursor control('', '?25l') end
next_line()
click to toggle source
Move to the next line
# File lib/cli/ui/ansi.rb, line 142 def self.next_line cursor_down + cursor_horizontal_absolute end
previous_line()
click to toggle source
Move to the previous line
# File lib/cli/ui/ansi.rb, line 148 def self.previous_line cursor_up + cursor_horizontal_absolute end
printing_width(str)
click to toggle source
ANSI
escape sequences (like x1b[31m) have zero width. when calculating the padding width, we must exclude them. This also implements a basic version of utf8 character width calculation like we could get for real from something like utf8proc.
# File lib/cli/ui/ansi.rb, line 13 def self.printing_width(str) zwj = false strip_codes(str).codepoints.reduce(0) do |acc, cp| if zwj zwj = false next acc end case cp when 0x200d # zero-width joiner zwj = true acc when "\n" acc else acc + 1 end end end
sgr(params)
click to toggle source
en.wikipedia.org/wiki/ANSI_escape_code#graphics
# File lib/cli/ui/ansi.rb, line 54 def self.sgr(params) control(params.to_s, 'm') end
show_cursor()
click to toggle source
Show the cursor
# File lib/cli/ui/ansi.rb, line 118 def self.show_cursor control('', '?25h') end