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.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,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 28046 invoked from network); 12 Feb 2022 09:35:20 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 12 Feb 2022 09:35:20 -0000 Received: (qmail 32137 invoked by uid 550); 12 Feb 2022 09:35:17 -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 32084 invoked from network); 12 Feb 2022 09:35:16 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=eRgiWlR1X4JJCUWwXFTKUYN3UgcfXHOGCq+jL5VLdaU=; b=VW3sX0p1fOUuItkJEYCW31oRmH8WJqnIHhnbW+FdyISpsTuhsM1W9dXXtiw293XAE6 igmDH051mFEkCox7EAJqyxa3by6Xzu26Li7xMflG95Upfu5CsleWHNuQECgQcutcnlOR p26R6QnkhRUdF7cDXhokS242N8Sf7a4NQjNYF/zXIyXCPbODU8ImpsaABzaaz6163Kt7 UvY/qwyO7HiwA4gC6aDxC1firrMNvge8QS0XLiypRoHFT290j+CwqRMTlQZaTCIah0w0 lPBNdRWiGUQ28o1SEutLZzoGBu9htA6JttzI1TyipUZBdAF19eDNjJK+dpZVFapW8MTz 2/WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=eRgiWlR1X4JJCUWwXFTKUYN3UgcfXHOGCq+jL5VLdaU=; b=AnR9bYl7NX4krIqDXZgsBTgqoowuSVBDFvDGvS9cvai01J7oIGgTIi01ypCXjZeltF GASmUaGElaqni12QdZ8ZufDraefwmNjF8I4mnL+pgYmeNryp5K+ATDsUC/lES5hudp7b KC6GbwgJjN5kQtbg2GjF475GViYxmTcjfd72o3Vh/tZmzygatYzdhY2idK61N/HdaAIE 5fT9HSGfM7BTomKT4//JJOl74Uq26/8Ya8N4oJawCnX6pqoCp1p4eHUxphCOT0NUgyOn 7umso1zFl9+OkC83wqU06bWAKQUzsoZC+UNY6khli80sdcNUNpClaCHWr+dVX2xgQvif tPRw== X-Gm-Message-State: AOAM533ZwVGAo8zlpgVim52WS9sgZv5s6bNyBC47Jp1VVYteHVxOHv5s pdKk1Ak3M7NxJOcMxXA27reLNDZDMtIT/PXifA== X-Google-Smtp-Source: ABdhPJy5NYlfLcX2YQ/LMsAdEMSo5GnX/Vw6zPtQjxU1cnmYTm+a3qtMkfNhmkILQghxABzwGKN1Kuu5xCbasqOuKmY= X-Received: by 2002:a63:6a48:: with SMTP id f69mr4345481pgc.521.1644658503893; Sat, 12 Feb 2022 01:35:03 -0800 (PST) MIME-Version: 1.0 References: <20220211155441.GG7074@brightrain.aerifal.cx> In-Reply-To: <20220211155441.GG7074@brightrain.aerifal.cx> From: Yuri Kanivetsky Date: Sat, 12 Feb 2022 11:34:52 +0200 Message-ID: To: Rich Felker Cc: musl@lists.openwall.com Content-Type: text/plain; charset="UTF-8" Subject: Re: [musl] What determines the TERM variable value? So, a program is a terminal emulator if it translates escape sequences in both directions? And if it, as a result, changes the TERM variable? What seems strange to me is that docker changes the TERM variable: $ echo $TERM screen-256color $ docker run --rm -it alpine / # echo $TERM xterm Does that qualify it as a terminal emulator? On Fri, Feb 11, 2022 at 5:54 PM Rich Felker wrote: > > 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