5 ms·
Why output spaces when “tput el” works?
by teddyh 6y ago
Why output spaces when “tput el” works?
- ComputerGuru 6y agoWe 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
- teddyh 6y agoYeah, I get it now; for some reason I completely misunderstood the intended effect of the spaces.
- ComputerGuru 6y agoNo 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.)
- teddyh 6y agoIf 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.
- ComputerGuru 6y agoI 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!
- ComputerGuru 6y agoErrr, 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.
- deleted 6y ago[deleted]
- minitech 6y agoThe 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.
- teddyh 6y agoOh, right; I somehow completely missed the wraparound effect of the spaces.
- kazinator 6y agoWhy "tput el", when ANSI/VT100 has won?
- teddyh 6y agoWon? Was there a war?
- kazinator 6y agoSo to speak, yes. There was once a competitive marketplace with all sorts of terminals featuring totally different emulations.
- JdeBP 6y agoNo use of "VT100" to describe what we have today is actually correct.
- kazinator 6y agoRight, 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"?
- JdeBP 6y agoNo, 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_vt220 https://invisible-island.net/xterm/xterm.faq.html#what_is_vt...