util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] chfn: Make readline prompt for each field on a separate line
@ 2020-06-27 18:58 Damien Goutte-Gattat
  2020-06-29 10:02 ` Karel Zak
  0 siblings, 1 reply; 2+ messages in thread
From: Damien Goutte-Gattat @ 2020-06-27 18:58 UTC (permalink / raw)
  To: util-linux

When readline is called to get user input, it is called without
a prompt argument. As a result, if the user does not enter anything
for a given field, then the next field is displayed on the same
line, yielding the following output:

  $ chfn
  Changing finger information for user.
  Password:
  Name []: Office []: Office Phone []: Home Phone []:

instead of the expected:

  $ chfn
  Changing finger information for user.
  Password:
  Full Name []:
  Room Number []:
  Work Phone []:
  Home Phone []:

This patch restores the expected behavior by feeding readline with
a character to display as "prompt".

Signed-off-by: Damien Goutte-Gattat <dgouttegattat@incenp.org>
---
 login-utils/chfn.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/login-utils/chfn.c b/login-utils/chfn.c
index 1b203a83e..b2aadb0d9 100644
--- a/login-utils/chfn.c
+++ b/login-utils/chfn.c
@@ -235,12 +235,13 @@ static char *ask_new_field(struct chfn_control *ctl, const char *question,
 	if (!def_val)
 		def_val = "";
 	while (true) {
-		printf("%s [%s]: ", question, def_val);
+		printf("%s [%s]:", question, def_val);
 		__fpurge(stdin);
 #ifdef HAVE_LIBREADLINE
 		rl_bind_key('\t', rl_insert);
-		if ((buf = readline(NULL)) == NULL)
+		if ((buf = readline(" ")) == NULL)
 #else
+		putchar('\n');
 		if (getline(&buf, &dummy, stdin) < 0)
 #endif
 			errx(EXIT_FAILURE, _("Aborted."));
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] chfn: Make readline prompt for each field on a separate line
  2020-06-27 18:58 [PATCH] chfn: Make readline prompt for each field on a separate line Damien Goutte-Gattat
@ 2020-06-29 10:02 ` Karel Zak
  0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2020-06-29 10:02 UTC (permalink / raw)
  To: Damien Goutte-Gattat; +Cc: util-linux

On Sat, Jun 27, 2020 at 07:58:13PM +0100, Damien Goutte-Gattat wrote:
>   $ chfn
>   Changing finger information for user.
>   Password:
>   Name []: Office []: Office Phone []: Home Phone []:

Good catch. Applied, thanks!

> --- a/login-utils/chfn.c
> +++ b/login-utils/chfn.c
> @@ -235,12 +235,13 @@ static char *ask_new_field(struct chfn_control *ctl, const char *question,
>  	if (!def_val)
>  		def_val = "";
>  	while (true) {
> -		printf("%s [%s]: ", question, def_val);
> +		printf("%s [%s]:", question, def_val);
>  		__fpurge(stdin);
>  #ifdef HAVE_LIBREADLINE
>  		rl_bind_key('\t', rl_insert);
> -		if ((buf = readline(NULL)) == NULL)
> +		if ((buf = readline(" ")) == NULL)
>  #else
> +		putchar('\n');

I have replaced '\n with ' ', otherwise for non-readline version it
it prints extra line.

I have also applied your change also to chsh.
https://github.com/karelzak/util-linux/commit/49848aa53ae3a599277e8ceb50feda565f140b45


    Karel


-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-29 19:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-27 18:58 [PATCH] chfn: Make readline prompt for each field on a separate line Damien Goutte-Gattat
2020-06-29 10:02 ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).