module Dev::UI::ANSI
Constants
- ESC
Public Class Methods
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/dev/ui/ansi.rb, line 132 def self.cursor_restore control('', 'u') end
cursor_save()
click to toggle source
Save the cursor position
# File lib/dev/ui/ansi.rb, line 126 def self.cursor_save control('', 's') end
cursor_up(n = 1)
click to toggle source
end_of_line()
click to toggle source
Move to the end of the line
# File lib/dev/ui/ansi.rb, line 150 def self.end_of_line control("\033[", 'C') end
hide_cursor()
click to toggle source
Hide the cursor
# File lib/dev/ui/ansi.rb, line 120 def self.hide_cursor control('', "?25l") end
next_line()
click to toggle source
Move to the next line
# File lib/dev/ui/ansi.rb, line 138 def self.next_line cursor_down + control('1', 'G') end
previous_line()
click to toggle source
Move to the previous line
# File lib/dev/ui/ansi.rb, line 144 def self.previous_line cursor_up + control('1', 'G') 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/dev/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 else acc + 1 end end end
sgr(params)
click to toggle source
en.wikipedia.org/wiki/ANSI_escape_code#graphics
# File lib/dev/ui/ansi.rb, line 52 def self.sgr(params) control(params.to_s, 'm') end
show_cursor()
click to toggle source
Show the cursor
# File lib/dev/ui/ansi.rb, line 114 def self.show_cursor control('', "?25h") end