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=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 10845 invoked from network); 18 May 2020 06:14:57 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 18 May 2020 06:14:57 -0000 Received: (qmail 23470 invoked by alias); 18 May 2020 06:14:47 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45840 Received: (qmail 9917 invoked by uid 1010); 18 May 2020 06:14:47 -0000 X-Qmail-Scanner-Diagnostics: from relay12.mail.gandi.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.3/25814. spamassassin: 3.4.4. Clear:RC:0(217.70.178.232):SA:0(-2.6/5.0):. Processed in 3.95424 secs); 18 May 2020 06:14:47 -0000 X-Envelope-From: stephane@chazelas.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _nblcust.gandi.net designates 217.70.178.232 as permitted sender) Date: Mon, 18 May 2020 07:14:04 +0100 From: Stephane Chazelas To: Mikael Magnusson Cc: Zsh hackers list Subject: Re: [PATCHv2] [doc] clone module using xterm's slave mode Message-ID: <20200518061404.qmtd4gy4m2zi26m3@chazelas.org> Mail-Followup-To: Mikael Magnusson , Zsh hackers list References: <20200517101347.g7v6k2g7hoew636q@chazelas.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 2020-05-17 22:19:24 +0200, Mikael Magnusson: [...] > > +started, we make it read the X11 Window ID that tt(xterm) oututs there > > outputs [...] Sorry about that. v2: diff --git a/Doc/Zsh/mod_clone.yo b/Doc/Zsh/mod_clone.yo index 02dc5be0e..634a8b106 100644 --- a/Doc/Zsh/mod_clone.yo +++ b/Doc/Zsh/mod_clone.yo @@ -20,7 +20,7 @@ and non-zero on error. The target of tt(clone) should be an unused terminal, such as an unused virtual console or a virtual terminal created by -example(xterm -e sh -c 'trap : INT QUIT TSTP; tty; +example(xterm -e sh -c 'trap "" INT QUIT TSTP; tty; while :; do sleep 100000000; done') Some words of explanation are warranted about this long xterm command @@ -39,11 +39,30 @@ enditemize() This does not apply when cloning to an em(unused) vc. -Cloning to a used (and unprepared) terminal will result in two -processes reading simultaneously from the same terminal, with -input bytes going randomly to either process. +It is possible however to clone zsh onto a xterm and that zsh process +to lead the session attached to that terminal by using tt(xterm)'s slave +mode in conjunction with an utility like tt(socat) that can create a +pseudo-terminal pair: -tt(clone) is mostly useful as a shell built-in replacement for -openvt. +example(socat pty,link=pty,wait-slave,echo=0 'exec:xterm -Spty/3,nofork,fdout=3,fdin=3' & + clone pty; (($!)) || { IFS= read -r WINDOWID && ((WINDOWID = 0x$WINDOWID));}) + +Above, tt(socat) creates a pseudo terminal, and makes a tt(pty) symbolic +link to the slave device in the current directory. As soon as a process +opens that device, tt(xterm) is started with its file descriptor 3 +connected to the master side. + +The cloned zsh is the process that opens that device here. And once +started, we make it read the X11 Window ID that tt(xterm) outputs there +into tt($WINDOWID) (the same variable that xterm sets itself when not in +slave mode) before resuming normal operation. That zsh process becomes +the session leader attached to the tty device in the same way a zsh +started with tt(xterm -e zsh) would, and job control works as it should. + +Cloning to a used (and unprepared) terminal will result in two processes +reading simultaneously from the same terminal, with input bytes going +randomly to either process. + +tt(clone) is mostly useful as a shell built-in replacement for openvt. ) enditem()