github.com/daviscodesbugs/cransi
0.1.0 / published Sep 30, 2019 / repository
ANSI escape codes for terminal manipulation
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_upMove the cursor upcursor_downMove the cursor downcursor_forwardMove the cursor forwardcursor_backwardMove the cursor backwardcursor_next_lineMove the cursor to the beginning of the next linecursor_prev_lineMove the cursor to the beginning of the previous linecursor_colMove the cursor to a specific columncursor_toMove the cursor to a specific row & columncursor_saveSave the current position of the cursor to latercursor_restoretocursor_restoreRestore the cursor to the position whencursor_savewas last calledcursor_showShow the cursorcursor_hideHide the cursorcursor_get_posGet the current position of the cursorcursor_homeReturn the cursor to row 0, column 0
Erase
For the following, a cell that is "erased" can also be thought of as blank
erase_charsMark cells from cursor as erasederase_endMark cells from the cursor the end of the line as erasederase_homeMark cells from the beginning of the line to the cursor as erasederase_lineMark the entire line as erasederase_downMark cells from the cursor the the bottom of the display as erasederase_upMark cells from the top of the display to the cursor as erasederase_screenMark the entire display as erasederase_terminalMark the entire display and the scroll-back buffer as erased
Insert
insert_charInsert cells, shifting the rest of the line forwardinsert_lineInsert lines, shifting the current line downward
Delete
delete_charDelete cells, shifting the rest of the line backwarddelete_lineDelete lines, shifting following lines upward
Misc
repeatRepeat the last printable characterscroll_upShift all lines upward, generating new linesscroll_downShift 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
API
- Cransi
Cransi encapsulates a collection of ANSI escape codes that can be used to manipulate the terminal