Remove trailing whitespace for StreamOutputComponent
From !351 (comment 981056):
- I saw trailing whitespace in the expected test output. I'm wonder, should we prevent that in this application itself? Or should we change
StreamOutputComponent
(in a separate issue), to right-trim outputted lines? But then, if for instance ToolDef script explicitly prints trailing whitespace, that is then also removed, which may not be desired? What do you think?
From !351 (comment 982603):
Wrt trailing whitespace, I noticed it too and somewhat managed to avoid it, but indeed it's out of scope here.
The underlying cause is that we don't collect text of a line until we have a EOL. Instead we simply stream characters directly to the output. For indenting you then don't have a choice to delay sending indenting spaces.
The advantage of the current solution is its simplicity and its directness, you immediately see everything printed rather than having to wait until the entire line is written by the application.
To fix trailing whitespace, collecting text until getting an EOL and then right-trim could work. Obviously that breaks "directness" to some extent. That gets annoying in some extreme cases, eg in Unix
./program | tee file
writes output in 64K blocks to the screen due to buffering in the pipe (./program | tee file | more
mostly fixes it again :p )
I am not sure we actually ever need trailing whitespace in output. To keep that door open we could add araw_out()
function or so.Another option is to keep a count of "missing indentation spaces". Indenting the text then simply changes that value. Printing anything (perhaps including spaces but that's another design decision) would cause a flush of "count" indentation spaces before the new printed characters. Note that here you do have the option to distinguish between indentation spaces and printed spaces.
Things to consider:
-
StreamOutputComponent
does print per line. It has code likeout.println(Strings.spaces(indent * 4) + msg);
. Ifmsg
is empty, then only the indentation is printed, which become trailing whitespace. We could easily fix that, ifmsg
is empty. - If
msg
is not empty, we could also right trim that. But we'd have to check where it is used, whether that has side effects, is really desired, etc. So that may require more discussion first.