Skip to content

Ctrl-C in a pager causes program to quit #350

@amjith

Description

@amjith

I'm using echo_via_pager() in my program to display the output through a pager. But while I'm in the pager if Ctrl-C is pressed then system.exit(1) is called, without giving me an opportunity to handle it.

I'm using this inside a repl and I'd like to have the ability to handle Ctrl-C.

Here's an example to reproduce:

import click

@click.command()
@click.option('--foo', prompt=True)
def cli(foo):
    try:
        click.echo_via_pager('foo=%s' % foo)
    except click.Abort:
        print('Tada!')

If you run this example and press Ctrl-C while in the pager, it will print 'Aborted!' and quit the program, I'd expect to see the message 'Tada!' instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions