Browse code

Allowing hostname to be 255chars length instead of 24.

Mahmoud Bassiouny authored on 2015/07/17 06:45:41
Showing 1 changed files
... ...
@@ -23,15 +23,17 @@ class ReadText(Action):
23 23
         self.ispassword = ispassword
24 24
         self.confirm_pass = confirm_pass;
25 25
         
26
-        self.init_text()        
26
+        self.textwin_width = self.textwin.getmaxyx()[1] - 1
27
+        self.visible_text_width = self.textwin_width - 1
28
+
29
+        self.init_text()
30
+        self.maxlength = 255        
27 31
 
28 32
         #initialize the accepted characters
29 33
         if self.ispassword:
30
-            self.maxlength = self.textwin.getmaxyx()[1] - 2
31 34
             # Adding all the letters
32 35
             self.accepted_chars = range(33, 127)
33 36
         else:
34
-            self.maxlength = 24
35 37
 
36 38
             self.alpha_chars = range(65, 91)
37 39
             self.alpha_chars.extend(range(97,123))
... ...
@@ -49,12 +51,12 @@ class ReadText(Action):
49 49
     def init_text(self):
50 50
         self.x = 0;
51 51
         #initialize the ----
52
-        dashes = '_' * (self.textwin.getmaxyx()[1] - 1)
52
+        dashes = '_' * self.textwin_width
53 53
         self.textwin.addstr(self.y, 0, dashes)
54 54
         self.str = ''
55 55
 
56 56
         #remove the error messages
57
-        spaces = ' ' * (self.textwin.getmaxyx()[1] - 1)
57
+        spaces = ' ' * self.textwin_width
58 58
         self.textwin.addstr(self.y + 2, 0, spaces)
59 59
 
60 60
     def do_action(self):
... ...
@@ -62,7 +64,11 @@ class ReadText(Action):
62 62
         curses.curs_set(1)
63 63
 
64 64
         while True:
65
-            ch = self.textwin.getch(self.y, self.x)
65
+            if len(self.str) > self.visible_text_width:
66
+                curs_loc = self.visible_text_width
67
+            else:
68
+                curs_loc = len(self.str)
69
+            ch = self.textwin.getch(self.y, curs_loc)
66 70
 
67 71
             if ch in [curses.KEY_ENTER, ord('\n')]:
68 72
                 if self.confirm_pass:
... ...
@@ -94,18 +100,24 @@ class ReadText(Action):
94 94
                 return ActionResult(False, None)
95 95
             elif ch == 127:
96 96
                 # Handle the backspace case
97
-                self.x -= 1
98
-                if self.x < 0:
99
-                    self.x = 0
100
-                self.textwin.addch(self.y, self.x, ord('_'))
101 97
                 self.str = self.str[:len(self.str) - 1]
102
-            elif self.x < self.maxlength and ch in self.accepted_chars:
103
-                if (self.ispassword):
104
-                    self.textwin.echochar(ord('*'))
105
-                else:
106
-                    self.textwin.echochar(ch)
98
+
99
+                update_text = True
100
+
101
+            elif len(self.str) < self.maxlength and ch in self.accepted_chars:
107 102
                 self.str += chr(ch)
108
-                self.x += 1
103
+                update_text = True
104
+
105
+            if update_text:
106
+                if len(self.str) > self.visible_text_width:
107
+                    text = self.str[-self.visible_text_width:]
108
+                else:
109
+                    text = self.str
110
+                if self.ispassword:
111
+                    text = '*' * len(text)
112
+                # Add the dashes
113
+                text = text + '_' * (self.visible_text_width - len(self.str))
114
+                self.textwin.addstr(self.y, 0, text)
109 115
 
110 116
     def validate_hostname(self, hostname):
111 117
         if (hostname == None or len(hostname) == 0):