From 186929d217a1e9fbee1ec40f800e6fe0904a6a53 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 26 Jun 2015 15:26:44 -0400 Subject: [PATCH] Only conditionally import readline If stdout is not a tty, do not import readline. import readline by itself can cause terminal control characters to appear in the stdout. Avoid this by only importing if there seems to be a sign it is connected to a terminal. --- confluent_client/bin/confetty | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/confluent_client/bin/confetty b/confluent_client/bin/confetty index 2e65054c..8cbdaa29 100755 --- a/confluent_client/bin/confetty +++ b/confluent_client/bin/confetty @@ -46,7 +46,6 @@ import math import getpass import optparse import os -import readline import select import shlex import socket @@ -601,9 +600,11 @@ except socket.gaierror: # sys.stdout.write('\x1b[H\x1b[J') # sys.stdout.flush() -readline.parse_and_bind("tab: complete") -readline.parse_and_bind("set bell-style none") -readline.set_completer(completer) +if sys.stdout.isatty(): + import readline + readline.parse_and_bind("tab: complete") + readline.parse_and_bind("set bell-style none") + readline.set_completer(completer) doexit = False inconsole = False pendingcommand = ""