[PATCH xinput] use ASCII art when UTF-8 environment is not available

Peter Hutterer peter.hutterer at who-t.net
Wed Dec 8 16:09:06 PST 2010


On Wed, Dec 08, 2010 at 10:31:37PM +0100, Matthieu Herrb wrote:
> 
> Based on an initial patch by Jasper Lievisse Adriaanse.
> 
> Signed-off-by: Matthieu Herrb <matthieu.herrb at laas.fr>
> ---
>  src/list.c |   37 ++++++++++++++++++++++++++++++++-----
>  1 files changed, 32 insertions(+), 5 deletions(-)
> 
> diff --git a/src/list.c b/src/list.c
> index 8633c62..7f882ab 100644
> --- a/src/list.c
> +++ b/src/list.c
> @@ -241,10 +241,13 @@ list_xi2(Display *display,
>          dev = &info[i];
>          if (dev->use == XIMasterPointer || dev->use == XIMasterKeyboard)
>          {
> -            if (dev->use == XIMasterPointer)
> -                printf("⎡ ");
> -            else
> -                printf("⎣ ");
> +	    if (have_utf8())
> +                if (dev->use == XIMasterPointer)
> +                    printf("⎡ ");
> +                else
> +                    printf("⎣ ");
> +	    else
> +		printf("+ ");
>  
>              print_info_xi2(display, dev, shortformat);
>              for (j = 0; j < ndevices; j++)
> @@ -254,7 +257,10 @@ list_xi2(Display *display,
>                  if ((sd->use == XISlavePointer || sd->use == XISlaveKeyboard) &&
>                       (sd->attachment == dev->deviceid))
>                  {
> -                    printf("%s   ↳ ", dev->use == XIMasterPointer ? "⎜" : " ");
> +		    if (have_utf8())
> +                        printf("%s   ↳ ", dev->use == XIMasterPointer ? "⎜" : " ");
> +                    else
> +		        printf("%s   + ", dev->use == XIMasterPointer ? "|" : " ");
>                      print_info_xi2(display, sd, shortformat);
>                  }
>              }
> @@ -324,4 +330,25 @@ list(Display	*display,
>      }
>  }
>  
> +Bool
> +have_utf8(void){
> +    char *t;
> +
> +    /*
> +     * There is no standard way to detect UTF-8 capabilities of a
> +     * given terminal, but this gets pretty close as a good heuristic.
> +     */
> +    if ((t = getenv("LC_ALL")) == NULL) {
> +	if ((t = getenv("LC_CTYPE")) == NULL) {
> +	    t = getenv("LANG");
> +	}
> +    }
> +
> +    if (t != NULL && (strcasestr(t, "UTF-8") != NULL ||
> +      strcasestr(t, "UTF8") != NULL))
> +	return True;
> +
> +    return False;
> +}
> +
>  /* end of list.c */
> -- 
> 1.7.3.2

urgh, no. I'd rather change the output ASCII only than have if/else
conditions for the output. we could probably use /|\ instead of ⎡⎜⎣ and
simple -> or just - instead of ↳.

Cheers,
  Peter


More information about the xorg-devel mailing list