Live data from Hacker News

"Rules" that terminal programs follow

jvns.ca

151–153 of 153 posts

Re: "Rules" that terminal programs follow

#151

Other rules for command line tools: 1. Don’t assume a terminal type. Look at `TERM` and use termcap/terminfo or a library built atop them for anything beyond line-oriented plain text output, or least assume a plain teletype unless you specifically recognize the user’s terminal type. 2. Don’t assume the presence of a terminal at all. Check `isatty()` before doing anything fancy, and be sure to work without a terminal…

I've never heard of the `@/path/to/file` convention, nor ever seen anything that documented using or supporting it. Do you have any examples of tools that do use it (maybe I've just never seen it in the documentation)?

It’s called a “response file” and they’re at least common among developer tools like compilers and linkers for avoiding common limits on command line arguments.

Re: "Rules" that terminal programs follow

#152
post #132

Earlier quoted context omitted.

I read up on this and "cooked but character-by-character" is apparently something called "cbreak mode" (or "rare mode").

According to stty(1), ”cbreak” is a negative alias of “icanon”, which simply enables the special functions of the ‘erase’ (backspace), ‘kill’ (Ctrl-U), ‘werase’ (Ctrl-W), and ‘rprnt’ (Ctrl-R) keybindings. “cooked” mode includes “icanon”. So no, I do not think that what you wrote is correct. From what I can tell, the line-by-line mode is “extproc”.

On macOS, running `stty cbreak; tr a-zA-Z A-Za-z` causes `tr` to immediately transform every character as it's typed. If I SSH into a linux box that doesn't work, though I'm wondering if that's SSH's fault (it's not convenient right now to get direct access). Certainly the Linux manpage for stty(1) documents a setting

  min N  with -icanon, set N characters minimum for a completed read
which suggests that if you set -icanon (e.g. cbreak) then reads may complete after 1 character.

Also on macOS the documentation for cbreak is different, it lists a bunch of settings including -icanon, it's Linux that makes it literally an alias for -icanon.

Re: "Rules" that terminal programs follow

#153
post #26

As an addendum to Rule 7, `cd -` takes you to the last opened directory. Or is `cd` considered part of the terminal emulator's job, as a built-in?

I don't think it's part of the terminal emulator (e.g. xterm, gnome-terminal) but the shell (bash, zsh, etc.). You're correct that it's not something that's implemented as an external program though; the "current directory" is state for a currently running terminal session, so changing that state is done via the shell interface (either directly by built-in commands like cd or indirectly via external commands that use…

True, I meant the shell, as `cd` is a shell builtin. However, `git-checkout` does implement this behavior. `git checkout -` will checkout the previously checked out branch.
Post reply on HN