swaybar: only show last status line
Solves #4496
Have you tested whether this will work if the last line ends with a new-line character?
I did before and after these changes, and both output just a new line character. I wasnt sure whether to go further and make it ignore the last line if it's a new line character, or whether the onus is on whatever is generating the status line to not output empty lines.
I mean: if you send first line\nsecond line\n what does this output?
From memory it would just output a newline, so the status line would be empty. I will check again once #5106 is fixed.
In sway config: status_command tail -f /tmp/1 `printf "XXX" >/tmp/1 from my terminal to output to the file, and then running swaybar (killing swaybar in between runs):
| XXX | new bar output on startup |
|---|---|
| aaa | aaa |
| aaa\n | (empty) |
| aaa\nbbb | bbb |
| aaa\nbbb\n | (empty) |
However the second time aaa\nbbb\n or aaa\n is sent, it displays the last value instead of just \n.
Hmm...
I think that it should show the line before the \n character. However, i3bar seems to try to display all the lines if you send it multiple lines at once, but I'm not sure if we should deviate from its behaviour. We currently, do, since it only the last line is shown, but no-one seems to have complained so far.
It is very common to produce output from shell scripts using echo, which by default appends a newline at the end.
As far as i3bar goes, maybe it'd be a good idea to ask the i3 developers if its behaviour is intentional.
Yeah if no one else does then I will try find some time to install i3 and verify the existing behaviour before asking the guys over there.
@ianyfan i3 has confirmed it's a bug, so we can go ahead with our changes.
Testing output of i3/swaybar below. "⏎" means the newline char was printed, but not rendered.
printf "XXX" >/tmp/1 and start i3/sway with bar config of status_command tail -f /tmp/1:
| XXX | i3 | sway | sway (this PR) |
|---|---|---|---|
| aaa | aaa | aaa | aaa |
| aaa\n | aaa | aaa | aaa |
| aaa\nbbb | aaa bbb |
aaa⏎bbb | bbb |
| aaa\nbbb\n | aaa bbb |
aaa⏎bbb | bbb |
| aaa\nbbb\n\n | todo | aaa⏎bbb⏎ | bbb |
| aaa\nbbb\n\n\n | todo | aaa⏎bbb⏎⏎ | bbb |
printf "XXX" >>/tmp/1 after i3/swaybar is already running:
| XXX | i3 | sway | sway (this PR) |
|---|---|---|---|
| aaa | aaa | aaa | aaa |
| aaa\n | aaa |
aaa | aaa |
| aaa\nbbb | aaa bbb |
bbb | bbb |
| aaa\nbbb\n | aaa bbb |
bbb | bbb |
| aaa\nbbb\n\n | todo | (blank) | (blank) |
| aaa\nbbb\n\n\n | todo | (blank) | (blank) |
I think I'll need to modify the behaviour of the code around getline to deal with multiple newline characters, then this should be complete.
I'd prefer to get changes merged into i3 first so that its behaviour can be confirmed (I think we can afford to wait since this seems to be fairly low priority).
Also: could you see what the intended behaviour is if you first send an incomplete line and then complete it later? e.g. if you send aaa followed by bbb\n should it complete the line (show aaabbb) or start a new line (show bbb)
Thanks.
Good points. Code should be more or less the same so I'll take it over to i3 first.
Closing as don't have time to work on this
Feel free to pick it up