From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 41C5B1F46C for ; Mon, 13 Jan 2020 08:29:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728847AbgAMI3j (ORCPT ); Mon, 13 Jan 2020 03:29:39 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:46193 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728774AbgAMI3h (ORCPT ); Mon, 13 Jan 2020 03:29:37 -0500 Received: by mail-wr1-f67.google.com with SMTP id z7so7517942wrl.13 for ; Mon, 13 Jan 2020 00:29:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=Pd7gm9sA8KWwnCXzcqZeBD0/pHyKhrgKove5Fa6H3tg=; b=Ohiil9RojRbraFNSJlv4OBUHQLV7lTdYs+qiHaEjlxBavzwpMWNCd67y7qjd9KDt05 cRGhhg9Jb5U8JZLGJ7P6gXw3/oIngn1ZBoqrUy1mZhFnzP0iwLSVrhRFScjex2PlL53i 4iQnkMl1Bfeqw+vk/6bYvK6YIm9F+VGt7k4ojq4EeEjj30LlNh9j3wLqQt9sKy7xkH3T 3iiAvwzAGcwMnfiYDU5u0mQI21KG+3AgK941U4eiwQSrRgx+lVXHvnuqv8hkMP+qAtYc 7yxqyBOJ5nxlaQCa61aMJ/O+bpuclmpOM0im5XvnQYEjRuUgaO3xtsNcR7gD0y/cyNrY IuuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=Pd7gm9sA8KWwnCXzcqZeBD0/pHyKhrgKove5Fa6H3tg=; b=MFWtt2v4bzkVo5g9clYwsUeubyHDSsDocKTLbeO7i1VZKc+vST1VBMCUCOfIdm8aR+ hkyOLoZf7gNrxZLCZEoflKuz499VFSyRMCUrCr0OMge1euW5M/yR+a/vTLs77xwBv04k eA5XoJ+qYzx4MhnlaOJGXhyT+2WP+hlQiZRE7mAgK7g1WOYoi2doL51milFPb8Iy38Ep fZkPWZCwRgdqB946YmbjnoHR/ZbzYXs681+inSi7K7xZHIJcHWkKclZHfdb/+/09WIjD T/KWrobWKI4eYCK5Snw9DhKqchB/2xzeHNOCVF3cLFRAGu7k4bhqqmDQ/O0O/MD4ncDx gIcw== X-Gm-Message-State: APjAAAWXyhlYW6NfMYSzApo4fh+FqzrtjRaoCo59M1g3xOE9udfK6MIP iqt+cEvQcz202geVR/Ct332cI7SZ X-Google-Smtp-Source: APXvYqzveV+Ek+FganPupfUmZxuYkIJ7P7Z0saX/s39CcHb/XqlY58LU1hjOPm4zImgBx+pR3qM9aQ== X-Received: by 2002:adf:f1cb:: with SMTP id z11mr16523783wro.375.1578904176272; Mon, 13 Jan 2020 00:29:36 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l18sm13494753wme.30.2020.01.13.00.29.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2020 00:29:35 -0800 (PST) Message-Id: <233f23791caaca5dee6b227520560f53977c8ea7.1578904171.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Date: Mon, 13 Jan 2020 08:29:26 +0000 Subject: [PATCH v3 05/10] terminal: accommodate Git for Windows' default terminal Fcc: Sent Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin Git for Windows' Git Bash runs in MinTTY by default, which does not have a Win32 Console instance, but uses MSYS2 pseudo terminals instead. This is a problem, as Git for Windows does not want to use the MSYS2 emulation layer for Git itself, and therefore has no direct way to interact with that pseudo terminal. As a workaround, use the `stty` utility (which is included in Git for Windows, and which *is* an MSYS2 program, so it knows how to deal with the pseudo terminal). Note: If Git runs in a regular CMD or PowerShell window, there *is* a regular Win32 Console to work with. This is not a problem for the MSYS2 `stty`: it copes with this scenario just fine. Also note that we introduce support for more bits than would be necessary for a mere `disable_echo()` here, in preparation for the upcoming `enable_non_canonical()` function. Signed-off-by: Johannes Schindelin --- compat/terminal.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/compat/terminal.c b/compat/terminal.c index 1fb40b3a0a..16e9949da1 100644 --- a/compat/terminal.c +++ b/compat/terminal.c @@ -2,6 +2,8 @@ #include "compat/terminal.h" #include "sigchain.h" #include "strbuf.h" +#include "run-command.h" +#include "string-list.h" #if defined(HAVE_DEV_TTY) || defined(GIT_WINDOWS_NATIVE) @@ -64,11 +66,28 @@ static int disable_echo(void) #define OUTPUT_PATH "CONOUT$" #define FORCE_TEXT "t" +static int use_stty = 1; +static struct string_list stty_restore = STRING_LIST_INIT_DUP; static HANDLE hconin = INVALID_HANDLE_VALUE; static DWORD cmode; static void restore_term(void) { + if (use_stty) { + int i; + struct child_process cp = CHILD_PROCESS_INIT; + + if (stty_restore.nr == 0) + return; + + argv_array_push(&cp.args, "stty"); + for (i = 0; i < stty_restore.nr; i++) + argv_array_push(&cp.args, stty_restore.items[i].string); + run_command(&cp); + string_list_clear(&stty_restore, 0); + return; + } + if (hconin == INVALID_HANDLE_VALUE) return; @@ -79,6 +98,37 @@ static void restore_term(void) static int disable_bits(DWORD bits) { + if (use_stty) { + struct child_process cp = CHILD_PROCESS_INIT; + + argv_array_push(&cp.args, "stty"); + + if (bits & ENABLE_LINE_INPUT) { + string_list_append(&stty_restore, "icanon"); + argv_array_push(&cp.args, "-icanon"); + } + + if (bits & ENABLE_ECHO_INPUT) { + string_list_append(&stty_restore, "echo"); + argv_array_push(&cp.args, "-echo"); + } + + if (bits & ENABLE_PROCESSED_INPUT) { + string_list_append(&stty_restore, "-ignbrk"); + string_list_append(&stty_restore, "intr"); + string_list_append(&stty_restore, "^c"); + argv_array_push(&cp.args, "ignbrk"); + argv_array_push(&cp.args, "intr"); + argv_array_push(&cp.args, ""); + } + + if (run_command(&cp) == 0) + return 0; + + /* `stty` could not be executed; access the Console directly */ + use_stty = 0; + } + hconin = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); -- gitgitgadget