News for hackers. Stuff that matters.
Re:Zsh and Fish’s simple but clever trick for highlighting m... by teddyh on Sunday June 14, 2020 @03:49PM (#23520746)
Why output spaces when “tput el” works?
Re:Zsh and Fish’s simple but clever trick for highlighting m... by ComputerGuru on Sunday June 14, 2020 @04:03PM (#23520841)
We wouldn’t run an external command because of the overhead, compatibility, and portability, but I’ll treat your question as “why not do what tput el would do?”

It all depends on where the input cursor is when the command terminated. You need something that works with both cases (line break and no line break) because you can’t introspect the output.

tput el clears the output to the end of line so you still have to figure out if you’re on the same line as the output or if you’re on a new line. The goal of spaces is not to clear content but to invoke the wrapping behavior of the terminal which will either cause you to be on the same line only in the case that you started off at col 0 or else somewhere in the middle of the next line, but in both cases, you’re on the row you need to be on (after taking into account whether wrapping happens at max column or max column plus one).

Edit: It’s actually a lot like rounding by adding 0.5 and truncating. And the complexities are akin to trying to do it with non-standardized or different standards of doubles and dealing with epsilon and NaN :D

Re:Zsh and Fish’s simple but clever trick for highlighting m... by teddyh on Sunday June 14, 2020 @04:07PM (#23520861)
Yeah, I get it now; for some reason I completely misunderstood the intended effect of the spaces.
Re:Zsh and Fish’s simple but clever trick for highlighting m... by ComputerGuru on Sunday June 14, 2020 @04:10PM (#23520890)
No worries! (Now try figuring out what it does and why it does it from the code that you found spread out over a few hundred lines of C interspersed with curses calls and no comments.)
Re:Zsh and Fish’s simple but clever trick for highlighting m... by teddyh on Sunday June 14, 2020 @04:35PM (#23521100)
If I understand it correctly, if a terminal had the “bw” attribute, you could simply do

PROMPT_COMMAND='echo -n %;tput cub1; tput cub1; tput cud1; echo -ne \\r'

But the “bw” attribute does not seem to be common, so I guess the trick with spaces is usually necessary.

Re:Zsh and Fish’s simple but clever trick for highlighting m... by ComputerGuru on Sunday June 14, 2020 @10:29PM (#23523232)
I would think so?

Not directly in fish, because we manually set the tty flags and restore them after each execution (it's why your fish prompt doesn't break when you ^C in the middle of a redirect or when you accidentally output binary to the terminal), but e.g. in bash or if fish were to emit those escape codes directly. But yeah, it definitely seems like a good hack and it would cut down on the bandwidth requirements (you can notice the lag when using fish/zsh over ssh on a lossy connection).

Note that depending on the xn attribute, \r may or may not end up taking you to col 0 of the same row, depending on if the previous output caused a soft wrap but didn't include the trailing new line - you could wind up at col 0 of the previous row instead, if I'm reading it correctly!

Re:Zsh and Fish’s simple but clever trick for highlighting m... by ComputerGuru on Monday June 15, 2020 @02:03AM (#23524255)
Errr, you can disregard that bit about it not working in fish. This has nothing to do with flags/modes and would be very basic ansi escapes.
Re:Zsh and Fish’s simple but clever trick for highlighting m... by minitech on Sunday June 14, 2020 @03:57PM (#23520812)
The goal is to get a new line only when not currently at the start of a line, so the number of spaces doesn’t depend on where the cursor is.
Re:Zsh and Fish’s simple but clever trick for highlighting m... by teddyh on Sunday June 14, 2020 @04:05PM (#23520851)
Oh, right; I somehow completely missed the wraparound effect of the spaces.
Re:Zsh and Fish’s simple but clever trick for highlighting m... by kazinator on Monday June 15, 2020 @11:52AM (#23528735)
Why "tput el", when ANSI/VT100 has won?
Re:Zsh and Fish’s simple but clever trick for highlighting m... by JdeBP on Monday June 15, 2020 @04:05PM (#23532331)
No use of "VT100" to describe what we have today is actually correct.
Re:Zsh and Fish’s simple but clever trick for highlighting m... by kazinator on Tuesday June 16, 2020 @10:22AM (#23539443)
Right, like no use of "Javascript" to describe what we have today is actually correct, that being "ECMAScript", damn it.

Why can't I get everyone to stop saying "Javascript"?

Re:Zsh and Fish’s simple but clever trick for highlighting m... by JdeBP on Tuesday June 16, 2020 @11:50AM (#23540583)
No, not like that. At all, in fact.

This is an XTerm FAQ, and you are not in the analogous situation that you purport to be in. You are abusing "VT100" to describe the current state of affairs in the world; which is most definitely not a DEC VT100, not like a DEC VT100, and most definitely different in many important respects (such as colour, for starters) to a DEC VT100. It's even different to "ANSI" (again, which should be ECMA-48) in that no terminal or terminal emulator (that I know of) actually provides standard function keys (function keys being another thing that a DEC VT100 does not have). A few of them, sort of, provide the non-standard function keys from a VT220, which isn't a VT100 either.

Far from "winning", "ANSI/VT100" was superseded (by things that were better) within a few years, long ago.

* https://invisible-island.net/xterm/xterm.faq.html#what_is_vt...

Re:Zsh and Fish’s simple but clever trick for highlighting m... by teddyh on Monday June 15, 2020 @03:08PM (#23531634)
Won? Was there a war?
Re:Zsh and Fish’s simple but clever trick for highlighting m... by kazinator on Monday June 15, 2020 @04:34PM (#23532636)
So to speak, yes. There was once a competitive marketplace with all sorts of terminals featuring totally different emulations.