GNU bug report logs -
#65546
[PATCH] guix: Properly compute progress bar width.
Previous Next
Reported by: Julien Lepiller <julien <at> lepiller.eu>
Date: Sat, 26 Aug 2023 06:39:02 UTC
Severity: normal
Tags: patch
Done: Julien Lepiller <julien <at> lepiller.eu>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
Hi Julien,
Julien Lepiller <julien <at> lepiller.eu> skribis:
> * guix/progress.scm (terminal-width): New procedure.
> (progress-reporter/bar): Use it to compute progress bar width.
> * guix/git.scm (show-progress): Use it to compute progress bar width.
[...]
> +(define (terminal-width str)
> + "Return the width of a string as it would be printed on the terminal. This
> +procedure accounts for characters that have a different width than 1, such as
> +CJK double-width characters."
> + (define get-wchar-ffi
> + (pointer->procedure int
> + (dynamic-func "mbstowcs" (dynamic-link))
> + (list '* '* size_t)))
> + (define terminal-width-ffi
> + (pointer->procedure int
> + (dynamic-func "wcswidth" (dynamic-link))
> + (list '* size_t)))
> + (define (get-wchar str)
> + (let ((wchar (make-bytevector (* (+ (string-length str) 1) 4))))
> + (get-wchar-ffi (bytevector->pointer wchar)
> + (string->pointer str)
> + (string-length str))
> + wchar))
> + (terminal-width-ffi
> + (bytevector->pointer (get-wchar str))
> + (string-length str)))
Neat! However, could you move it to (guix build syscalls), next to
‘terminal-columns’ (making sure ‘pointer->procedure’ is called only once
rather than once per call), and with a test or two in
‘tests/syscalls.scm’?
For clarity, perhaps rename it to ‘terminal-string-width’?
TIA!
Ludo’.
This bug report was last modified 1 year and 193 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.