From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:306:2d92::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id yGVlDdN3/GRUXwEA9RJhRA:P1 (envelope-from ) for ; Sat, 09 Sep 2023 15:49:07 +0200 Received: from aspmx1.migadu.com ([2001:41d0:306:2d92::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id yGVlDdN3/GRUXwEA9RJhRA (envelope-from ) for ; Sat, 09 Sep 2023 15:49:07 +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 E4B6B3C974 for ; Sat, 9 Sep 2023 15:49:06 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=NDnabhOK; 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=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1694267346; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=T0XyricgZn+OrJlvvkUXDPqhA9+HdFxt7lJjiNvEICM=; b=MQlfT/4pTjXDqcZe4d/KSy4OkmNtfY2tECUh17NPJzNX2C+hGapLpwhZqc30kMiPWIIBMt oNY06DsL6b+L4rAwglg4TX2he1FarH2M0TmjyqUy1Bl1CqQAjVwZfVTW07uifAiZ0IdAZA 7Jj8xnUru4pJ3QeTbrp59HGbn2fFD2VGJRfR3A/Hlmjlsz0TOYtVWizG2OsWaYQvrmCxWj eRNDXlpx94NUli33sPdwdpL04W0s7ruAaF23+08qwvpWsnqqkPFCWT5/6CSBvtA4Pfr8mH mMkHmEJSUB+WsgXkTfxw2VeO9gUetOJc7kNlnH6M8/lli6VGrvI63p9AxY5n9Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1694267346; a=rsa-sha256; cv=none; b=MYmeT5yi+mByvnaacjkEwwzL4L/gedVcjkhcGClT7D6gNVigdIAiJEoSOEoSvikNK8/4oi oBSp7sYtngm/t/eU9qa3j+KclWcSAWrLJmX7ZIITyB50FvPIJL9tfxiA1gcFt9WpnxRuaw XBvuMVeXLI4x4JmxEhsIxVV/DBzclGzqN32xOuXhe6iXEoarf/ALANHrjxHiz+udGdsttJ cMCDtrswNLDSXBtWczLCsLwrJISYnsLD2tETOPNRNBxqhLI2docAbbQVck1j1lD3TAztuF ZR4uc9ptibArno43/Y5OSKyB90OWMRSfNGFJnh4+VDioSO2UkyNcvZN2UIwnXw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=NDnabhOK; 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=pass (policy=none) header.from=gnu.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeyKa-00013Q-IY; Sat, 09 Sep 2023 09:49:00 -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 1qeyKZ-000136-3h for guix-patches@gnu.org; Sat, 09 Sep 2023 09:48:59 -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 1qeyKY-0005I3-SC for guix-patches@gnu.org; Sat, 09 Sep 2023 09:48:58 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qeyKb-0002Rv-N4 for guix-patches@gnu.org; Sat, 09 Sep 2023 09:49:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#65546] [PATCH] guix: Properly compute progress bar width. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 09 Sep 2023 13:49:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65546 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Julien Lepiller Cc: 65546@debbugs.gnu.org Received: via spool by 65546-submit@debbugs.gnu.org id=B65546.16942673179384 (code B ref 65546); Sat, 09 Sep 2023 13:49:01 +0000 Received: (at 65546) by debbugs.gnu.org; 9 Sep 2023 13:48:37 +0000 Received: from localhost ([127.0.0.1]:46460 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qeyKD-0002RI-8n for submit@debbugs.gnu.org; Sat, 09 Sep 2023 09:48:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35816) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qeyK9-0002Qp-8K for 65546@debbugs.gnu.org; Sat, 09 Sep 2023 09:48:35 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeyK0-0005Cf-SI; Sat, 09 Sep 2023 09:48:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-Reply-To:Date:References:Subject:To: From; bh=T0XyricgZn+OrJlvvkUXDPqhA9+HdFxt7lJjiNvEICM=; b=NDnabhOKZCulImFQXbmt Dzl5nd2uGRbLjoh3irHz0aCmQl6ry+iTzFCp5TGa7Q0C7HF1Ls8oV1Zlf0pMjClCPM7aHRNEwThcJ U61JZrnYP1KHgF1P2cYQaDEupJ5BZ3LeVcp4yFOLbUwiIDW57YJA4wTcPiZ5yE4zFpVN7F0gEyIqE C6QF2P+wTp1X+MkyXtmhYJbXl+h3B/b7G7zV5A7HvQviNOH/5+9uzCZW6t70grMexgOD5+h7L/bQM Kow/mxdnI0cJFzKY62Ak4nl5M7j1NoJvBeBJbvr6PQZmqoDHDBZRVD0fLghNQIJlBorfnodSJr79/ iveKUTD4HADyjA==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= References: <20230826063655.2227-1-julien@lepiller.eu> Date: Sat, 09 Sep 2023 15:48:23 +0200 In-Reply-To: <20230826063655.2227-1-julien@lepiller.eu> (Julien Lepiller's message of "Sat, 26 Aug 2023 08:36:55 +0200") Message-ID: <87wmwzwj88.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Scanner: mx2.migadu.com X-Spam-Score: -6.83 X-Migadu-Queue-Id: E4B6B3C974 X-Migadu-Spam-Score: -6.83 X-TUID: 6y4D4mr8QpiK Hi Julien, Julien Lepiller 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, su= ch 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 =E2=80=98terminal-columns=E2=80=99 (making sure =E2=80=98pointer->procedure= =E2=80=99 is called only once rather than once per call), and with a test or two in =E2=80=98tests/syscalls.scm=E2=80=99? For clarity, perhaps rename it to =E2=80=98terminal-string-width=E2=80=99? TIA! Ludo=E2=80=99.