From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 18683 invoked from network); 11 Feb 2022 15:54:57 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 11 Feb 2022 15:54:57 -0000 Received: (qmail 9301 invoked by uid 550); 11 Feb 2022 15:54:55 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 9263 invoked from network); 11 Feb 2022 15:54:54 -0000 Date: Fri, 11 Feb 2022 10:54:41 -0500 From: Rich Felker To: Yuri Kanivetsky Cc: musl@lists.openwall.com Message-ID: <20220211155441.GG7074@brightrain.aerifal.cx> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] What determines the TERM variable value? On Fri, Feb 11, 2022 at 03:30:32PM +0200, Yuri Kanivetsky wrote: > Hi, > > I was told recently that I can set TERM to any value inside a docker > container, which is, sort of, at odds with my understanding. > > And my understanding is as follows. When a program creates a > pseudoterminal (a pty master/slave pair), it sort of becomes a > terminal emulator. I guess, it can decide not to process any escape > sequences in which case the pair is probably not much different from > an ordinary pipe. And basically what sequences it decides to process > determines the TERM variable value. No, creating the pty pair does not make you a terminal emulator any more than a modem or null modem cable is a terminal emulator. The pty is just a data channel with kernel support for certain types of data translation/interpretation and very basic line buffering and editing (if enabled). This layer has nothing to do with terminal semantics. > I can separate such programs into 2 categories: > > * Terminal emulators (xterm, urxvt, ...). They receive input, process > escape sequences, and draw the result in a window. They can invent > their own language (escape sequences), but it's probably best to have > some terminal as a base. > > * The rest (docker, ssh, tmux, screen, ...). They receive input, > translate escape sequences to the language of the process up the chain > (by using the TERM variable and the terminfo database), and pass the > result to stdout (text, optionally with translated escape sequences). tmux and screen *are* terminal emulators who use *another terminal* (the one they're attached to) as a presentation layer for showing what's on the terminals (one for each window) they're emulating internally. They're not just data channel carriers. > So, generally you have a chain of processes connected via > pseudoterminals (a pty master/slave pairs). E.g. xterm <-> ssh <-> > tmux <-> docker. > > Also, you can't set TERM to an arbitrary value. Each program that > creates a pseudoterminal supports a fixed set of values. E.g. the tmux > documentation says: > > > For tmux to work correctly, this must be set to screen, tmux or a derivative of them. > > https://man.archlinux.org/man/community/tmux/tmux.1.en > > Is my understanding correct? > > Also, I have a pretty vague understanding of what the TERM variable > affects. Can you give some examples? Or categorize things in some way? > Is it only about escape sequences? Pretty much, yes. The TERM environment variable simply tells the program you're invoking what dialect of terminal escapes to use (normally found by looking it up in the terminfo/termcap database) and what to expect as input when different special keys are pressed. It's informing the application of the contract you want it to honor with whatever is on the other side of the tty channel. Rich