-
-
Save emdeeeks/6b0df97510022970a9b97a931a171f80 to your computer and use it in GitHub Desktop.
Controlling Terminal Cursor in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def mv_up(n=1) | |
cursor(self, "\033[#{n}A") | |
end | |
def mv_down(n=1) | |
cursor(self, "\033[#{n}B") | |
end | |
def mv_fw(n=1) | |
cursor(self, "\033[#{n}C") | |
end | |
def mv_bw(n=1) | |
cursor(self, "\033[#{n}D") | |
end | |
def cls_upline | |
cursor(self, "\e[K") | |
end | |
def cls | |
# cursor(self, "\033[2J") | |
cursor(self, "\e[H\e[2J") | |
end | |
def save_position | |
cursor(self, "\033[s") | |
end | |
def restore_position | |
cursor(self, "\033[u") | |
end | |
def cursor(text, position) | |
"\r#{position}#{text}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment