9️⃣ Here's the 9th post highlighting key new features of the upcoming v258 release of systemd. #systemd258
Most Linux folks probably spend much of their day in their terminal emulator. Such emulators ultimately reimplement in software what dedicated hardware terminals did in the 1980's and before. While the protocol terminals speak didn't change much in its most basic concepts, various extensions have been added over the years to integrate terminal emulators better with the windowing…
…environment they nowadays run on. For example, early on terminal emulators provided controls to change the window title, and since a long time most shell configurations make use of that to show the user name or hostname in the window title.
More recently added where controls that allow interactive shells that run in terminals (e.g. bash or zsh) to tell terminal emulators when a prompt begins, when it ends and what command it is about to execute.
I think such integration between terminal emulators and the programs, sessions, and infrastructure that runs within them is truly useful, in order to enhance the user experience for an otherwise conceptually quite limited UI concept.
With systemd v258 we added support for a new terminal control (people usually call these "ansi sequences", though a major part of the ones people actually use are definitely not an ANSI standard) that allows communicating a *lot* more meta information…
…from terminal payload to terminal emulator: we came up with a new "ansi" sequence that can be used to define and maintain a stack of *contexts* that tell emulators about what is going on inside the terminal.
What does "context" mean in the above? A context in this sense is basically the runtime of a specific program taking over the terminal's tty device. i.e. typically in a terminal emulator you start out with an interactive shell, that's already your first context.
You then invoke some shell tool, let's say "ls". That's your second context. The tool then exits, now the second context is closed you are back at the first shell context. Now you ssh to some other host. That's a new second context. On that other host you invoke "run0" (or "sudo -s" if you must), that's a third context, from which you then invoke "echo", that's your fourth, and so on.
Each of these invoked tools might output a thing or two onto the terminal. Or, to turn this around:
each character cell on your terminal that has been written to, conceptually can be associated with a context from which it was initialized.
The new ansi sequence informs the terminal emulator about contexts as they are opened, or closed. And most importantly, the sequence allows attaching various bits of meta information to each context: which host they have been created by, what kind of context they are (i.e. shell, remote shell, privilege upgrade, and so on), which user ID they belong to, …
…, which service, which cgroup, which container, …. Moreover, metadata can be updated for running contexts, and when closing them. For example when a program invoked from a shell starts among the metadata reported to the emulators is the command lone invoked, but when the program ends the exit status of the command can be attached too.
What is this all good for? Well, that's ultimately up for the terminal emulator developers to decide. Here are some ideas though:
@pid_eins Nice! Regarding hashed colours, https://www.mavit.org.uk/termcolours/ exists for people who want this today. It’ll certainly be neater to be able to do it in the terminal emulator, without trying to individually hook/wrap everything that might change the context, though.