cransi
ANSI escape codes for terminal manipulation
Installation
- Add the dependency to your
shard.yml
:
dependencies:
cransi:
github: daviscodesbugs/cransi
- Run
shards install
Usage
require "cransi"
puts "Hello world!\nThanks for checking out cransi!"
print Cransi.cursor_save
wait
print Cransi.cursor_prev_line 2
wait
print Cransi.cursor_col 6
wait
print Cransi.insert_char 7
wait
print " there,"
wait
print Cransi.cursor_restore
wait
puts "Try this example with SLOW = true"
wait
SLOW = false
def wait
sleep 1.second if SLOW
end
Final output
Hello there, world!
Thanks for checking out cransi!
Try this example with SLOW = true
API
Additional documentation can be found here
Cursor Movement
cursor_up
Move the cursor upcursor_down
Move the cursor downcursor_forward
Move the cursor forwardcursor_backward
Move the cursor backwardcursor_next_line
Move the cursor to the beginning of the next linecursor_prev_line
Move the cursor to the beginning of the previous linecursor_col
Move the cursor to a specific columncursor_to
Move the cursor to a specific row & columncursor_save
Save the current position of the cursor to latercursor_restore
tocursor_restore
Restore the cursor to the position whencursor_save
was last calledcursor_show
Show the cursorcursor_hide
Hide the cursorcursor_get_pos
Get the current position of the cursorcursor_home
Return the cursor to row 0, column 0
Erase
For the following, a cell that is "erased" can also be thought of as blank
erase_chars
Mark cells from cursor as erasederase_end
Mark cells from the cursor the end of the line as erasederase_home
Mark cells from the beginning of the line to the cursor as erasederase_line
Mark the entire line as erasederase_down
Mark cells from the cursor the the bottom of the display as erasederase_up
Mark cells from the top of the display to the cursor as erasederase_screen
Mark the entire display as erasederase_terminal
Mark the entire display and the scroll-back buffer as erased
Insert
insert_char
Insert cells, shifting the rest of the line forwardinsert_line
Insert lines, shifting the current line downward
Delete
delete_char
Delete cells, shifting the rest of the line backwarddelete_line
Delete lines, shifting following lines upward
Misc
repeat
Repeat the last printable characterscroll_up
Shift all lines upward, generating new linesscroll_down
Shift all lines downward
Contributing
- Fork it (https://github.com/daviscodesbugs/cransi/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- daviscodsbugs - creator and maintainer