From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:403:478a::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id eF/QKiae6WSDCQEA9RJhRA:P1 (envelope-from ) for ; Sat, 26 Aug 2023 08:39:34 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:478a::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id eF/QKiae6WSDCQEA9RJhRA (envelope-from ) for ; Sat, 26 Aug 2023 08:39:34 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id C962C50C9E for ; Sat, 26 Aug 2023 08:39:32 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=lepiller.eu header.s=dkim header.b="gSZN CdO"; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=lepiller.eu (policy=none) ARC-Seal: i=1; s=key1; d=yhetil.org; t=1693031974; a=rsa-sha256; cv=none; b=pIBfVAC5aY2hsY0zItiTqSpWojcOP7qCa4KB579qrxzRuNMqBo/u4Nlcdwnp/XbFGTarE9 tu+JXql3W+xZ/fSIsCQxBdrO2BHsFKdD9nF3KvKUwRrOc/diq2155EuMpIrM6dG8JZjgHV ivF9r/H7qUPycrZOiDpvV1rkyvbDKeKxxaJ4t0RyeJS1nxxbHwDNEiBcA0iWogjsKHiA72 IlMzpob2dDrezFJHLkT8sC/Knkkv8t6mkJTcamRXXbCG4K0mS5IUAcyN1oGKOntT8MnW9b 6B3Gt80o1Vuo4WhXZa7IH+UAupHfirfJRnIcIZII0GUZatbXOuwDbQBQS0odkg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=lepiller.eu header.s=dkim header.b="gSZN CdO"; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=lepiller.eu (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1693031974; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=dC3lXJKAkNNP3UyDBCf0VEb2IaNFh0BupxK267+r/s8=; b=USuQrOy46Qhr6r0aoerZFvPyiqVPW0XjUqonH+zQHl4ju/eNHeXlGYfCIWhGTCfWCsiy1v DQxE9kTFWd/DpRDcgnHytpAqq4UdCwXKkCCNervMVDcgyeVD5VA/Ldsbx40g33K3DRVCd4 p6c3QwQcTR7dZwNecGW9nidGPgnS3oZIV4mTYLfAelikQ19XsKAUUyefrISuU1pGWPmuEd W+qzpnEmONAY7t53Qklzuevyz/dRWFBup7yMeh7fKZOI8rBR3pTSHZ0uLtXoFFn2rpVmBd XiSebd4lBzxH4wHjLftprFMoiAFpV1qDSISi6hB/pwiLJr92ARkIUsyfm7bvtA== Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qZmwr-0004ok-TV; Sat, 26 Aug 2023 02:39:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qZmwp-0004nz-IR for guix-patches@gnu.org; Sat, 26 Aug 2023 02:39:03 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qZmwj-0006ny-AZ for guix-patches@gnu.org; Sat, 26 Aug 2023 02:39:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qZmwo-0001ns-9j for guix-patches@gnu.org; Sat, 26 Aug 2023 02:39:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#65546] [PATCH] guix: Properly compute progress bar width. Resent-From: Julien Lepiller Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 26 Aug 2023 06:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 65546 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 65546@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16930319216900 (code B ref -1); Sat, 26 Aug 2023 06:39:02 +0000 Received: (at submit) by debbugs.gnu.org; 26 Aug 2023 06:38:41 +0000 Received: from localhost ([127.0.0.1]:41576 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qZmwT-0001nE-DR for submit@debbugs.gnu.org; Sat, 26 Aug 2023 02:38:41 -0400 Received: from lists.gnu.org ([2001:470:142::17]:60516) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qZmwO-0001my-Sk for submit@debbugs.gnu.org; Sat, 26 Aug 2023 02:38:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qZmwC-0004lI-FV for guix-patches@gnu.org; Sat, 26 Aug 2023 02:38:25 -0400 Received: from lepiller.eu ([2a00:5884:8208::1] helo=localhost) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qZmw8-0006VS-2Q for guix-patches@gnu.org; Sat, 26 Aug 2023 02:38:23 -0400 Received: from localhost (localhost [127.0.0.1]) by localhost (OpenSMTPD) with ESMTP id f6952dbe for ; Sat, 26 Aug 2023 06:37:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=lepiller.eu; h=from:to :subject:date:message-id:mime-version:content-transfer-encoding; s=dkim; bh=1xlwRh/ihmH4yclBriW/mA/2tgGwt1xRWCBwDoc1+nA=; b=gSZN CdOqCqnfs6mn35neSTApG29XNsNQo8uC3JD0BGyQ9GoIfhd++GHkwE4pH2f4YLpx nE9TnsBSU9glTiG8E5fD0M7IWHGyszntZCN7TyCgyM9OLNp9gfQfUoVNBVTZR70Q EXH28mKFKyzDALDXGnipVqdrI3BHDKgkfwndt2V6tc4cQb8VC23wCIDy3RqzkStQ 1ROKyxtrPRT+ximrnzPcpEijdkPkGGboq2QViEokDuPFjR67cmJ1lFihDDu6/BCC PAa44i1YT8NbUBRbtBIeu06D4k1p5ktsRfZ/ZcJE6xQr2Fe0jir5mQenGOBW5GE6 i8QH4jC7/XjlRRbylg== Received: by localhost (OpenSMTPD) with ESMTPSA id e76155e3 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Sat, 26 Aug 2023 06:37:09 +0000 (UTC) From: Julien Lepiller Date: Sat, 26 Aug 2023 08:36:55 +0200 Message-ID: <20230826063655.2227-1-julien@lepiller.eu> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:5884:8208::1; envelope-from=julien@lepiller.eu; helo=localhost X-Spam_score_int: 17 X-Spam_score: 1.7 X-Spam_bar: + X-Spam_report: (1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FSL_HELO_NON_FQDN_1=0.001, HELO_LOCALHOST=3.828, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Scanner: mx0.migadu.com X-Spam-Score: -3.62 X-Migadu-Queue-Id: C962C50C9E X-Migadu-Spam-Score: -3.62 X-TUID: KcShSBJkjYs9 * 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. --- guix/git.scm | 2 +- guix/progress.scm | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/guix/git.scm b/guix/git.scm index dbc3b7caa7..870045cddf 100644 --- a/guix/git.scm +++ b/guix/git.scm @@ -153,7 +153,7 @@ (define % ;; TODO: Both should be handled & exposed by the PROGRESS-BAR API instead. (define width (max (- (current-terminal-columns) - (string-length label) 7) + (terminal-width label) 7) 3)) (define grain diff --git a/guix/progress.scm b/guix/progress.scm index 33cf6f4a1a..8a84bcd1b0 100644 --- a/guix/progress.scm +++ b/guix/progress.scm @@ -24,6 +24,7 @@ (define-module (guix progress) #:use-module (srfi srfi-19) #:use-module (rnrs io ports) #:use-module (rnrs bytevectors) + #:use-module (system foreign) #:use-module (ice-9 format) #:use-module (ice-9 match) #:export ( @@ -47,6 +48,7 @@ (define-module (guix progress) progress-bar byte-count->string current-terminal-columns + terminal-width dump-port*)) @@ -166,6 +168,28 @@ (define current-terminal-columns ;; Number of columns of the terminal. (make-parameter 80)) +(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))) + (define-record-type* progress-bar-style make-progress-bar-style progress-bar-style? (start progress-bar-style-start) @@ -307,7 +331,7 @@ (define (draw-bar) (if (string-null? prefix) (display (progress-bar ratio (current-terminal-columns)) port) (let ((width (- (current-terminal-columns) - (string-length prefix) 3))) + (terminal-width prefix) 3))) (display prefix port) (display " " port) (display (progress-bar ratio width) port))) -- 2.41.0