-
Notifications
You must be signed in to change notification settings - Fork 3k
Add io_ansi module #9940
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
base: master
Are you sure you want to change the base?
Add io_ansi module #9940
Conversation
CT Test Results 5 files 288 suites 2h 58m 4s ⏱️ Results for commit a6e4754. ♻️ This comment has been updated with latest results. To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass. See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally. Artifacts// Erlang/OTP Github Action Bot |
b17ffb1
to
a6e4754
Compare
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.
Great work
-doc """ | ||
Change background color to index color. `Index` 0-15 are equivilant to | ||
the named colors in `t:background_color/0` in the order that they are listed. | ||
|
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.
I guess you have already thought about this but why not have:
foreground/1
and background/1
accept color atoms directly?
Then you could remove all Color() and Color_background() functions.
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.
hmm, good point! we can definitely do that!
?FUNCTION(negative_off). | ||
|
||
-doc """ |
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.
Similiar to previous comment, do we want a style(Style::atom())
function.
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.
in this case I don't think so as the style
does not add any additional information while background
/foreground
does.
?SPEC(cursor_report_position). | ||
?FUNCTION(cursor_report_position). |
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.
Is a cursor_get_position() -> {Col:integer(), Row:integer()}
feasible?
So I don't have to parse the ANSI codes, when debugging?
Or do I do that with one of the terminfo functions?
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.
It might be possible. The problem I have found is that this function is rather slow, so I'm not sure it has any practical usecases... also there are no terminfo function for parsing stuff... so I'd have to do that myself.
Activate the alternate screen. | ||
|
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.
Maybe a short description of what alternate screen do?
Most of the other stuff is self explanatory but this I would have to go to other docs.
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.
will do!
[case Data of | ||
<<Value:(byte_size(Value))/binary, Rest/binary>> -> | ||
throw({Key, Value, Rest}); | ||
_ -> | ||
ok | ||
end || Key := Values <- get_vts_mappings(), | ||
Value <- Values], |
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 code is un-parseable for me :-)
Re-write with a fun() in the map-comprehension or something?
Co-authored-by: Dan Gudmundsson <[email protected]>
This PR adds a new module called
io_ansi
that allows the user to emit Virtual Terminal Sequences (aka ansi sequences) to the terminal in order to add colors/styling to text, or create fullyfledged terminal applications.io_ansi
uses the local terminfo database in order to be as cross-platform compatibly as possible.It also works across nodes so that if functions on a remote node calls
io_ansi:fwrite/1
it will use the destination terminals terminfo database to determine which sequences to emit. In practice this means that you can call things in a remote shell session that usesio_ansi
and it will properly detects that terminal sequences the target terminal can handle and will print using them correctly.At the same time all at-hoc ANSI escape sequence usage in Erlang/OTP has been migrated to use
io_ansi
and the terminal application user's guide has been updated.