-
Notifications
You must be signed in to change notification settings - Fork 168
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
adds cursor control ANSI escape codes #887
base: master
Are you sure you want to change the base?
Conversation
… the stdlib_ansi module
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.
Thank you @wassup05 for this PR. It sounds like a good start. I left a few comments.
@@ -0,0 +1,107 @@ | |||
module stdlib_ansi_cursor |
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.
Could this be considered as a submodule of the module stdlib_ansi
?
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.
Thank you for reviewing!
It could be, but I thought separating it would be better since stdlib_ansi
revolves around it's own derived type whereas this doesn't... I'm open to either way though
|
||
character(len=*), parameter :: esc = achar(27) | ||
!> moves the cursor to home => `(0,0)` | ||
character(len=*), parameter :: home = esc//"[H" |
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 this the same for all OS?
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.
Yes, It's more of a terminal thing than an OS thing.. But almost all of the modern terminals support these ansi codes
contains | ||
!> moves the cursor to `(line, column)` | ||
!> returns an empty string if any of them is negative | ||
pure function move_to(line, col) result(str) |
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.
Could some of these functions be elemental
?
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.
They could be made so, But I don't think it's worth it since I don't see anyone using it like that
…essages to tests, small fixes
Nice work @wassup05, thank you. I'm no expert on ANSI terminal handling so I will add some of my thoughts here.
Lines 23 to 31 in 7511064
If the terminal handling codes provided here match the same pattern, I believe it would be better to uniform their handling with that of the module, and make them
|
Thanks for replying, @perazz ! When I started working on this, I thought of ways to integrate the two but couldn't really find any such way... As these are more action oriented whereas those of ansi_type were more of like changing the properties of the text being printed Regarding examples... I added an example in the recent commit which basically draws a blue box on the screen using a subroutine Please let me know what you think about it |
The PR adds cursor control ANSI escape codes as a separate module
stdlib_ansi_cursor
This was brought up scarcely in #229 but was not really discussed.
Functions added are
move_to(x,y)
move_to_column(x)
move_<direction>
where<direction>
is any one of up, down, left, rightMotivation
There is already a module
stdlib_ansi
for ANSI escape codes of foreground, background colors and the different styles... If a person finds the use for such module it is very probable that he will also at some point want to control the cursor position too, to let's say, implement a custom loading animation or for elegant management of terminal outputSide note
I chose to make it a different module because of the difference in approach between the two, the functions in this module talk in terms of strings whereas
stdlib_ansi
has a whole type surrounding it and also because you won't need to add the cursor_ to all the functions to make it more readable... But I don't really see a problem in merging the two too...Edit: This is my first attempt at contributing here and I am not sure about who I am supposed to ask for feedback.. Could you guide me regarding this @perazz @jalvesz (I figured as you were the most active right now, hence pinging you would be appropriate)