Skip to content

Commit

Permalink
add interrupt handler
Browse files Browse the repository at this point in the history
  • Loading branch information
seamile committed Jun 20, 2023
1 parent 4e6a264 commit ef7c1be
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions jsonfmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from io import TextIOBase
from pydoc import pager
from shutil import get_terminal_size
from signal import signal, SIGINT
from sys import stdin, stdout, stderr, exit as sys_exit
from typing import Any, List, IO, Optional, Sequence, Tuple, Union
from unittest.mock import patch
Expand Down Expand Up @@ -278,6 +279,14 @@ def parse_cmdline_args(args: Optional[Sequence[str]] = None):
return parser.parse_args(args)


def handle_interrupt(signum, _):
print_err('user canceled!')
sys_exit(0)


signal(SIGINT, handle_interrupt)


def main():
args = parse_cmdline_args()

Expand Down

0 comments on commit ef7c1be

Please sign in to comment.