diff --git a/cccli/printer.py b/cccli/printer.py index 4edd905ace5c3e67f00e5c8dd9e54104a964cc39..c13ec49c5c19a9e84a1c6195e9264c85c9518987 100644 --- a/cccli/printer.py +++ b/cccli/printer.py @@ -7,7 +7,9 @@ CloudControl CLI Printer module import sys import os -import getpass +import termios +import fcntl +import struct import cccli from cccli.exception import * @@ -118,7 +120,16 @@ class Printer(object): '''Ask for a password. No echo. Not in history''' if self.readline is None: raise cliError("Unable to ask a password in non-interactive mode") - return getpass.getpass(prompt) + fd = sys.stdin.fileno() + old = termios.tcgetattr(fd) + new = termios.tcgetattr(fd) + new[3] = new[3] & ~termios.ECHO + try: + termios.tcsetattr(fd, termios.TCSADRAIN, new) + passwd = raw_input(prompt) + finally: + termios.tcsetattr(fd, termios.TCSADRAIN, old) + return passwd def ask(self, prompt): '''Used to ask a question. Default answer not saved to history''' @@ -132,6 +143,15 @@ class Printer(object): self.history.load(h) return r + def get_term_size(self): + '''Return terminal size''' + if self.readline is None: + raise cliError("Unable to get term size in non-interactive mode") + req = struct.pack("HHHH", 0, 0, 0, 0) + resp = fcntl.ioctl(sys.stdin.fileno(), termios.TIOCGWINSZ, req) + rows, cols, px_x, px_y = struct.unpack("HHHH", resp) + return rows, cols + class History(object): '''History class'''