adds cursor control ANSI escape codes#887
adds cursor control ANSI escape codes#887wassup05 wants to merge 4 commits intofortran-lang:masterfrom
Conversation
… the stdlib_ansi module
| @@ -0,0 +1,107 @@ | |||
| module stdlib_ansi_cursor | |||
There was a problem hiding this comment.
Could this be considered as a submodule of the module stdlib_ansi?
There was a problem hiding this comment.
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.
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.
Could some of these functions be elemental?
There was a problem hiding this comment.
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_cursorThis 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_ansifor 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_ansihas 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)