[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH] virsh: Honor reedit opts printing to a function



On 06/13/2012 03:54 AM, Michal Privoznik wrote:
> When printing reedit options we make stdin raw. However,
> this results in stdout being raw as well. Therefore we need
> to return carriage when doing new line. Unfortunately,
> '\r' cannot be part of internationalized messages hence
> we must move them to formatting string which then in turn
> become huge and disarranged. To solve this, a new function
> is introduced which takes variable string arguments and
> prepend each with "\r\n" just before printing.
> ---
>  tools/virsh.c |   25 +++++++++++++++++++++----
>  1 files changed, 21 insertions(+), 4 deletions(-)

Looks nice.

> 
> diff --git a/tools/virsh.c b/tools/virsh.c
> index 90ea43d..6840b92 100644
> --- a/tools/virsh.c
> +++ b/tools/virsh.c
> @@ -655,6 +655,21 @@ vshReconnect(vshControl *ctl)
>      ctl->useSnapshotOld = false;
>  }
>  
> +static void
> +vshPrintRaw(vshControl *ctl, ...)
> +{
> +    va_list ap;
> +    char *key;
> +
> +    va_start(ap, ctl);
> +    while ((key = va_arg(ap, char *)) != NULL) {
> +        vshPrint(ctl, "\r\n%s", key);
> +    }
> +    vshPrint(ctl, "\r\n");

This both prepends and ends with a newline.  I think it would be a
little bit simpler if it only ever added newlines on the end.  Callers
would then...

> +
> +    va_end(ap);
> +}
> +
>  /**
>   * vshAskReedit:
>   * @msg: Question to ask user
> @@ -690,10 +705,12 @@ vshAskReedit(vshControl *ctl, const char *msg)
>          c = c_tolower(getchar());
>  
>          if (c == '?') {
> -            vshPrint(ctl, "\r\n%s", _("y - yes, start editor again\n"
> -                                      "n - no, throw away my changes\n"
> -                                      "f - force, try to redefine again\n"
> -                                      "? - print this help\n"));
> +            vshPrintRaw(ctl,

...start with a "" (untranslated, since _("") doesn't do what you think)
if they want to also prepend a newline.

> +                        _("y - yes, start editor again"),
> +                        _("n - no, throw away my changes"),
> +                        _("f - force, try to redefine again"),
> +                        _("? - print this help"),
> +                        NULL);
>              continue;
>          } else if (c == 'y' || c == 'n' || c == 'f') {
>              break;

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]