From 00da61b981fdb094460ca9787c3b2913e576f85b Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 3 Aug 2016 13:49:27 -0400 Subject: [PATCH] Enable backspace for ssh user/pass prompt When prompting for username and password, make backspace work fine. --- confluent_server/confluent/plugins/shell/ssh.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/confluent_server/confluent/plugins/shell/ssh.py b/confluent_server/confluent/plugins/shell/ssh.py index 331a4a5a..67ca12f2 100644 --- a/confluent_server/confluent/plugins/shell/ssh.py +++ b/confluent_server/confluent/plugins/shell/ssh.py @@ -117,6 +117,13 @@ class SshShell(conapi.Console): def write(self, data): if self.inputmode == 0: + while len(data) > 0 and data[0] == b'\x7f': + self.datacallback('\b \b') # erase previously echoed value + self.username = self.username[:-1] + data = data[1:] + while b'\x7f' in data: + delidx = data.index(b'\x7f') + data = data[:delidx - 1] + data[delidx + 1:] self.username += data if '\r' in self.username: self.username, self.password = self.username.split('\r') @@ -125,10 +132,16 @@ class SshShell(conapi.Console): self.datacallback(lastdata) self.datacallback('\r\nEnter password: ') self.inputmode = 1 - else: + elif len(data) > 0: # echo back typed data self.datacallback(data) elif self.inputmode == 1: + while len(data) > 0 and data[0] == b'\x7f': + self.password = self.password[:-1] + data = data[1:] + while b'\x7f' in data: + delidx = data.index(b'\x7f') + data = data[:delidx - 1] + data[delidx + 1:] self.password += data if '\r' in self.password: self.password = self.password.split('\r')[0]