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 autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 21494 invoked from network); 30 Dec 2022 08:59:11 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 30 Dec 2022 08:59:11 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1672390751; b=matyYCMn1eg93Yqdk1a3CyWVnYOEOMW2nxbPyECfohlrYvYKHaJrTT5DLUG4nguz+zQOhdm/iY kPzbgYDkJDWr+2sSh/oylMhA9voOxE/IwO/n7doi+UhR+h9AUSOjoOsS/YRs44vq/gWGZBur4F nqj9cUUJ6lA/dgdAh7rBIoDGEoLsPVmOeGa1JyJWezQxKPyci5GeOUUAkDYbZrDRLnq1iilt4m +RjcpPS5cS0WQBR50cAS+RUc2lDeNBfF7wP5rbMz+C4DNnApWXmRt+asEYFZLRs+1LpGE2B7jw M10A5Mt/Rh7EDiqU6KUP8eQ9Ekdw+b2uttaYKFlB0rEXMw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f43.google.com) smtp.remote-ip=209.85.218.43; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1672390751; bh=Uxk642BIPZHmnOw6oVXripW3fASRRVp+M6R7vMEVATg=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:References: In-Reply-To:MIME-Version:DKIM-Signature:DKIM-Signature; b=AHXHsbJpF8qk02lG7S/R6H6UP+nBA0dAzWXcI7bsxXWT0ZbD76mIG/EsmGJxyTfi0uqsdV+pr5 YayBs2hIa7/Xsdsj8qmR5bzZhBBLvbyY5ZFIcgTu4TQIVzjqnDFxDqe5s9159Fz+iT/HI6JJqi FUMdUeOmafrrbFv0cp+jNw9okqJwB366c3HNGoduMnut38bh0qJqfcEi6Qcsk9TuuMsDaUs4EN 2yC42c25Zp3ug6Sowhx/B9O7nZ8an5WO5iYlRWYhYXWQh7dtKhW0F61pOZfPxUMrTTlNaCdxhM Lt2+z7EeC3AuoyKw8i05OZXRrl6nQEWD0OkA/Kf+hHC9pw==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:References:In-Reply-To:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=gAU9BLBQDKe9JvltDK9TjbNxupEQD5RV0y2ApdK/aUU=; b=DEAr2Dj3eeJfkQYxcavFzEXv7q THzmVUB0buqACQ+mn++77q7UCU7MefnOS79HQWOBPM2usPR11YETt9I7GPULKs2ZsyQG7gjZmUp/B WY0LRjyXY51u8lnKICXPGrFzYN822w5n0FcYsCANjoEF4joN3tkmyQEJp4U8iVq4sszCcAMhlk8Aj 7SeXNDEmN29RlTp8SKKxoYhzW67K3b5tqyQ+zK3WgrKKWDap1tmcLKf/pjFPZMdS3lWZ1AzbR687r sEDGLCEbNwBhBMW8pI3uuwJS6UnPsAkil2FI6RRoYyrM9In5P6BsKvYRNZLOchDrhX+eepruSFvc7 og5+jmmw==; Received: by zero.zsh.org with local id 1pBBEM-000F0V-1N; Fri, 30 Dec 2022 08:59:10 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f43.google.com) smtp.remote-ip=209.85.218.43; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-ej1-f43.google.com ([209.85.218.43]:46873) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1pBBDm-000EgK-RH; Fri, 30 Dec 2022 08:58:35 +0000 Received: by mail-ej1-f43.google.com with SMTP id bj12so50031016ejb.13 for ; Fri, 30 Dec 2022 00:58:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=gAU9BLBQDKe9JvltDK9TjbNxupEQD5RV0y2ApdK/aUU=; b=VxrBwttViI8B0RxBHg2EMNJmffNVyBN6+2a2ia+7KYsWLmUDuOxUA+lN/zcSzg3pQa FtF/DbovKCqSzFPqrIUThGmxPXSuaqopggZcBhZt+uHg/Eu2lEHvcU+3egKq/ePDziAd CJhgC2mg9yAl/7BPklA+mADGwMDaSTDR+tRNJR84Yeg2nwJtyjP23/GoI5iwabtMfVye t7dZltUzt47gVccz1nCBZto4KsaCqv30u7Fr4l4kw+ZEx/nzTkhP1dmuJBLO/CQK9yxP 1hlj1XMLGOICdzRfZ76wLvITYizHzMSEa8jI3i707ci74qMoH0mZg7g+flXuyM690Ef5 CbaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=gAU9BLBQDKe9JvltDK9TjbNxupEQD5RV0y2ApdK/aUU=; b=0HzTERgdwgaUXOlfZOLZEgnwO/5oTZ21027U7ZvLaXyMe2k1dQQAE9KR75UCexg7Hw +J+VGgKfpZ6uyOsilrckNNJevea1iho6xMh55E5PaIW5BKmZA2dCNRpqK8ECaI9psosK bwkKztJ8k1caFVj28a+dDL/pHM8Vd2Q7RAa8kZH0PXTCp4PtRnCwbPKUWwOFBWoU33Vj h6VKKS/VAdzMzkIm1DW1216QLn8qFSR2+0Vxq0E0VjeKfniSB0iXuPOsZFwGk1oqblio Uo8R6dEbYFY47rP+Y7jlPlc5G2k8JvIPrvpjj6sm3PHikvs1UdPwygJHsumGpD+tTR2v R/6w== X-Gm-Message-State: AFqh2koQnLSkwq3CNjfAQJf7JWgDbw4n56Yz/soVaKZ9qOkNF7baWm8S blGC3ss7XtCQekWiAxo9DGjRtjnFw2IZL/Pd/vJk+Nqc X-Google-Smtp-Source: AMrXdXsghnT0+8cb+Q3057y+SXVTzHRzehGyPLaGktBiECHCRVjTme/ErT0pE3wah9oK1Ae5j3FBfTEaLRR6VxO1u/w= X-Received: by 2002:a17:906:5a73:b0:7de:d873:204a with SMTP id my51-20020a1709065a7300b007ded873204amr4183408ejc.422.1672390714206; Fri, 30 Dec 2022 00:58:34 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a17:907:c606:b0:7cd:3b2e:124 with HTTP; Fri, 30 Dec 2022 00:58:33 -0800 (PST) In-Reply-To: References: From: Mikael Magnusson Date: Fri, 30 Dec 2022 09:58:33 +0100 Message-ID: Subject: Re: Read a line from user without clearing screen below the prompt while allowing user to use arrow keys to make edits in middle of line To: OG Code Poet Cc: zsh-workers@zsh.org Content-Type: text/plain; charset="UTF-8" X-Seq: 51260 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On 12/30/22, OG Code Poet wrote: > Using Bash ``tput cup 0 0; read -e -p "Enter input: " userinput`` works > well for getting a line of user input: > > * It does not clear screen below the prompt > * It allows user to use arrow keys to go to middle of line and edit a > mistake they might have made while typing > > How can this be achieved in zsh? I have tried two techniques; either it > clears screen below prompt or it does not allow using arrow to go back to > middle of line to edit it. > > 1. Using ``vared``: > ``` > tput cup 0 0; userinput=""; vared -p "Enter input: " userinput > ``` > ``vared`` seems to clear screen below the prompt, so this clears the entire > screen before showing the prompt. > > 2. Using ``read``: > > ``` > tput cup 0 0; printf "Enter input: "; read -r userinput > ``` > This does not clear the screen below the prompt, but does not allow using > arrow keys to go to middle of the line and make an edit ("delete" key > works, but is too much to ask users to delete and retype everything from > the point of typo). > > Is there a way out? Perhaps it could be possible to trick vared to believe > there are no lines below, so it clears just 1 line (the line of prompt). If > it is not possible in zsh, I am open to an external POSIX way of getting > user input on first line of the screen. > > P.S. Also posted in unix.stackexchange.com: > https://unix.stackexchange.com/q/730022/456507 Without more context this sounds like a very weird request, surely printing stuff at 0,0 will just overlap whatever existing text was there, resulting in a corrupted screen output? Perhaps you will have better luck switching to the alternate screen while prompting for the string, and then switching back, in effect giving you the appearance of a full screen program (more likely to direct the user's attention to the top of the terminal). (enable with echo -n '\e[?47h' and disable with echo -n '\e[?47l') PS this is probably more of a zsh-users question than zsh-workers -- Mikael Magnusson