News for hackers. Stuff that matters.
Re:Zsh and Fish’s simple but clever trick for highlighting m... by dahfizz on Sunday June 14, 2020 @04:41PM (#23521155)
Out of curiosity, I installed fish and set my prompt to be blank[1]. Based on this article, I would expect to see the missing line feed character as the first character on the line after every command, but I didn't. Do you know why?

[1] My `fish_prompt` function just does `echo -n ''`. I also tried `true` and an empty function body, I don't know much about fish scripting.

Re:Zsh and Fish’s simple but clever trick for highlighting m... by ComputerGuru on Sunday June 14, 2020 @11:05PM (#23523383)
Nice catch and great show of initiative there! It's actually not overwritten by the prompt but rather by the "hack"/post-execution handler itself, depending on where the glyph was emitted (which in turn depends on if the command output included a trailing \n or not) when the line is cleared after guaranteeing we're at col 0 of the next line. If the glyph wrapped to this line, then it would be cleared. If it didn't, it'll show on the line above.

I think the missing clue is that the hack is followed by `^[[K` (clear line from the cursor to the right), before control is passed to `fish_prompt` to paint the prompt or whatever else.

Here's some sample output (stripped of the hack spaces and any ansii escapes):

     mqudsi@ZBOOK /m/c/U/mqudsi> echo -n hello
     hello¶
     mqudsi@ZBOOK /m/c/U/mqudsi>
`fish_prompt` isn't called until the cursor is already at column 0 and the line is clear; the "missing line ending glyph" (here ¶ rather than ⏎ because fish correctly detected that the latter is likely not supported by the font used by my terminal emulator in yet another hack) is emitted at the end of the previous line.

You can see all this and more by piping the output of a `fish --interactive` session to `xxd -C` or `hexyl` or whatever (that'll disable tty feature detection and force ansii escapes to be emitted that you can then inspect).`

(You can also verify by simply using `sleep 1` as your fish_prompt - you'd expect to see the glyph appear at least while the `sleep` was running if fish were waiting on/expecting the prompt to overwrite the glyph.)

Re:Zsh and Fish’s simple but clever trick for highlighting m... by koala_man on Sunday June 14, 2020 @11:35PM (#23523520)
I did indeed skip some details in the article. In the case of Zsh, the output actually ends with `\r \r` which is probably meant to handle this exact case by having a space overwrite any marker in case the prompt doesn't.
Re:Zsh and Fish’s simple but clever trick for highlighting m... by ComputerGuru on Monday June 15, 2020 @12:10AM (#23523713)
Ah, I couldn't remember what it was that we did differently from zsh, but I knew there was something.

I would imagine - depending on the terminal emulator - the zsh behavior would cause copy-paste-cruft in the form of trailing whitespace while appearing correct, and would guess this was why we changed our implementation.

Re:Zsh and Fish’s simple but clever trick for highlighting m... by hauleth on Sunday June 14, 2020 @05:30PM (#23521564)
I assume that there is control character after carriage return that deletes everything from there to the EOL, so this do not break copy functionality or "go to EOL" shortcuts.
Re:Zsh and Fish’s simple but clever trick for highlighting m... by ComputerGuru on Sunday June 14, 2020 @11:12PM (#23523422)
Oh, I just saw your reply after posting my own, though you beat me to it by quite some margin of time. That's correct, fish sends ^[[K to clear to the EOL after correctly setting the cursor position via this hack to erase any evidence of the hack and for posterity of your ptty contents.
Re:Zsh and Fish’s simple but clever trick for highlighting m... by JdeBP on Monday June 15, 2020 @04:10PM (#23532382)
Beware of using EL when the inverse video attribute is on.

* https://unix.stackexchange.com/a/586458/5132

Re:Zsh and Fish’s simple but clever trick for highlighting m... by ComputerGuru on Monday June 15, 2020 @09:49PM (#23535150)
Fantastic rabbit hole to dive into, thanks for linking!

The "good news" is that you can't even use tput rev under fish because it saves and restores attributes each time it regains control of the tty with very few exceptions , rev not being one of them. You can't break what you don't even support!

(Seriously though, we should add rev support.)

EDIT: I just saw that you're the same person that answered that post, which very much deserved the upvote. Your knowledge of tty behavior is impressive. It is also rare to find another person that cares about the kvt - a lot of apps that manipulate terminal attributes or use any vte codes are completely broken under even the well-written kernel virtual terminals.

Re:Zsh and Fish’s simple but clever trick for highlighting m... by JdeBP on Tuesday June 16, 2020 @12:08PM (#23540804)
If you want another rabbit hole with respect to supporting attributes, consider that the Windows Terminal people are considering adding ECMA-48 standards conformance that no other terminal emulator has, the various graphic renditions from ECMA-48:1991 that no-one else has implemented in 30 years. (I saw the issue and added overline, framed, and encircled to my terminal emulator's framebuffer front-end. It will be in version 1.41 of the toolset, but that is not out yet.)

* https://github.com/microsoft/terminal/issues/6000

* https://github.com/microsoft/terminal/issues/6205

It brought me up short to be described as caring about KVTs. (-: I've mooted doing VTs in application mode code for a couple of decades, now. Here's a white paper from 2006, which was several years in.

* http://jdebp.uk./Proposals/linux-console-daemon.html

I must update that test script for Windows Terminal.

Re:Zsh and Fish’s simple but clever trick for highlighting m... by CGamesPlay on Sunday June 14, 2020 @10:03PM (#23523138)
I believe you are misunderstanding. The feature ensures that your (empty) prompt is printed at the start of a line, even if the preceding command's output doesn't end with a newline.

Start up fish and run `echo -n foo` to see `foo⏎` in your terminal.

Re:Zsh and Fish’s simple but clever trick for highlighting m... by dahfizz on Sunday June 14, 2020 @10:09PM (#23523156)
My understanding is that the ⏎ character (and some whitespace) is printed unconditionally, but is overwritten by my prompt if the previous command ended with a newline.

If there is no prompt to overwrite the ⏎, why can I not see it?

Re:Zsh and Fish’s simple but clever trick for highlighting m... by ComputerGuru on Sunday June 14, 2020 @11:09PM (#23523405)
That would actually not be OK because we can't count on the prompt to overwrite n characters, and the resulting cruft would give you an incorrect representation of the output if you captured a snapshot of the terminal state (or tried to copy and select). Fish clears the line itself after finding itself at col 0 of the correct row. See my other response for more.