diff mbox series

[v1,1/2] cmd: exit: add continue on key press command

Message ID 20230123200354.3642-2-clamor95@gmail.com
State Superseded
Delegated to: Tom Rini
Headers show
Series CMD commands improvements | expand

Commit Message

Svyatoslav Ryhel Jan. 23, 2023, 8:03 p.m. UTC
This command stops performing script until any
key is pressed. It is useful for keeping logs
on screen until user decides to continue.

Co-developed-by: Jonas Schwöbel <jonasschwoebel@yahoo.de>
Signed-off-by: Jonas Schwöbel <jonasschwoebel@yahoo.de>
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
 cmd/exit.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Comments

Simon Glass Jan. 23, 2023, 10:25 p.m. UTC | #1
On Mon, 23 Jan 2023 at 13:04, Svyatoslav Ryhel <clamor95@gmail.com> wrote:
>
> This command stops performing script until any
> key is pressed. It is useful for keeping logs
> on screen until user decides to continue.
>
> Co-developed-by: Jonas Schwöbel <jonasschwoebel@yahoo.de>
> Signed-off-by: Jonas Schwöbel <jonasschwoebel@yahoo.de>
> Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
> ---
>  cmd/exit.c | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
>

Please add a file in doc/usage/cmd

Also how about a test?

> diff --git a/cmd/exit.c b/cmd/exit.c
> index 7bf241ec73..673b4b6be7 100644
> --- a/cmd/exit.c
> +++ b/cmd/exit.c
> @@ -7,6 +7,17 @@
>  #include <common.h>
>  #include <command.h>
>
> +static int do_continue(struct cmd_tbl *cmdtp, int flag, int argc,
> +                      char *const argv[])
> +{
> +       while (true) {
> +               if (getchar())
> +                       break;
> +       }
> +
> +       return 0;
> +}
> +
>  static int do_exit(struct cmd_tbl *cmdtp, int flag, int argc,
>                    char *const argv[])
>  {
> @@ -19,6 +30,12 @@ static int do_exit(struct cmd_tbl *cmdtp, int flag, int argc,
>         return -r - 2;
>  }
>
> +U_BOOT_CMD(
> +       continue,       1,      0,      do_continue,
> +       "continue script on key pressed",
> +       ""
> +);
> +
>  U_BOOT_CMD(
>         exit,   2,      1,      do_exit,
>         "exit script",
> --
> 2.25.1
>

Regards,
Simon
Heinrich Schuchardt Jan. 23, 2023, 10:42 p.m. UTC | #2
Am 23. Januar 2023 23:25:41 MEZ schrieb Simon Glass <sjg@chromium.org>:
>On Mon, 23 Jan 2023 at 13:04, Svyatoslav Ryhel <clamor95@gmail.com> wrote:
>>
>> This command stops performing script until any
>> key is pressed. It is useful for keeping logs
>> on screen until user decides to continue.
>>
>> Co-developed-by: Jonas Schwöbel <jonasschwoebel@yahoo.de>
>> Signed-off-by: Jonas Schwöbel <jonasschwoebel@yahoo.de>
>> Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
>> ---
>>  cmd/exit.c | 17 +++++++++++++++++
>>  1 file changed, 17 insertions(+)
>>
>
>Please add a file in doc/usage/cmd
>
>Also how about a test?
>
>> diff --git a/cmd/exit.c b/cmd/exit.c
>> index 7bf241ec73..673b4b6be7 100644
>> --- a/cmd/exit.c
>> +++ b/cmd/exit.c
>> @@ -7,6 +7,17 @@
>>  #include <common.h>
>>  #include <command.h>
>>
>> +static int do_continue(struct cmd_tbl *cmdtp, int flag, int argc,
>> +                      char *const argv[])
>> +{
>> +       while (true) {
>> +               if (getchar())
>> +                       break;
>> +       }
>> +
>> +       return 0;
>> +}

We already have the sleep command which waits until CTRL+C is pressed or a time interval has elapsed.

Why does that command not satisfy the use case?

The command name continue is used in other languages for control structures. We should not use it for pausing.

We should not put a new command into an existing C module without good reason.

Best regards

Heinrich 



>> +
>>  static int do_exit(struct cmd_tbl *cmdtp, int flag, int argc,
>>                    char *const argv[])
>>  {
>> @@ -19,6 +30,12 @@ static int do_exit(struct cmd_tbl *cmdtp, int flag, int argc,
>>         return -r - 2;
>>  }
>>
>> +U_BOOT_CMD(
>> +       continue,       1,      0,      do_continue,
>> +       "continue script on key pressed",
>> +       ""
>> +);
>> +
>>  U_BOOT_CMD(
>>         exit,   2,      1,      do_exit,
>>         "exit script",
>> --
>> 2.25.1
>>
>
>Regards,
>Simon
Svyatoslav Ryhel Jan. 24, 2023, 6:40 a.m. UTC | #3
вт, 24 січ. 2023 р. о 00:43 Heinrich Schuchardt <xypron.glpk@gmx.de> пише:
>
>
>
> Am 23. Januar 2023 23:25:41 MEZ schrieb Simon Glass <sjg@chromium.org>:
> >On Mon, 23 Jan 2023 at 13:04, Svyatoslav Ryhel <clamor95@gmail.com> wrote:
> >>
> >> This command stops performing script until any
> >> key is pressed. It is useful for keeping logs
> >> on screen until user decides to continue.
> >>
> >> Co-developed-by: Jonas Schwöbel <jonasschwoebel@yahoo.de>
> >> Signed-off-by: Jonas Schwöbel <jonasschwoebel@yahoo.de>
> >> Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
> >> ---
> >>  cmd/exit.c | 17 +++++++++++++++++
> >>  1 file changed, 17 insertions(+)
> >>
> >
> >Please add a file in doc/usage/cmd
> >
> >Also how about a test?
> >
> >> diff --git a/cmd/exit.c b/cmd/exit.c
> >> index 7bf241ec73..673b4b6be7 100644
> >> --- a/cmd/exit.c
> >> +++ b/cmd/exit.c
> >> @@ -7,6 +7,17 @@
> >>  #include <common.h>
> >>  #include <command.h>
> >>
> >> +static int do_continue(struct cmd_tbl *cmdtp, int flag, int argc,
> >> +                      char *const argv[])
> >> +{
> >> +       while (true) {
> >> +               if (getchar())
> >> +                       break;
> >> +       }
> >> +
> >> +       return 0;
> >> +}

Hello, Heinrich!

> We already have the sleep command which waits until CTRL+C is pressed or a time interval has elapsed.

You are correct, this commit duplicates same command, but not sleep.
Pause command was merged 2022.09 while I have made this command
approx. a year ago and did not check since then if any new commands
were added. This commit will be dropped in V2, but the second commit
in this patchset has no other implementations.

> Why does that command not satisfy the use case?

My keyboard has only 3 keys: up, down and enter. I have no luxury of a
108 key keyboard.

> The command name continue is used in other languages for control structures. We should not use it for pausing.
>
> We should not put a new command into an existing C module without good reason.
>
> Best regards
>
> Heinrich
>

Thanks for your review.
Best regards, Svyatoslav R.

>
> >> +
> >>  static int do_exit(struct cmd_tbl *cmdtp, int flag, int argc,
> >>                    char *const argv[])
> >>  {
> >> @@ -19,6 +30,12 @@ static int do_exit(struct cmd_tbl *cmdtp, int flag, int argc,
> >>         return -r - 2;
> >>  }
> >>
> >> +U_BOOT_CMD(
> >> +       continue,       1,      0,      do_continue,
> >> +       "continue script on key pressed",
> >> +       ""
> >> +);
> >> +
> >>  U_BOOT_CMD(
> >>         exit,   2,      1,      do_exit,
> >>         "exit script",
> >> --
> >> 2.25.1
> >>
> >
> >Regards,
> >Simon
Svyatoslav Ryhel Jan. 24, 2023, 6:47 a.m. UTC | #4
Hello Simon!

Thanks for your review. Heinrich Schuchardt made a valid remark that
command with such functionality already exists. It is called - pause -
and my commit fully duplicates it.

Pause command was merged 2022.09 while I have made this command
approx. a year ago in my fork and did not check since then if any new commands
were added. This commit will be dropped in V2, but the second commit
in this patchset, seems, to have no other implementations.

Best regards, Svyatoslav R.

вт, 24 січ. 2023 р. о 00:25 Simon Glass <sjg@chromium.org> пише:
>
> On Mon, 23 Jan 2023 at 13:04, Svyatoslav Ryhel <clamor95@gmail.com> wrote:
> >
> > This command stops performing script until any
> > key is pressed. It is useful for keeping logs
> > on screen until user decides to continue.
> >
> > Co-developed-by: Jonas Schwöbel <jonasschwoebel@yahoo.de>
> > Signed-off-by: Jonas Schwöbel <jonasschwoebel@yahoo.de>
> > Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
> > ---
> >  cmd/exit.c | 17 +++++++++++++++++
> >  1 file changed, 17 insertions(+)
> >
>
> Please add a file in doc/usage/cmd
>
> Also how about a test?
>
> > diff --git a/cmd/exit.c b/cmd/exit.c
> > index 7bf241ec73..673b4b6be7 100644
> > --- a/cmd/exit.c
> > +++ b/cmd/exit.c
> > @@ -7,6 +7,17 @@
> >  #include <common.h>
> >  #include <command.h>
> >
> > +static int do_continue(struct cmd_tbl *cmdtp, int flag, int argc,
> > +                      char *const argv[])
> > +{
> > +       while (true) {
> > +               if (getchar())
> > +                       break;
> > +       }
> > +
> > +       return 0;
> > +}
> > +
> >  static int do_exit(struct cmd_tbl *cmdtp, int flag, int argc,
> >                    char *const argv[])
> >  {
> > @@ -19,6 +30,12 @@ static int do_exit(struct cmd_tbl *cmdtp, int flag, int argc,
> >         return -r - 2;
> >  }
> >
> > +U_BOOT_CMD(
> > +       continue,       1,      0,      do_continue,
> > +       "continue script on key pressed",
> > +       ""
> > +);
> > +
> >  U_BOOT_CMD(
> >         exit,   2,      1,      do_exit,
> >         "exit script",
> > --
> > 2.25.1
> >
>
> Regards,
> Simon
diff mbox series

Patch

diff --git a/cmd/exit.c b/cmd/exit.c
index 7bf241ec73..673b4b6be7 100644
--- a/cmd/exit.c
+++ b/cmd/exit.c
@@ -7,6 +7,17 @@ 
 #include <common.h>
 #include <command.h>
 
+static int do_continue(struct cmd_tbl *cmdtp, int flag, int argc,
+		       char *const argv[])
+{
+	while (true) {
+		if (getchar())
+			break;
+	}
+
+	return 0;
+}
+
 static int do_exit(struct cmd_tbl *cmdtp, int flag, int argc,
 		   char *const argv[])
 {
@@ -19,6 +30,12 @@  static int do_exit(struct cmd_tbl *cmdtp, int flag, int argc,
 	return -r - 2;
 }
 
+U_BOOT_CMD(
+	continue,	1,	0,	do_continue,
+	"continue script on key pressed",
+	""
+);
+
 U_BOOT_CMD(
 	exit,	2,	1,	do_exit,
 	"exit script",