sway icon indicating copy to clipboard operation
sway copied to clipboard

swaybar: only show last status line

Open ammgws opened this issue 5 years ago • 13 comments

Solves #4496

ammgws avatar Mar 14 '20 03:03 ammgws

Have you tested whether this will work if the last line ends with a new-line character?

ianyfan avatar Mar 14 '20 11:03 ianyfan

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.

ammgws avatar Mar 14 '20 11:03 ammgws

I mean: if you send first line\nsecond line\n what does this output?

ianyfan avatar Mar 14 '20 19:03 ianyfan

From memory it would just output a newline, so the status line would be empty. I will check again once #5106 is fixed.

ammgws avatar Mar 15 '20 00:03 ammgws

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...

ammgws avatar Mar 16 '20 16:03 ammgws

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.

ianyfan avatar Mar 17 '20 00:03 ianyfan

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.

FreeFull avatar Mar 17 '20 02:03 FreeFull

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.

ammgws avatar Mar 17 '20 04:03 ammgws

@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)

ammgws avatar Mar 25 '20 14:03 ammgws

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.

ammgws avatar Mar 26 '20 01:03 ammgws

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.

ianyfan avatar Mar 26 '20 10:03 ianyfan

Good points. Code should be more or less the same so I'll take it over to i3 first.

ammgws avatar Mar 26 '20 11:03 ammgws

Closing as don't have time to work on this

Feel free to pick it up

ammgws avatar Nov 06 '20 08:11 ammgws