fusesource / jansi

Jansi is a small java library that allows you to use ANSI escape sequences to format your console output which works even on windows.
http://fusesource.github.io/jansi/
Apache License 2.0
1.11k stars 140 forks source link

change OutputStream to Writer, because char != byte #152

Closed Arnaud-Nauwynck closed 3 years ago

Arnaud-Nauwynck commented 5 years ago

changed OutputStream to Writer ... so method "write(int)" now receive and interpret argument as "char" instead of "byte" also implement/override methods write(char[]), write(char[],int,int), write(String), write(CharSequence) ...

rename accordingly AnsiOutputStream -> AnsiFilterWriter HtmlAnsiOutputStream -> HtmlAnsiFilterWriter

there is no more encoding problem in strange conversion byte[]->String using new String(..Charset.defaultCharset()), or String->byte[] using String.getBytes(.. "UTF-8") There is also no more suspect int->(byte) conversion, but int->(char)

Dunemaster commented 4 years ago

@Arnaud-Nauwynck , I am not a maintainer (@hboutemy is?), but I will try to look through the commit to try to speed up the process a bit

gnodet commented 4 years ago

While I agree about Writer != OutputStream, I don't think it's wise to just rename 4 classes in the library, that will break everything.

Arnaud-Nauwynck commented 4 years ago

@gnodet, I am very glad you have a look to this PR. I understand that the change from Stream to Writer will break dependencies. If you really think these classes OutputStream are part of a public API, maybe it is still possible to keep theses classes unmodified, do not use them internally, and mark them as @Deprecated (for future removal ?) I believe most users will use Jansi public API only with "AnsiConsole.systemInstall()", and "ansi()" helper methods, and would not touch any internal OutputStream/Writer classes.

The initial goal was not to do refactoring, but to improve the performance bottlenecks due to lack of buffering and avoiding the system calls flush() char per char (byte per byte..)... so it really has to be considered with optimization pull request #150 (and #149 is the corresponding benchmark test)... to gain a performance factor ~ x2.5

I understand my PR has to be considered as a proof-of-concept and work in progress, with backward-compatibility to enhance, code to cleanup, comments to add, unit tests, etc...

Regards,

gnodet commented 3 years ago

Fixed by https://github.com/fusesource/jansi/commit/57aa84d4120395922458f61f20e741198f051087