pyinfra icon indicating copy to clipboard operation
pyinfra copied to clipboard

CJK chracters causing result table columns to shift

Open JokerQyou opened this issue 4 months ago • 1 comments

Describe the bug

When file / directory names contains CJK chracters, each chracter takes space of two ASCII chracters, the table header does not take this into account, and sometimes may causing confusion.

To Reproduce

Run the following command to reproduce:

pyinfra hosts/test-machine.py exec -- echo 随便输出一些中文试试
--> Loading config...
--> Loading inventory...
--> Connecting to hosts...
    [x64.test-machine] Connected

--> Preparing exec operation...
    [x64.test-machine] Ready: shell

--> Beginning operation run...
--> Starting operation: server.shell (echo 随便输出一些中文试试)
[x64.test-machine] 随便输出一些中文试试
    [x64.test-machine] Success

--> Results:
    Operation                        Hosts   Success   Error   No Change
    server.shell (echo 随便输出一些中文试试)   1       1         -       -
    Grand total                      1       1         -       -

--> Disconnecting from hosts...

You can see in the Results table, the server.shell line does not match table header, and might confuse user into thinking the command has failed.

Image

Expected behavior

I expect the table header columns to shift to the right, each column should use the longest vallue of that field to decide its position.

Alternatively, it might help to render the table with cell borders.

Meta

Pyinfra support meta:

    System: Darwin
      Platform: macOS-14.7.6-arm64-arm-64bit
      Release: 23.6.0
      Machine: arm64
    pyinfra: v3.4.1
      click: v8.1.7
      click: v8.1.7
      click: v8.1.7
      distro: v1.8.0
      gevent: v23.9.1
      jinja2: v3.1.2
      packaging: v25.0
      paramiko: v2.12.0
      python-dateutil: v2.8.2
      pywinrm: v0.4.3
      typeguard: v4.4.4
      typing-extensions: v4.14.1
      wheel: v0.42.0
    Executable: ~/.miniforge3/envs/<redacted>/bin/pyinfra
    Python: 3.12.0 (CPython, Clang 15.0.7 )

JokerQyou avatar Aug 23 '25 03:08 JokerQyou

Nice catch! So the table printing is… super basic, I hacked it together and never looked at it since, would definitely be improved using something more robust like rich.

Fizzadar avatar Sep 12 '25 11:09 Fizzadar