ansi-diff icon indicating copy to clipboard operation
ansi-diff copied to clipboard

Add support for windows (No, not the operating system ;-) )

Open piranna opened this issue 6 years ago • 1 comments

In terminals, a window is a sub-region of the screen, similar to boxes in blessed. I've review the code and it's focused on generating ANSI diffs to be directly printed in the screen, but seems everything is in place to add support for windows. To do so, seems the only missing parts are:

  • [ ] top and left options in addition to width and height. By default they can be set to zero, but if set, all the newlines and clear screen moves should be set to their values instead of zero, so it's easy.
  • [ ] add right and bottom options, or replace width and height with them, because if a windows have non-zero top and left values, then its width and height are not anymore the window right and bottom ones.
  • [x] hard wrapping. At this moment, if a line is longer than screen width, it's left to the terminal itself to do the wrapping to the new line, but with non-zero left value, then it would print at the left side of the screen instead of the window. Hard wrapping would be done just by inserting moveTo() calls when the end of a window is reached.
  • [ ] windows inception, allowing to have windows relatives to another parent windows :-) Although maybe this could be done in another module, but having a test for that would not hurt...

If you don't have the time to work on that, maybe I could be able to start a pull-request and start discussing it... :-)

piranna avatar Apr 29 '18 19:04 piranna

I've seen there could be a problem with CLEAR_LINE, since it has the ANSI codes to clean all the line until the end of the screen, so will not work with the windows. One option would be to wrap it in a function and create a new Window class the same way the Diff one is working as a Screen one, so for Window instances it would be implemented as writting whitespaces until the right side of the Window.

This lead to another thing: what about updating the code to have separated files for Diff, Line and the util functions, and use ES6 classes and other similar features? This way Screen would inherit from Window, so Screen would focus only on actual screen related things. It would break compatibility and need to be published as a major version, but would be a huge move forward for the code... :-)

piranna avatar Apr 29 '18 20:04 piranna