ansi-diff
ansi-diff copied to clipboard
Add support for windows (No, not the operating system ;-) )
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
andleft
options in addition towidth
andheight
. 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
andbottom
options, or replacewidth
andheight
with them, because if a windows have non-zerotop
andleft
values, then itswidth
andheight
are not anymore the windowright
andbottom
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-zeroleft
value, then it would print at the left side of the screen instead of the window. Hard wrapping would be done just by insertingmoveTo()
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... :-)
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... :-)