8000 echo_via_pager with generators leaves terminal in broken state · Issue #2674 · pallets/click · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
echo_via_pager with generators leaves terminal in broken state #2674
Closed
@0xDEC0DE

Description

@0xDEC0DE

Steps to reproduce

Run the following test case:

import click

def output_generator():
    counter = 0
    while True:
        yield "this is a line of output\n"
        if counter == 1024:
            click.echo("kaboom", err=True)
            click.get_current_context().exit(0)
        counter += 1

@click.command
def kaboom():
    click.echo_via_pager(output_generator)

if __name__ == "__main__":
    kaboom()

Attempt to use the terminal afterwards

Expected result

A working terminal.

Actual behavior

Newlines and output are obscured. Commands may be entered, but they are not displayed.

Workaround

Run the reset command after the command terminates.

Environment:

Reproducible on OS X and Ubuntu (x86_64):

$ sw_vers
ProductName:            macOS
ProductVersion:         14.3.1
BuildVersion:           23D60
  • Python version: 3.11.2
  • Click version: 8.1.7
# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.3 LTS"
  • Python version: 3.10.12
  • Click version: 8.1.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0