adds cursor control ANSI escape codes
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, right- A couple of constants for clearning the terminal, clearning a line and it's different variants
Motivation
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 output
Side 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)
Nice work @wassup05, thank you. I'm no expert on ANSI terminal handling so I will add some of my thoughts here.
- The
stdlib_ansimodule has a derived type for ANSI escape codes:
https://github.com/fortran-lang/stdlib/blob/7511064e45476cc2deaa5af195fdb70cb73214d1/src/stdlib_ansi.f90#L23-L31
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 type(ansi_code) as well.
- Testing and examples are hard with console handling. However, I think it would be very useful to have examples that show some console interaction with these functions (for example, draw a box on the terminal, or something like that).
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 draw_box, whose width, height and the position (line, column) were it is drawn can be changed.. I added the link to it in the spec as well
Please let me know what you think about it