Better HN
topnewbestaskshowjobs
Log inSign up

ComputerGuru

32,405 karma · joined Jan 3, 2008 (18y ago) · 8,297 submissions

mqudsi on most sites.
Submissions

comment 6y ago · link · parent

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.

comment 6y ago · link · parent

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.

comment 6y ago · link · parent

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.

comment 6y ago · link · parent

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.

comment 6y ago · link · parent

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

comment 6y ago · link · parent

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!

comment 6y ago · link · parent

Yup. Fish checks both and acts accordingly, but they're kind of useless because `xn` could mean anything.

The real problem is I'm not sure when the last boolean capability was added to the termcap standard. While new terminals continue to add and update their termcaps, the spec itself is missing a lot of features that would help enormously.

comment 6y ago · link · parent

Thanks for the post! These things absolutely should be documented and dissected in posts like your; there’s way too much voodoo in dealing with terminals.

comment 6y ago · link · parent

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

comment 6y ago · link · parent

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

comment 6y ago · link · parent

It depends if you make it bigger or smaller and if the line break was missing or not. Under some combinations of those two parameters, previous lines overflow with white space.

comment 6y ago · link · parent

One of the fish devs here. I definitely didn’t come up with this hack but I’ve worked on improving some edge cases in the past. Our implementation differs from zsh some although I think we’d originally adopted their approach.

This feature is still surprisingly complicated with many caveats. For example, some terminals will wrap to the next line if you are at $COLUMNS, some at $COLUMNS+1, and some not at all. Some advertise they do one thing and do another. If you miscalculate, you’ll end up skipping an extra line or none at all, maybe overwriting existing output or emitting the missing line break glyph when it should be hidden. We’ve ironed out most of the cases but every once in a while someone will be running an esoteric Pseudo tty (usually not under X) and run into issues.

There are also issues with selection of content. Some terminal emulators will bug out when you try to copy-and-paste content because they get lost with the output past the current location in cases where a line break was already emitted. It’s always the terminal emulator that’s broken but you’d be surprised at how broken some of the most popular emulators are. The entire codebase is littered with workarounds for tty emulators; if someone comes to you and says “fish doesn’t work in $terminal but bash does” (either because it’s minimalistic and is missing a feature that would cause the breakage or because it has a workaround), we almost always end up treating it as a fish bug unless we’re able to get it fixed in the upstream terminal package/OS/software/whatever, whom we file reports with all the time.

It’s insane the configurations and platforms people use shells under and I’m personally deeply appreciative of everyone that takes the time to file these bugs - in addition to making the software better it really does shed light on some extremely archaic bits of posix standards and Unix behavior and I’ve learned so much from the many deep-dives that start off with “this is kind of quirky behavior observed under certain circumstances” and ends up requiring architectural changes deep within because some underlying assumption doesn’t hold universally true as exemplified by a *nix that hasn’t seen a new user in fifteen years or something. It’s why I love hacking on fish; I must have one of the craziest collection of virtual machines to test edge cases, as do many of the other devs (especially @zanchey and @faho, although no one does a deep dive like @ridiculousfish).

comment 6y ago · link · parent

I wrote/donated the code for the original integration with the Windows bootloader for the non-Uefi version. It must have been almost ten years ago, it was even distributed on the official Ubuntu install cd. I didn’t know the project was still around.

comment 6y ago · link · parent

I too have been there, done that when it comes to persistent storage, but my similar conclusion is “use SQLite unless it really, really doesn’t fit, in which case, use PostgreSQL.” (It’s usually easy to figure out which of the two you’ll end up needing.)

comment 6y ago · link · parent

And if you’re the only one offering said service?...

comment 6y ago · link · parent

How is staying out of this altogether “compromising their principles?”

comment 6y ago · link · parent

That’s a reply to an argument for abolishing BitTorrent, and not on-topic. What the Archive did is obviate the need to even pirate: everyone could get content “for free” from a legal entity operating under US laws and subsuming all liabilities.

Suddenly you can get your book for free without even the legal or ethical hazards.

comment 6y ago · link · parent

Putting aside the obvious “not if there is a clear and agreed upon plan for naming their replacements,” there is actually a very different last resort for organizations (typically non-profits) that are deemed to be in service of the community (even if just as a place of employment but especially when they are furthering a mission) where the courts are granted custody of the non-profit and appoint a respected member of the community to maintain core operations as they oversee the process of creating a new board of directors, possibly by setting up elections, creating a committee to establish new governing bylaws, etc so that the good a non-profit has been doing isn’t wholly undone by the dissolution of its governing body.

comment 6y ago · link · parent

No. A board that collectively shirks its responsibilities to the stakeholders needs to be replaced. It’s not like no one could have predicted this was a possibility- and even their board did too, but they gambled that it was worth it.

What that tells you is that their board does not place the sustainability and long-term availability of the archive over all other metrics and I think that’s a fundamental issue that can’t be corrected. If growth, popularity, increasing in scope, etc are more important to the archive’s board than the guaranteed existence of the content they’ve curated ten, twenty, or a hundred years from now then they are not worthy protectors of it. The archive’s worth isn’t the data they have today, it’s the fact that they promised to safekeep it for the years to come. If they can’t be trusted to do that and place that over everything else, then they are failing what the whole world has been sharing data and making donations in the name of.

comment 6y ago · link · parent

That’s not a very believable scenario. First, the precedent is not worth much as all it would say is when all libraries in the whole country are closed, they can give away books for free - how often do you see that happening? Second, that’s not how precedent is established: typically a single case is hand-picked to serve as the exception to the rule taking great care to make it as palatable, appealing, and free of recriminations as possible and you take that to the courts. You don’t make available millions of books to billions of people, you make available a book or a hundred books or whatever number that it takes to prove your point without making matters worse for you and opening you up to such a massive liability. Third, you are making my point for me: again, some other website or organization should gamble their entire existence that isn’t worth as much as the Archive to get this precedent: whatever the reason, it’s a massive and hugely irresponsible gamble.

It’s not like the Archive doesn’t know what kind of people they are dealing with. They know publishers are out to stop second hand sales, ebook lending, right of resellers to set prices, and a million other things. It’s like expecting the RIAA or the MPAA to settle for an injunction when they have the chance to kill Napster/TPB/IsoTorrent/whatever. If it’s really in order to set a precedent then that’s damn short-sighted.

comment 6y ago · link · parent

I warned about this very outcome when they announced the initiative [0]. The Internet Archive is too big and too important to gamble on this short term of a win (giving everyone free and unlimited access to all books for a few months at most). Assuming the organization continues to exist after this ordeal, their entire board should step down for putting at risk one of the most invaluable archives in existence.

I’m an executive board member for a much smaller IRL non-profit and could never imagine opening us up to such liabilities. I honestly cannot fathom how this came to pass.

[0]: https://news.ycombinator.com/item?id=22732640

comment 6y ago · link · parent

Hey, thanks. I've done all those things but tbh the name predates all that. I was an op in a tech support irc channel in the 90s/00s and that was the name I'd picked at the time (I was not comfortable with tying my ID to myself IRL but perhaps even moreso, I was also very sensitive about being pretty much the only minority on all the user groups and mailing lists I frequented. The "guru" half of the moniker was somewhat an homage to being a minority, although I'm not Indian).

I messaged the HN mods many years ago (either pg or dang, can't remember) when things had changed and I had decided to just use my real name online but was told that it would not be possible to change it for posterity purposes.

comment 6y ago · link · parent

I was specifically asking because I’d never heard of a robots.txt solution for blocking snippets. None of the responses have included that information.

comment 6y ago · link · parent

How?

Edit: thanks. I see Google makes it really hard to opt out of featured snippet while retaining regular search result snippet support.

comment 6y ago · link · parent

> It has a very rich standard library

Yet I still have to define startsWith() and endsWith() any time I touch PHP code...

(More importantly, PHP is the one language I can never write from memory without referencing the manual for each and every function call because of how inconsistent it is. Eg Sometimes $haystack is the first parameter and sometimes it is $needle.)

comment 6y ago · link · parent

You can do SQLite in the browser but it’ll have to download the entire dB file instead of only opening the pages it needs (because the naive JS port can’t convert page requests to range requests).

comment 6y ago · link · parent

exa completely breaks ls arguments/switches and as such is a hard pass for me.

comment 6y ago · link · parent

I have no problems using LSPs for C/C++ (via clangs), rust (rust-analyzer), Python (pyls), JS/TypeScript, CSS, bash, and more in Vim (Well, NeoVim) with the autozimu language client.
1
121122123
277