(self, prompt, **kwargs)
| 135 | test_path = "\\".join([x.replace("\\", "") for x in test_path.split("\\\\")]) |
| 136 | |
| 137 | def grab(self, prompt, **kwargs): |
| 138 | # Takes a prompt, a default, and a timeout and shows it with that timeout |
| 139 | # returning the result |
| 140 | timeout = kwargs.get("timeout",0) |
| 141 | default = kwargs.get("default","") |
| 142 | if not self.interactive: |
| 143 | return default |
| 144 | # If we don't have a timeout - then skip the timed sections |
| 145 | if timeout <= 0: |
| 146 | try: |
| 147 | if sys.version_info >= (3, 0): |
| 148 | return input(prompt) |
| 149 | else: |
| 150 | return str(raw_input(prompt)) |
| 151 | except EOFError: |
| 152 | return default |
| 153 | # Write our prompt |
| 154 | sys.stdout.write(prompt) |
| 155 | sys.stdout.flush() |
| 156 | if os.name == "nt": |
| 157 | start_time = time.time() |
| 158 | i = '' |
| 159 | while True: |
| 160 | if msvcrt.kbhit(): |
| 161 | c = msvcrt.getche() |
| 162 | if ord(c) == 13: # enter_key |
| 163 | break |
| 164 | elif ord(c) >= 32: # space_char |
| 165 | i += c.decode() if sys.version_info >= (3,0) and isinstance(c,bytes) else c |
| 166 | else: |
| 167 | time.sleep(0.02) # Delay for 20ms to prevent CPU workload |
| 168 | if len(i) == 0 and (time.time() - start_time) > timeout: |
| 169 | break |
| 170 | else: |
| 171 | i, o, e = select.select( [sys.stdin], [], [], timeout ) |
| 172 | if i: |
| 173 | i = sys.stdin.readline().strip() |
| 174 | print('') # needed to move to next line |
| 175 | if len(i) > 0: |
| 176 | return i |
| 177 | else: |
| 178 | return default |
| 179 | |
| 180 | def cls(self): |
| 181 | if not self.interactive: |
no test coverage detected