-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add cursor movement to IO.ANSI #7396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a247c7d
12bfa2c
13ec4f0
16332ab
ee54a77
dc8c4d6
0b74e75
a3628b1
d4e0204
4d23cb2
7f9ad71
d057335
87350ba
0c60956
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,4 +155,69 @@ defmodule IO.ANSITest do | |
IO.ANSI.color_background(5, -1, 1) | ||
end | ||
end | ||
|
||
test "cursor/2" do | ||
assert IO.ANSI.cursor(0, 0) == "\e[0;0H" | ||
assert IO.ANSI.cursor(11, 12) == "\e[11;12H" | ||
|
||
assert_raise FunctionClauseError, fn -> | ||
IO.ANSI.cursor(-1, 5) | ||
end | ||
|
||
assert_raise FunctionClauseError, fn -> | ||
IO.ANSI.cursor(5, -1) | ||
end | ||
end | ||
|
||
test "cursor_up/1" do | ||
assert IO.ANSI.cursor_up() == "\e[1A" | ||
assert IO.ANSI.cursor_up(12) == "\e[12A" | ||
|
||
assert_raise FunctionClauseError, fn -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also test the value There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! Wouldn't it be best to have a guard that the value is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we go that way, the typespec should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had the guard as |
||
IO.ANSI.cursor_up(0) | ||
end | ||
|
||
assert_raise FunctionClauseError, fn -> | ||
IO.ANSI.cursor_up(-1) | ||
end | ||
end | ||
|
||
test "cursor_down/1" do | ||
assert IO.ANSI.cursor_down() == "\e[1B" | ||
assert IO.ANSI.cursor_down(2) == "\e[2B" | ||
|
||
assert_raise FunctionClauseError, fn -> | ||
IO.ANSI.cursor_right(0) | ||
end | ||
|
||
assert_raise FunctionClauseError, fn -> | ||
IO.ANSI.cursor_down(-1) | ||
end | ||
end | ||
|
||
test "cursor_left/1" do | ||
assert IO.ANSI.cursor_left() == "\e[1C" | ||
assert IO.ANSI.cursor_left(3) == "\e[3C" | ||
|
||
assert_raise FunctionClauseError, fn -> | ||
IO.ANSI.cursor_left(0) | ||
end | ||
|
||
assert_raise FunctionClauseError, fn -> | ||
IO.ANSI.cursor_left(-1) | ||
end | ||
end | ||
|
||
test "cursor_right/1" do | ||
assert IO.ANSI.cursor_right() == "\e[1D" | ||
assert IO.ANSI.cursor_right(4) == "\e[4D" | ||
|
||
assert_raise FunctionClauseError, fn -> | ||
IO.ANSI.cursor_right(0) | ||
end | ||
|
||
assert_raise FunctionClauseError, fn -> | ||
IO.ANSI.cursor_right(-1) | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also testing
cursor_up/0
:)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😁 so it is