From 964ffadc8e3f4aa227ce875906c11f5692f179e1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 8 Mar 2018 13:37:56 +0530 Subject: [PATCH] DRYer --- kitty/utils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kitty/utils.py b/kitty/utils.py index 9317e13df..c7a14e18b 100644 --- a/kitty/utils.py +++ b/kitty/utils.py @@ -280,6 +280,12 @@ def parse_address_spec(spec): return family, address, socket_path +def make_fd_non_blocking(fd): + oldfl = fcntl.fcntl(fd, fcntl.F_GETFL) + fcntl.fcntl(fd, fcntl.F_SETFL, oldfl | os.O_NONBLOCK) + return oldfl + + @contextmanager def non_blocking_read(src=sys.stdin): import termios @@ -289,8 +295,7 @@ def non_blocking_read(src=sys.stdin): if src.isatty(): old = termios.tcgetattr(fd) tty.setraw(fd) - oldfl = fcntl.fcntl(fd, fcntl.F_GETFL) - fcntl.fcntl(fd, fcntl.F_SETFL, oldfl | os.O_NONBLOCK) + oldfl = make_fd_non_blocking(fd) yield fd if src.isatty(): termios.tcsetattr(fd, termios.TCSADRAIN, old)