pw_watch: Use prompt_toolkit instead of input

Bug: b/247553978
Change-Id: I1b7fd4872b6da7e9b40fc3e38f297c1d874b9dcd
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/111311
Pigweed-Auto-Submit: Anthony DiGirolamo <tonymd@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
diff --git a/pw_watch/py/pw_watch/watch.py b/pw_watch/py/pw_watch/watch.py
index 445a33b..c057b81 100755
--- a/pw_watch/py/pw_watch/watch.py
+++ b/pw_watch/py/pw_watch/watch.py
@@ -66,6 +66,7 @@
 from watchdog.events import FileSystemEventHandler  # type: ignore[import]
 from watchdog.observers import Observer  # type: ignore[import]
 
+from prompt_toolkit import prompt
 from prompt_toolkit.formatted_text.base import OneStyleAndTextTuple
 from prompt_toolkit.formatted_text import StyleAndTextTuples
 
@@ -231,7 +232,7 @@
             self.wait_for_keypress_thread.start()
 
     def rebuild(self):
-        """ Rebuild command triggered from watch app."""
+        """Rebuild command triggered from watch app."""
         self._current_build.terminate()
         self._current_build.wait()
         self.debouncer.press('Manual build requested')
@@ -239,14 +240,14 @@
     def _wait_for_enter(self) -> NoReturn:
         try:
             while True:
-                _ = input()
-                self._current_build.terminate()
-                self._current_build.wait()
-
-                self.debouncer.press('Manual build requested...')
+                _ = prompt('')
+                self.rebuild()
         # Ctrl-C on Unix generates KeyboardInterrupt
         # Ctrl-Z on Windows generates EOFError
         except (KeyboardInterrupt, EOFError):
+            # Force stop any running ninja builds.
+            if self._current_build:
+                self._current_build.terminate()
             _exit_due_to_interrupt()
 
     def _path_matches(self, path: Path) -> bool:
@@ -675,6 +676,7 @@
 def _exit_due_to_interrupt() -> NoReturn:
     # To keep the log lines aligned with each other in the presence of
     # a '^C' from the keyboard interrupt, add a newline before the log.
+    print('')
     _LOG.info('Got Ctrl-C; exiting...')
     _exit(0)