canonical / craft-cli

https://canonical-craft-cli.readthedocs-hosted.com/en/latest/
GNU Lesser General Public License v3.0
9 stars 15 forks source link

Tabs cause a emitter to reprint the same line repeatedly #182

Open mr-cal opened 11 months ago

mr-cal commented 11 months ago

Bug Description

If there is a tab in an emitter message, it causes the line to be reprinted every time the spinner spins.

To Reproduce

from craft_cli import EmitterMode, emit
from pathlib import Path
from time import sleep

emit.init(
    mode=EmitterMode.TRACE,
    appname="test",
    greeting="hello",
    log_filepath=Path("log.txt"),
    streaming_brief=True,
)

emit.progress("\tmessage")
sleep(5)

part yaml

No response

Relevant log output

Expected output

2023-10-04 11:30:18.460 hello
2023-10-04 11:30:18.460 Logging execution to 'log.txt'
2023-10-04 11:30:18.460     message \ (4.9s)

Actual output

2023-10-04 11:28:58.446 hello
2023-10-04 11:28:58.446 Logging execution to 'log.txt'
2023-10-04 11:28:58.446     message2023-10-04 11:28:58.446  message - (2.0s)2023-10-04 11:28:58.446     message \ (2.1s)2023-10-04 11:28:58.446     message | (2.2s)2023-10-04 11:28:58.446     message / (2.3s)2023-10-04 11:28:58.446     message - (2.4s)2023-10-04 11:28:58.446     message \ (2.5s)2023-10-04 11:28:58.446     message | (2.6s)2023-10-04 11:28:58.446     message / (2.7s)2023-10-04 11:28:58.446     message - (2.8s)2023-10-04 11:28:58.446     message \ (2.9s)2023-10-04 11:28:58.446     message | (3.0s)2023-10-04 11:28:58.446     message / (3.1s)2023-10-04 11:28:58.446     message - (3.2s)2023-10-04 11:28:58.446     message \ (3.3s)2023-10-04 11:28:58.446     message | (3.4s)2023-10-04 11:28:58.446     message / (3.5s)2023-10-04 11:28:58.446     message - (3.6s)2023-10-04 11:28:58.446     message \ (3.7s)2023-10-04 11:28:58.446     message | (3.8s)2023-10-04 11:28:58.446     message / (3.9s)2023-10-04 11:28:58.446     message - (4.0s)2023-10-04 11:28:58.446     message \ (4.1s)2023-10-04 11:28:58.446     message | (4.2s)2023-10-04 11:28:58.446     message / (4.3s)2023-10-04 11:28:58.446     message - (4.4s)2023-10-04 11:28:58.446     message \ (4.5s)2023-10-04 11:28:58.446     message | (4.6s)2023-10-04 11:28:58.446     message / (4.7s)2023-10-04 11:28:58.446     message - (4.8s)2023-10-04 11:28:58.446     message \ (4.9s)

The above displays normally (see picture attached) but it copy/pastes like there are no newlines. Screenshot_20231004_113327

tigarmo commented 11 months ago

Thanks for reporting! Out of curiosity, what is the size of the tab in the environment where you are running this? This issue rings a bell

On Wed, Oct 4, 2023, 13:32 Callahan @.***> wrote:

Bug Description

If there is a tab in an emitter message, it causes the line to be reprinted every time the spinner spins. To Reproduce

from craft_cli import EmitterMode, emitfrom pathlib import Pathfrom time import sleep emit.init( mode=EmitterMode.TRACE, appname="test", greeting="hello", log_filepath=Path("log.txt"), streaming_brief=True, ) emit.progress("message")sleep(5)

part yaml

No response Relevant log output

Expected output

2023-10-04 11:30:18.460 hello 2023-10-04 11:30:18.460 Logging execution to 'log.txt' 2023-10-04 11:30:18.460 message \ (4.9s)

Actual output

2023-10-04 11:28:58.446 hello 2023-10-04 11:28:58.446 Logging execution to 'log.txt' 2023-10-04 11:28:58.446 message2023-10-04 11:28:58.446 message - (2.0s)2023-10-04 11:28:58.446 message \ (2.1s)2023-10-04 11:28:58.446 message | (2.2s)2023-10-04 11:28:58.446 message / (2.3s)2023-10-04 11:28:58.446 message - (2.4s)2023-10-04 11:28:58.446 message \ (2.5s)2023-10-04 11:28:58.446 message | (2.6s)2023-10-04 11:28:58.446 message / (2.7s)2023-10-04 11:28:58.446 message - (2.8s)2023-10-04 11:28:58.446 message \ (2.9s)2023-10-04 11:28:58.446 message | (3.0s)2023-10-04 11:28:58.446 message / (3.1s)2023-10-04 11:28:58.446 message - (3.2s)2023-10-04 11:28:58.446 message \ (3.3s)2023-10-04 11:28:58.446 message | (3.4s)2023-10-04 11:28:58.446 message / (3.5s)2023-10-04 11:28:58.446 message - (3.6s)2023-10-04 11:28:58.446 message \ (3.7s)2023-10-04 11:28:58.446 message | (3.8s)2023-10-04 11:28:58.446 message / (3.9s)2023-10-04 11:28:58.446 message - (4.0s)2023-10-04 11:28:58.446 message \ (4.1s)2023-10-04 11:28:58.446 message | (4.2s)2023-10-04 11:28:58.446 message / (4.3s)2023-10-04 11:28:58.446 message - (4.4s)2023-10-04 11:28:58.446 message \ (4.5s)2023-10-04 11:28:58.446 message | (4.6s)2023-10-04 11:28:58.446 message / (4.7s)2023-10-04 11:28:58.446 message - (4.8s)2023-10-04 11:28:58.446 message \ (4.9s)

— Reply to this email directly, view it on GitHub https://github.com/canonical/craft-cli/issues/182, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAO4MQYN5MTZCIF26CI6NZDX5WFRBAVCNFSM6AAAAAA5S5DBKKVHI2DSMVQWIX3LMV43ASLTON2WKOZRHEZDMNJZGMYTSMQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

mr-cal commented 11 months ago

Thanks for reporting! Out of curiosity, what is the size of the tab in the environment where you are running this? This issue rings a bell

A tab evaluates to 8 spaces in my bash environment.

lengau commented 7 months ago

This is a side-effect of the fact that the emitter is printing spaces for the rest of the line. #210 fixes it.