aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElaine Hwang <elainehwang@google.com>2022-03-04 16:47:23 +0800
committerCQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-03-31 02:39:40 +0000
commitb7ed839321e377847aa4a9d1842d5c25409631b5 (patch)
treeea878fb2a3d8ff5a63a008a6e225202ae0185fa8
parentba414d66e44e6932c34d90210cb691a47b79a2c8 (diff)
downloadpigweed-b7ed839321e377847aa4a9d1842d5c25409631b5.tar.gz
pw_watch: Fix watch_app styling for highlighting text and showing result
Change-Id: Ifce84bf9650ae216a9324767eac57fb49f6b81c6 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/86560 Reviewed-by: Anthony DiGirolamo <tonymd@google.com> Reviewed-by: Wyatt Hepler <hepler@google.com> Commit-Queue: Elaine Hwang <elainehwang@google.com>
-rw-r--r--pw_console/py/pw_console/style.py2
-rwxr-xr-xpw_watch/py/pw_watch/watch.py91
-rw-r--r--pw_watch/py/pw_watch/watch_app.py26
3 files changed, 78 insertions, 41 deletions
diff --git a/pw_console/py/pw_console/style.py b/pw_console/py/pw_console/style.py
index 19d41820d..da252b478 100644
--- a/pw_console/py/pw_console/style.py
+++ b/pw_console/py/pw_console/style.py
@@ -192,7 +192,7 @@ class AnsiTerm:
inactive_bg = 'default'
inactive_fg = 'default'
- line_highlight_bg = 'default underline'
+ line_highlight_bg = 'ansidarkgray white'
selected_line_bg = 'default reverse'
dialog_bg = 'default'
diff --git a/pw_watch/py/pw_watch/watch.py b/pw_watch/py/pw_watch/watch.py
index 273857060..8f3d29152 100755
--- a/pw_watch/py/pw_watch/watch.py
+++ b/pw_watch/py/pw_watch/watch.py
@@ -63,6 +63,7 @@ from watchdog.events import FileSystemEventHandler # type: ignore[import]
from watchdog.observers import Observer # type: ignore[import]
from prompt_toolkit.formatted_text.base import OneStyleAndTextTuple
+from prompt_toolkit.formatted_text import StyleAndTextTuples
import pw_cli.branding
import pw_cli.color
@@ -187,6 +188,7 @@ class PigweedBuildWatcher(FileSystemEventHandler, DebouncedFunction):
self.banners = banners
self.status_message: Optional[OneStyleAndTextTuple] = None
+ self.result_message: Optional[StyleAndTextTuples] = None
self.current_stdout = ''
self.current_build_step = ''
self.current_build_percent = 0.0
@@ -216,10 +218,10 @@ class PigweedBuildWatcher(FileSystemEventHandler, DebouncedFunction):
self.wait_for_keypress_thread.start()
def rebuild(self):
- """ Manual 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...')
+ self.debouncer.press('Manual build requested')
def _wait_for_enter(self) -> NoReturn:
try:
@@ -267,6 +269,8 @@ class PigweedBuildWatcher(FileSystemEventHandler, DebouncedFunction):
log_message = f'File change detected: {os.path.relpath(matching_path)}'
if self.restart_on_changes:
+ if self.fullscreen_enabled and self.watch_app:
+ self.watch_app.rebuild_on_filechange()
self.debouncer.press(f'{log_message} Triggering build...')
else:
_LOG.info('%s ; not rebuilding', log_message)
@@ -287,11 +291,16 @@ class PigweedBuildWatcher(FileSystemEventHandler, DebouncedFunction):
# Clear the screen and show a banner indicating the build is starting.
self._clear_screen()
- for line in pw_cli.branding.banner().splitlines():
- _LOG.info(line)
- _LOG.info(
- _COLOR.green(
- ' Watching for changes. Ctrl-C to exit; enter to rebuild'))
+ if self.fullscreen_enabled:
+ msg = 'Watching for changes. Ctrl-C to exit; enter to rebuild'
+ self.result_message = [('', msg)]
+ else:
+ for line in pw_cli.branding.banner().splitlines():
+ _LOG.info(line)
+ _LOG.info(
+ _COLOR.green(
+ ' Watching for changes. Ctrl-C to exit; enter to rebuild')
+ )
_LOG.info('')
_LOG.info('Change detected: %s', self.matching_path)
@@ -432,38 +441,50 @@ class PigweedBuildWatcher(FileSystemEventHandler, DebouncedFunction):
self.status_message = ('ansired', 'Failed')
_LOG.info('Finished; some builds failed')
- # Then, show a more distinct colored banner.
- if not cancelled:
- # Write out build summary table so you can tell which builds passed
- # and which builds failed.
- _LOG.info('')
- _LOG.info(' .------------------------------------')
- _LOG.info(' |')
+ # Show individual build results for fullscreen app
+ if self.fullscreen_enabled:
+ self.result_message = []
for (succeeded, cmd) in zip(self.builds_succeeded,
self.build_commands):
- slug = (self.charset.slug_ok
- if succeeded else self.charset.slug_fail)
- _LOG.info(' | %s %s', slug, cmd)
- _LOG.info(' |')
- _LOG.info(" '------------------------------------")
- else:
- # Build was interrupted.
- _LOG.info('')
- _LOG.info(' .------------------------------------')
- _LOG.info(' |')
- _LOG.info(' | %s- interrupted', self.charset.slug_fail)
- _LOG.info(' |')
- _LOG.info(" '------------------------------------")
-
- # Show a large color banner so it is obvious what the overall result is.
- if all(self.builds_succeeded) and not cancelled:
- if self.banners:
- for line in _PASS_MESSAGE.splitlines():
- _LOG.info(_COLOR.green(line))
+ if succeeded:
+ self.result_message.append(
+ ('class:theme-fg-green', 'OK '))
+ else:
+ self.result_message.append(('class:theme-fg-red', 'FAIL'))
+ self.result_message.append(('', f' {cmd}\n'))
+ # For non-fullscreen pw watch
else:
+ # Show a more distinct colored banner.
+ if not cancelled:
+ # Write out build summary table so you can tell which builds
+ # passed and which builds failed.
+ _LOG.info('')
+ _LOG.info(' .------------------------------------')
+ _LOG.info(' |')
+ for (succeeded, cmd) in zip(self.builds_succeeded,
+ self.build_commands):
+ slug = (self.charset.slug_ok
+ if succeeded else self.charset.slug_fail)
+ _LOG.info(' | %s %s', slug, cmd)
+ _LOG.info(' |')
+ _LOG.info(" '------------------------------------")
+ else:
+ # Build was interrupted.
+ _LOG.info('')
+ _LOG.info(' .------------------------------------')
+ _LOG.info(' |')
+ _LOG.info(' | %s- interrupted', self.charset.slug_fail)
+ _LOG.info(' |')
+ _LOG.info(" '------------------------------------")
+
+ # Show a large color banner for the overall result.
if self.banners:
- for line in _FAIL_MESSAGE.splitlines():
- _LOG.info(_COLOR.red(line))
+ if all(self.builds_succeeded) and not cancelled:
+ for line in _PASS_MESSAGE.splitlines():
+ _LOG.info(_COLOR.green(line))
+ else:
+ for line in _FAIL_MESSAGE.splitlines():
+ _LOG.info(_COLOR.red(line))
if self.watch_app:
self.watch_app.redraw_ui()
diff --git a/pw_watch/py/pw_watch/watch_app.py b/pw_watch/py/pw_watch/watch_app.py
index c2bd96244..0f8c93f0f 100644
--- a/pw_watch/py/pw_watch/watch_app.py
+++ b/pw_watch/py/pw_watch/watch_app.py
@@ -44,6 +44,7 @@ from prompt_toolkit.layout import (
)
from prompt_toolkit.layout.controls import BufferControl
from prompt_toolkit.styles import DynamicStyle, merge_styles, Style
+from prompt_toolkit.formatted_text import StyleAndTextTuples
from pw_console.console_app import get_default_colordepth
from pw_console.console_prefs import ConsolePrefs
@@ -87,9 +88,7 @@ class WatchApp(PluginMixin):
# such as mouse drag resizing.
PW_CONSOLE_APP_CONTEXTVAR.set(self) # type: ignore
- theme_name = 'ansi'
- self.prefs = ConsolePrefs(project_file=False, user_file=False)
- self.prefs.set_ui_theme(theme_name)
+ self.prefs = ConsolePrefs()
key_bindings = KeyBindings()
@@ -162,7 +161,13 @@ class WatchApp(PluginMixin):
Window(
content=FormattedTextControl(self.get_statusbar_text),
height=Dimension.exact(1),
- style='',
+ style='class:toolbar_inactive',
+ ),
+ # Result Toolbar.
+ Window(
+ content=FormattedTextControl(self.get_resultbar_text),
+ height=lambda: len(self.event_handler.build_commands),
+ style='class:toolbar_inactive',
),
# The main content.
DynamicContainer(lambda: self.window_manager_container),
@@ -173,7 +178,8 @@ class WatchApp(PluginMixin):
key_bindings,
])
- self.current_theme = pw_console.style.generate_styles(theme_name)
+ self.current_theme = pw_console.style.generate_styles(
+ self.prefs.ui_theme)
self.current_theme = merge_styles([
self.current_theme,
Style.from_dict({'search': 'bg:ansired ansiblack'}),
@@ -233,6 +239,10 @@ class WatchApp(PluginMixin):
self.clear_ninja_log()
self.event_handler.rebuild()
+ def rebuild_on_filechange(self):
+ self.ninja_log_view.log_store.clear_logs()
+ self.ninja_log_view.view_mode_changed()
+
def get_statusbar_text(self):
status = self.event_handler.status_message
fragments = [('class:logo', 'Pigweed Watch')]
@@ -260,6 +270,12 @@ class WatchApp(PluginMixin):
return fragments
+ def get_resultbar_text(self) -> StyleAndTextTuples:
+ result = self.event_handler.result_message
+ if not result:
+ result = [('', 'Loading...')]
+ return result
+
def exit(self, exit_code: int) -> None:
log_file = self.external_logfile