class Bash_Visual::Builder
Public Class Methods
new(font = Font.new)
click to toggle source
# File lib/bash-visual/builder.rb, line 6 def initialize (font = Font.new) @default_font = font end
Public Instance Methods
clear()
click to toggle source
# File lib/bash-visual/builder.rb, line 10 def clear set_position(0, 0) + "\e[2J" end
erase_to_end_line()
click to toggle source
# File lib/bash-visual/builder.rb, line 14 def erase_to_end_line "\e[K" end
move_position(offset_x, offset_y)
click to toggle source
# File lib/bash-visual/builder.rb, line 30 def move_position(offset_x, offset_y) bash = '' if (offset_y > 0) bash << "\e[#{offset_y}B" else bash << "\e[#{offset_y.abs}A" end if (offset_x > 0) bash << "\e[#{offset_x}C" else bash << "\e[#{offset_x.abs}D" end bash end
restore_position()
click to toggle source
# File lib/bash-visual/builder.rb, line 18 def restore_position "\e[u" end
save_position()
click to toggle source
# File lib/bash-visual/builder.rb, line 22 def save_position "\e[s" end
set_position(x, y)
click to toggle source
# File lib/bash-visual/builder.rb, line 26 def set_position(x, y) "\e[#{y.to_i};#{x.to_i}H" end
write(text, font = nil)
click to toggle source
# File lib/bash-visual/builder.rb, line 54 def write(text, font = nil) return text if font.nil? font.to_bash + text + Font::RESET end
write_ln(text, font = nil)
click to toggle source
# File lib/bash-visual/builder.rb, line 59 def write_ln(text, font = nil) return text + "\n" if font.nil? font.to_bash + text.to_s + "\n" + Font::RESET end
write_to_position(x, y, text, font = nil)
click to toggle source
# File lib/bash-visual/builder.rb, line 45 def write_to_position(x, y, text, font = nil) bash = '' bash << save_position() bash << move_position(x, y) bash << write(text, font) bash << restore_position() bash end