MCPcopy Index your code
hub / github.com/USBToolBox/tool / grab

Method grab

Scripts/utils.py:30–61  ·  view source on GitHub ↗
(self, prompt, **kwargs)

Source from the content-addressed store, hash-verified

28 os.chdir(cwd)
29
30 def grab(self, prompt, **kwargs):
31 # Takes a prompt, a default, and a timeout and shows it with that timeout
32 # returning the result
33 timeout = kwargs.get("timeout", 0)
34 default = kwargs.get("default", None)
35 # If we don't have a timeout - then skip the timed sections
36 if timeout <= 0:
37 return input(prompt)
38 # Write our prompt
39 sys.stdout.write(prompt)
40 sys.stdout.flush()
41 if os.name == "nt":
42 start_time = time.time()
43 i = ""
44 while True:
45 if msvcrt.kbhit():
46 c = msvcrt.getche()
47 if ord(c) == 13: # enter_key
48 break
49 elif ord(c) >= 32: # space_char
50 i += c.decode("utf-8")
51 if len(i) == 0 and (time.time() - start_time) > timeout:
52 break
53 else:
54 i, o, e = select.select([sys.stdin], [], [], timeout)
55 if i:
56 i = sys.stdin.readline().strip()
57 print("") # needed to move to next line
58 if len(i) > 0:
59 return i
60 else:
61 return default
62
63 def cls(self):
64 os.system("cls" if os.name == "nt" else "clear")

Callers 1

discover_portsMethod · 0.80

Calls 1

selectMethod · 0.80

Tested by

no test coverage detected