Textualize / trogon

Easily turn your Click CLI into a powerful terminal application
MIT License
2.4k stars 54 forks source link

click and rich prompts interweave into system command prompt #46

Open apeaveysf opened 1 year ago

apeaveysf commented 1 year ago

System: Windows 10 (have not tried on Linux yet). Terminal: Windows Terminal set to Command Prompt.

When using @click.option with a prompt, the command prompt appears to interweave with the running program. Also occurs when using click.prompt() or rich's Prompt.ask() inside of the function definition.

Will cause the command prompt (such as "(venv) C:\py>") to be displayed throughout click prompts while program is running.

Sometimes will treat response to prompt as if trying to run a system command, sometimes will accept prompt input from the command prompt when the click prompt is not the active display.

As an example, the attached screenshot shows one run of a program through trogon, asking for 2 prompt inputs (a staff name, and an email address). The greenish-yellow squares show the command prompt appearing inside of the running trogon program.

No such problems occur when directly running the click program without trogon. No issues occur if provide the option values in trogon and/or bypass prompts inside program. Have tried on several different functions.

tui

EDIT: Minimal viable product:

mvp.py:

import click

from trogon import tui

@tui()
@click.group()
def cli():
    pass

@click.command()
@click.option('--name', prompt="Name")
def minimal(name):
    """Prompt for a name."""
    pass

cli.add_command(minimal)

if __name__ == '__main__':
    cli()

setup.py:

from setuptools import setup, find_packages

setup(
    name='mvp',
    version='0.1',
    py_modules=['mvp'],
    install_requires=[
        'Click'
    ],
    packages=find_packages(),
    entry_points='''
        [console_scripts]
        mvp=mvp:cli
    ''',
)

Example application run: image

darrenburns commented 1 year ago

Thanks for the report

I haven't been able to reproduce this on MacOS - so it may be a Windows issue.

Does it only happen on command prompt?

apeaveysf commented 1 year ago

Thanks for the report

I haven't been able to reproduce this on MacOS - so it may be a Windows issue.

That was all from my work computer.

Just tried on windows 10 on home computer and experienced all the same issues.

Tried from a Linux install and all the problems disappeared.

Can confirm it appears to be a Windows issue.

Edit: all windows attempts were after pip installing . Using Windows Terminal from the windows store (with windows terminal set to use command prompt. I did not attempt using PowerShell)

timb82 commented 10 months ago

I'm getting same issue on Windows 10 with command line prompt run both as CMD and in Windows terminal. I've checked in Powershell too and this behavior completely freezez the PS.

ddsmit commented 9 months ago

I can confirm that Windows 10 running Powershell in Windows Terminal has this issue for me too.