![]() |
|
![]() |
| > you can use `stty` to change a lot of stuff about the terminal, including how it deals with inputs
> You can rewire all of these defaults and behaviors I've also found this article on implementing a terminal text editor to be illuminating: https://viewsourcecode.org/snaptoken/kilo/ https://viewsourcecode.org/snaptoken/kilo/02.enteringRawMode... Also, just in case anyone is wondering, as I once did, where many of these magical-looking stty parameters and symbols are coming from: they are control sequences defined a long time ago. A lot of stuff is defined in ambiguous old standards from the 70s such as ECMA-48 that include such arcane terminology not seen anywhere else. For example, jargon like Select Graphic Rendition basically refers to a 70s version of the HTML tag.
Where params are something like 38/2 RGB to set foreground color. The parameter 0 clears the current style.
Parameters come before the command. Kind of backwards.They even had the same implementation issues we have today with browsers. Terminals were and stil are inconsistent in what they implemented and how they did it. Stuff like colors is pretty well supported but many other features aren't. For example, SGR<7> is supposed to enable "negative image" mode, whatever that is. Standard doesn't really explain. Some terminals choose to do reverse video, other terminals do other equally valid things and to this day people have problems with it. |
![]() |
| That's pretty cool, gonna steal the idea.
I can implement that specific case with a couple of lines in zsh. Something like:
Then icommit, via zed¹, will initiate an inline editor with all the power of ZLE available. Hit C-x C-w to write and commit, or C-c to abort. Obviously, you'd want some error checking and the like².Beauty of this basic implementation is that the keymap is fully controllable in zed as it is simply a new ZLE widget. It works with emacs or vi mode out of the box, and is fully customisable beyond that. You could make the interface generic by writing your own ZLE widget, so that it can be called directly from within the line editor and remove the need for wrapping commands like I did above. ¹ https://github.com/zsh-users/zsh/blob/master/Functions/Misc/... ² This at least uses, and cleans up, a temp file to handle the commit message so it isn't completely useless. |
![]() |
| In bash, if you set $EDITOR to your favorite text editor, you can send the current line to $EDITOR with ctrl-x ctrl-e. After editing the command you can save and exit for the command to execute. |
![]() |
| i don't even know where they are without looking at the keyboard. then when i try to press them half the time i accidentally press insert or print-screen instead |
![]() |
| To be clear, it's not the terminal emulator (xterm, mintty, iTerm2, etc.) that does this. It's the tty layer. You can use the stty command to change the settings. |
![]() |
| > some programs (the dash shell, cat, nc, git commit --interactive, etc) don’t support using arrow keys at all.
The dash shell does in fact support an editing mode if compiled with libedit. Debian derivatives do not do so (likely for concerns of space). They very much should, as people who start with bash will have much to unlearn. The POSIX standard also specifies "set -o vi" as an optional extension. Every shell claiming POSIX-compatibility must support set -o vi if the shell implements this editing mode (so ignore inputrc if it pleases you). "[set -o] vi: Allow shell command line editing using the built-in vi editor. Enabling vi mode shall disable any other command line editing mode provided as an implementation extension." https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V... |
![]() |
| Exactly, there was no other, complicated interface. Except in 1991-1995 when System 6 was going to merge with AIX and be A/UX and Apple was going to merge with IBM and it was all briefly very weird. |
![]() |
| Doesn't Windows, the most popular OS out there, have a cmd.exe terminal thing? Why isn't that harming Windows?
The Windows Command Prompt's default experience is worse than most if not all terminals you find on Linux systems. Even in play TTY, you're bound to find that the shortcuts the author mentioned work like a charm. To make my cmd.exe bearable I am using https://chrisant996.github.io/clink tl;dr You're comparing the choice of wheels on a plane to what makes planes sell more. |
![]() |
| > Doesn't Windows, the most popular OS out there, have a cmd.exe terminal thing? Why isn't that harming Windows?
That's because the overwhelming majority of Windows usage, administration, and programming can be done almost entirely without ever touching the command-line, from Explorer.exe, Task Manager, Edge, Media Player, Paint, and built-in ZIP handling to the huge list of MMC snap-ins[1], and Visual Studio 2022. > tl;dr You're comparing the choice of wheels on a plane to what makes planes sell more. For the record, aeroplane cockpits have also gotten considerably simpler in the intervening half-century since Concorde and the first 747s. Here is an Airbus A350 cockpit[2]. [1]: https://serverfault.com/questions/158075/what-are-the-names-... [2]: https://cdn.airplane-pictures.net/images/uploaded-images/201... |
![]() |
| if you have a problem with gnu/linux (as opposed to android) you can usually find the solution on stack overflow, server fault, or superuser, but the solution you find there is going to be a textual command line, not a gui. gpt-4 can tell you how to solve the problem, but only using a textual command line, not a gui. text is the most powerful, useful, effective communication technology ever, period. always bet on text: https://graydon2.dreamwidth.org/193447.html
https://news.ycombinator.com/item?id=40909185 documents that this is actually also true for microsoft windows on the other hand, 'always bet on text' doesn't mean 'always bet on editing your command line with inconsistent control-character commands in a mode where clicking with the mouse doesn't do anything' |
![]() |
| as i said in my other comment at https://news.ycombinator.com/item?id=40912296, text really helps a lot with constraining accidents
obtaining networking and operating systems knowledge includes as an essential part using software like ip and top (though try htop instead). it's not a strict sequencing but a back-and-forth interplay, synergistic with factors like study and mentorship as for poetry, there are plenty of clis that aren't very expressive—rt-11, cp/m, grub, ms-dos, and mpv come to mind—and plenty of guis that are very expressive, such as godot, blender, inkscape, labview, solidworks, freecad, and sieuferd. you can write your own poetry as easily in godot as in bash |
![]() |
| Likely an unpopular take, but I switched to the "Natural text editing" preset in iTerm2 to get editing shortcuts that match the traditional macOS ones. It has the advantage of just remapping to the normal control sequences inside terminal apps, so you basically get this functionality everywhere without needed to change it in multiple places/worry about readline support/etc. It isn't perfect (I have rarely needed to enter sequences manually that then are remapped), but I find I have used way more command editing since its part of my muscle memory.
https://pliszko.com/blog/post/2021-10-31-natural-text-editin... |
![]() |
| Oh I always do ctrl+shift+r for that last bit, like reverse-tabbing on a gui. Good to know about ctrl+s, though I imagine muscle memory will prevent me for ever using it. :) |
![]() |
| Idk, but I can guess. In windows terminal and shell are not so separate as in Unix. For example, is cmd.exe is a terminal or a shell? I believe it is both. Probably it is the same with powershell. |
![]() |
| This is a mistake, but forgivable, as Windows executable launch behavior blurs this distinction.
Just like UNIX shells, cmd and PowerShell are ordinary console programs. The Windows equivalent to xterm and friends — i.e., the mechanism responsible for displaying console I/O in a window — is a bit complicated, has changed over time, and only recently (Windows 10 1809 / Server 2019) adopted a UNIX-like pseudo tty / terminal emulator model. For a good overview of Windows console architecture, past and present, see https://devblogs.microsoft.com/commandline/windows-command-l... |
![]() |
| I think you could achieve this in Wezterm, which is configurable with lua. Not on my laptop right now but will try to get it working later. I have other keybinds that run specific lua functions. |
![]() |
| that doesn't work in terminal emulators because the terminal emulator doesn't know how to delete the selected text in whatever program drew it there (which may no longer even exist) |
![]() |
| I plan to make one day an alternative to terminals. My idea is not fully fleshed out, but I would like to try to forgo TTYs altogether. Use only pipes, file descriptors and job control.
The closest thing I saw to what I have in mind is this: https://github.com/letoram/cat9/ but more in a way of interface. |
![]() |
| Nice to see this writeup. Entering text into the terminal, and copying output out, is a huge barrier to entry for beginners. Windows terminals in particular feel downright antagonistic to use. |
![]() |
| I wonder what terminal that is, because the Home and End keys, which I'm pretty sure are the expected alternatives, work fine in every terminal for me on Linux. |
![]() |
| These defaults are not bad if you use Emacs :) Or if you use macOS that (gasp) supports the very same ^A and ^E shortcuts in all edit controls. |
![]() |
| Another neat trick is to use ctrl-x ctrl-e, this gets the command in a vim buffer (default editor for me). Edit the command and then :wq to reflect the changes |
![]() |
| "The other day I asked what folks on Mastodon find confusing about working in the terminal, and one thing that stood out to me was "editing a command you already typed in".
This really resonated with me: even though entering some text and editing it is a very "basic" task, it took me maybe 15 years of using the terminal every single day to get used to using Ctrl+A to go to the beginning of the line (or Ctrl+E for the end)." Only took me a year or so to get used to using "v" in vi mode and fc. I am not a "developer" but I prefer textmode command line to GUI. I do not use X11/Wayland/etc. I learned sh on NetBSD which I still think is one of the best shells available. It's fast. vi mode is the default. People may disagree but I think for editing single a line of text, i.e., a "command", vi mode offers more precision. For example, being able to jump directly to a particular column number. https://web.archive.org/web/20240528201424if_/https://pubs.o...
IMO, as a dumb computer user who is not a "developer", this is not complicated. I think terminal emulators are complicated, though. I do not use them.I believe fc came to POSIX from ksh. For me, it is not that UNIX is objectively good. It is that the available alternatives are still comparatively bad. |
![]() |
| Periodic reminder that many emacs-like keybindings exist in almost every text field in macOS: Ctrl A, E, P, N, K, Y, T, and probably others I'm forgetting (start of line, end of line, previous line, next line, kill (delete everything to the end of the line and put it in a special pasteboard), yank (paste from that special pasteboard) and transpose characters).
Edit: more complete list here: https://jblevins.org/log/kbd Edit 2: can't believe I forgot Ctrl-D, which is forward delete. |
![]() |
| At this point Google has basically taken over that function... "How do I _ on the command line?" more often than not gives one some starting point to develop from. |
![]() |
| Also worth mention the Plan 9 "fixed prompt" where any command is at the top, with it's output underneath, there are few variants and in few cases they are comfy. |
![]() |
| No, the GPL license for GNU Readline is very intentional. There is a bunch of written history from Richard Stallman about it. He felt it provided such an large advantage, that some programs might switch to GPL to use GNU Readline. After 35 years of development (started in 1989 according to Wiki), it has a hefty start is someone wants to beat it with a "clean room" BSD-licensed edition.
Some HN info about Stallman's reasoning: https://news.ycombinator.com/item?id=26606328 I cannot find any specific writing from him, but I am sure I read words from him about 25 years ago.
Yes, the problem is that commercial organizations would like open source to do all the hard work for them. Then, they use the software internally, and don't give anything back -- except two pence via RedHat licensing. (We have learned this the hard way in the last 10 years of major security bugs due to underfunded projects.) However, you are free to re-implement the API and license it in a different way. |
![]() |
| How can you discover something on the terminal itself? You fall into a pattern and stick with it. It is only if you get out of band information that you can learn these tricks. |
![]() |
| In your first comment, you said it "seems weird" that Julia doesn't like Vi-mode.
In this comment, you quote Julia talking about Emacs-mode. Which doesn't really follow on from your first comment. |
![]() |
| Ah, this reply does indeed make it clearer what you were saying :)
Whether I agree with what you were saying is a different matter (:p) but at least it makes more sense now! |
Here's some stuff that's missing:
Within shell scripts, you can use `stty` to change a lot of stuff about the terminal, including how it deals with inputs. You can rewire all of these defaults and behaviors.
Here's an experiment I did a while ago using sh and stty: https://gist.github.com/alganet/63f1dbc97b8fd35f7bb14ec30f79...
It is able to capture and understand most keyboard combinations and even mouse gestures (hold/drag/drop) from within the shell in any VT100-compatible terminal (mintty, xterm, Terminal.app, vscode, so many others).
Runnable demo:
Run it and press some keys or move the mouse. Use Ctrl+W to exit. It supports zsh and ksh too, but not dash or other shells lacking `read -rn1`.---
Here's another funny thing:
If you pipe an interactive program to `cat -v`, you can see which VT100 escapes that program is using. I learned a lot from how vi does it.