Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1iNvUB-0004pj-KW for mharc-grub-devel@gnu.org; Fri, 25 Oct 2019 05:02:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54553) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNvU7-0004bK-Jz for grub-devel@gnu.org; Fri, 25 Oct 2019 05:02:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNvU3-0002bh-6j for grub-devel@gnu.org; Fri, 25 Oct 2019 05:02:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48898) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iNvU2-0002ag-Tw for grub-devel@gnu.org; Fri, 25 Oct 2019 05:02:11 -0400 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2B131C049E10 for ; Fri, 25 Oct 2019 09:02:09 +0000 (UTC) Received: by mail-wr1-f71.google.com with SMTP id q14so695890wrw.4 for ; Fri, 25 Oct 2019 02:02:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=9shKX74ywKpGBiRWE1Boc9AH6FBd4orbczfbFgqggu4=; b=rn0HNGE2vLFeIssNeJgArwvHbo3jLPPQIdbdQ7dRpMJ7mKyhqFNiUfFzbp8UyiRsSR ANKbIeBsXNGjR25fokTw//mFUMZDRO1qIh2ynZoD2rA6qRk75D+o8SS7pVkHtI5dIMuM L2AgV1823CENJuIGodyIfWi20NXgwOTP58i+pOPvJmzyOK/IU/tb6mQHFb1OzxGubH25 stbH2NUdCi2NhLQTRzGZ/AnjWnhqR1bvf2pR2Al0al9/I0mUxNzs9cjnOdrZ/f5NIuBV goF1kT4G4WKXAKYh4x1p5gpwh/urmSu0ZhjlrMwOKvTDYKMoTUVwBEb5Medfi05lK4TD NEVg== X-Gm-Message-State: APjAAAWShi70kRvTkZjz8OdLwRheaMNecXpB7fJFgfGNKi2DSXiimRLx mJLuGSzT/vgqNBQHjovjmh4WOJr3cCGFTc2AXE0VXzaCa3BA5d8z/xMbeWjjYCrqy2O4/8LiUqS whQ7d+daQGi0= X-Received: by 2002:a1c:9894:: with SMTP id a142mr2358239wme.135.1571994127773; Fri, 25 Oct 2019 02:02:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqwR30q1nXEHbhOFvtrIZUsi/f20hbRhmXA4tw4XMYW/4P45t6NvDzs1zaU5ZesZBwIRJ7mRfA== X-Received: by 2002:a1c:9894:: with SMTP id a142mr2358218wme.135.1571994127496; Fri, 25 Oct 2019 02:02:07 -0700 (PDT) Received: from [192.168.1.13] ([90.168.169.92]) by smtp.gmail.com with ESMTPSA id c8sm1361657wml.44.2019.10.25.02.02.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 25 Oct 2019 02:02:06 -0700 (PDT) Subject: Re: [PATCH] Enable pager by default To: Daniel Kiper Cc: grub-devel@gnu.org, Peter Jones References: <20191018124318.16361-1-javierm@redhat.com> <20191021145619.gewxm5eys4qu2ahp@tomti.i.net-space.pl> <6569e1ee-36e9-b774-0332-b746d591843b@redhat.com> <20191022140428.ignbsxgngmq4bm6x@tomti.i.net-space.pl> <59a34f9e-2fa2-2702-6896-b176e2b4ad79@redhat.com> <20191024145042.k3zybdll6cqiydz2@tomti.i.net-space.pl> From: Javier Martinez Canillas Message-ID: Date: Fri, 25 Oct 2019 11:02:04 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.0 MIME-Version: 1.0 In-Reply-To: <20191024145042.k3zybdll6cqiydz2@tomti.i.net-space.pl> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Oct 2019 09:02:18 -0000 Hello Daniel, On 10/24/19 4:50 PM, Daniel Kiper wrote: [snip] >> >> From 7c4da6295ebd3a034d1f7e32099eab33efa465d4 Mon Sep 17 00:00:00 2001 >> From: Javier Martinez Canillas >> Date: Tue, 22 Oct 2019 15:35:12 +0200 >> Subject: [PATCH v2] Add a GRUB_COMMAND_FLAG_PAGINATED to request paginated >> output for commands >> >> When user enters into the GRUB shell and tries to use help command, lot of >> information is scrolled out of screen and the user doesn't have chance to >> read it. Also, there isn't any information about 'set pager=1' at the end >> of the help output, to tell the user how scrolling could be enabled. >> >> Since the out for some commands may not fit into a screen, add a new flag >> GRUB_COMMAND_FLAG_PAGINATED that can be used when registering commands that >> can be used to request the pager to be enabled while executing the handler. >> >> Signed-off-by: Javier Martinez Canillas > > In general I like the idea but I think patch requires some polishing... > > Hmmm... Still thinking about "-p" flag which allows user to choose > between pager on/off. Or something which I proposed in the email to > Michael... > I'm OK with any of the other two approaches too. But it seems that Vladimir is worried about the added complexity for these. I honestly think that the approach in this patch is the least bad option since it doesn't require a special configuration or the user to do anything, just execute the command printing a lot of stuff and get paginated output by default. Can't think why users would want to execute commands that print a lot of messages without the output being paginated, or why they would want to execute a command like help in in batch mode. It's only useful in interactive mode. And also the patch is quite trivial, it already uses all the existing code for the pager option. But I'll wait for the discussion to settle and a solution to be agreed upon, before posting a new patch for this. >> --- >> >> Changes in v2: >> - Only enable pager temporarily while printing output for commands that asked >> for paginated output instead of doing it globally using the pager variable. >> >> grub-core/commands/help.c | 3 ++- >> grub-core/commands/minicmd.c | 13 ++++++++----- >> grub-core/normal/dyncmd.c | 7 +++++++ >> grub-core/normal/term.c | 17 +++++++++++++++++ >> grub-core/script/execute.c | 7 +++++++ >> include/grub/command.h | 4 +++- >> include/grub/normal.h | 3 +++ >> 7 files changed, 47 insertions(+), 7 deletions(-) >> >> diff --git a/grub-core/commands/help.c b/grub-core/commands/help.c >> index f0be89baa19..6e20e1447a8 100644 >> --- a/grub-core/commands/help.c >> +++ b/grub-core/commands/help.c >> @@ -142,7 +142,8 @@ static grub_extcmd_t cmd; >> >> GRUB_MOD_INIT(help) >> { >> - cmd = grub_register_extcmd ("help", grub_cmd_help, 0, >> + cmd = grub_register_extcmd ("help", grub_cmd_help, >> + GRUB_COMMAND_FLAG_PAGINATED, >> N_("[PATTERN ...]"), >> N_("Show a help message."), 0); >> } >> diff --git a/grub-core/commands/minicmd.c b/grub-core/commands/minicmd.c >> index 6bbce3128cf..e6a9242bfa6 100644 >> --- a/grub-core/commands/minicmd.c >> +++ b/grub-core/commands/minicmd.c >> @@ -21,6 +21,7 @@ >> #include >> #include >> #include >> +#include >> #include >> #include >> #include >> @@ -75,7 +76,7 @@ grub_mini_cmd_cat (struct grub_command *cmd __attribute__ ((unused)), >> >> /* help */ >> static grub_err_t >> -grub_mini_cmd_help (struct grub_command *cmd __attribute__ ((unused)), >> +grub_mini_cmd_help (grub_extcmd_context_t ctxt __attribute__ ((unused)), >> int argc __attribute__ ((unused)), >> char *argv[] __attribute__ ((unused))) >> { >> @@ -188,7 +189,8 @@ grub_mini_cmd_exit (struct grub_command *cmd __attribute__ ((unused)), >> /* Not reached. */ >> } >> >> -static grub_command_t cmd_cat, cmd_help; >> +static grub_command_t cmd_cat; >> +static grub_extcmd_t cmd_help; >> static grub_command_t cmd_dump, cmd_rmmod, cmd_lsmod, cmd_exit; >> >> GRUB_MOD_INIT(minicmd) >> @@ -197,8 +199,9 @@ GRUB_MOD_INIT(minicmd) >> grub_register_command ("cat", grub_mini_cmd_cat, >> N_("FILE"), N_("Show the contents of a file.")); >> cmd_help = >> - grub_register_command ("help", grub_mini_cmd_help, >> - 0, N_("Show this message.")); >> + grub_register_extcmd ("help", grub_mini_cmd_help, >> + GRUB_COMMAND_FLAG_PAGINATED, >> + 0, N_("Show this message."), 0); >> cmd_dump = >> grub_register_command ("dump", grub_mini_cmd_dump, >> N_("ADDR [SIZE]"), N_("Show memory contents.")); >> @@ -216,7 +219,7 @@ GRUB_MOD_INIT(minicmd) >> GRUB_MOD_FINI(minicmd) >> { >> grub_unregister_command (cmd_cat); >> - grub_unregister_command (cmd_help); >> + grub_unregister_extcmd (cmd_help); >> grub_unregister_command (cmd_dump); >> grub_unregister_command (cmd_rmmod); >> grub_unregister_command (cmd_lsmod); >> diff --git a/grub-core/normal/dyncmd.c b/grub-core/normal/dyncmd.c >> index 719ebf477f2..1ef52cbe43b 100644 >> --- a/grub-core/normal/dyncmd.c >> +++ b/grub-core/normal/dyncmd.c >> @@ -78,11 +78,18 @@ grub_dyncmd_dispatcher (struct grub_extcmd_context *ctxt, >> cmd = grub_command_find (name); >> if (cmd) >> { >> + /* Temporarily enable paginated output for commands that asked for it */ >> + if (cmd->flags & GRUB_COMMAND_FLAG_PAGINATED) >> + grub_enable_temp_more (); >> + >> if (cmd->flags & GRUB_COMMAND_FLAG_BLOCKS && >> cmd->flags & GRUB_COMMAND_FLAG_EXTCMD) >> ret = grub_extcmd_dispatcher (cmd, argc, args, ctxt->script); >> else >> ret = (cmd->func) (cmd, argc, args); >> + >> + if (cmd->flags & GRUB_COMMAND_FLAG_PAGINATED) >> + grub_disable_temp_more (); >> } >> else >> ret = grub_errno; >> diff --git a/grub-core/normal/term.c b/grub-core/normal/term.c >> index a1e5c5a0daf..7d4021ff8be 100644 >> --- a/grub-core/normal/term.c >> +++ b/grub-core/normal/term.c >> @@ -57,6 +57,7 @@ static struct term_state *term_states = NULL; >> >> /* If the more pager is active. */ >> static int grub_more; >> +static int temp_more; >> >> static void >> putcode_real (grub_uint32_t code, struct grub_term_output *term, int fixed_tab); >> @@ -128,6 +129,22 @@ grub_set_more (int onoff) >> grub_normal_reset_more (); >> } >> >> +void >> +grub_enable_temp_more (void) >> +{ >> + temp_more = grub_more; >> + >> + if (!temp_more) >> + grub_set_more (1); > > Does it change pager variable value? If yes I think > that you should store its original value here and > restore below. > Yes it does and that's why I added the temp_more variable. It only calls to gru_set_more() if pager is disabled, since if is already enabled, then there's no need to call grub_set_more(1). >> +} >> + >> +void >> +grub_disable_temp_more (void) >> +{ >> + if (!temp_more) >> + grub_set_more (0); > Same here, the pager only needs to be disabled if it wasn't enabled before. > Daniel > Best regards, -- Javier Martinez Canillas Software Engineer - Desktop Hardware Enablement Red Hat