Skip to content

Commit 75904c9

Browse files
committed
Add --hide-unmonitored arg to frontend
Signed-off-by: Blake McHale <[email protected]>
1 parent 0f35afb commit 75904c9

File tree

3 files changed

+90
-5
lines changed

3 files changed

+90
-5
lines changed

greenwave_monitor/greenwave_monitor/ncurses_frontend.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
with real-time diagnostics including publication rates, latency, and status.
2525
"""
2626

27+
import argparse
2728
import curses
2829
import signal
2930
import threading
@@ -40,7 +41,7 @@
4041
class GreenwaveNcursesFrontend(Node):
4142
"""Ncurses frontend for Greenwave Monitor."""
4243

43-
def __init__(self):
44+
def __init__(self, hide_unmonitored: bool = False):
4445
"""Initialize the ncurses frontend node."""
4546
super().__init__('greenwave_ncurses_frontend')
4647

@@ -59,7 +60,7 @@ def __init__(self):
5960
self.input_buffer = ''
6061
self.status_message = ''
6162
self.status_timeout = 0
62-
self.show_only_monitored = False
63+
self.show_only_monitored = hide_unmonitored
6364

6465
# Initialize UI adaptor
6566
self.ui_adaptor = GreenwaveUiAdaptor(self)
@@ -448,10 +449,31 @@ def curses_main(stdscr, node):
448449
stdscr.refresh()
449450

450451

452+
def parse_args():
453+
"""Parse command-line arguments."""
454+
parser = argparse.ArgumentParser(
455+
description='Ncurses-based frontend for Greenwave Monitor',
456+
add_help=False
457+
)
458+
parser.add_argument(
459+
'--help',
460+
action='help',
461+
default=argparse.SUPPRESS,
462+
help='Show this help message and exit'
463+
)
464+
parser.add_argument(
465+
'--hide-unmonitored',
466+
action='store_true',
467+
help='Hide unmonitored topics on initialization'
468+
)
469+
return parser.parse_known_args()
470+
471+
451472
def main(args=None):
452473
"""Entry point for the ncurses frontend application."""
453-
rclpy.init(args=args)
454-
node = GreenwaveNcursesFrontend()
474+
parsed_args, ros_args = parse_args()
475+
rclpy.init(args=ros_args)
476+
node = GreenwaveNcursesFrontend(hide_unmonitored=parsed_args.hide_unmonitored)
455477
thread = None
456478

457479
def signal_handler(signum, frame):

greenwave_monitor/scripts/ncurses_dashboard

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# Parse command line arguments
2424
DEMO_MODE=false
2525
LOG_DIR=""
26+
HIDE_UNMONITORED=false
2627
MONITOR_ARGS=()
2728

2829
show_help() {
@@ -33,6 +34,7 @@ show_help() {
3334
echo "OPTIONS:"
3435
echo " --demo, --test Launch demo publisher nodes for testing"
3536
echo " --log-dir DIR Enable logging to specified directory"
37+
echo " --hide-unmonitored Hide unmonitored topics on initialization"
3638
echo " --help, -h Show this help message"
3739
echo ""
3840
echo "MONITOR_ARGS are passed directly to the greenwave_monitor node"
@@ -56,6 +58,10 @@ while [[ $# -gt 0 ]]; do
5658
LOG_DIR="$2"
5759
shift 2
5860
;;
61+
--hide-unmonitored)
62+
HIDE_UNMONITORED=true
63+
shift
64+
;;
5965
--help|-h)
6066
show_help
6167
exit 0
@@ -115,7 +121,11 @@ echo "Monitor process started with PID: $MONITOR_PID"
115121
# Launch ncurses frontend in the foreground
116122
echo "Starting ncurses TUI..."
117123
echo "Controls: a=Add Topic, r=Remove, f=Set Frequency, c=Clear Freq, q=Quit"
118-
python3 -m greenwave_monitor.ncurses_frontend
124+
FRONTEND_ARGS=()
125+
if [ "$HIDE_UNMONITORED" = "true" ]; then
126+
FRONTEND_ARGS+=("--hide-unmonitored")
127+
fi
128+
python3 -m greenwave_monitor.ncurses_frontend "${FRONTEND_ARGS[@]}"
119129

120130
# Note: We don't need to explicitly exit here because the trap will handle cleanup
121131
# when the ncurses frontend exits
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env python3
2+
3+
# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
4+
# Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
# SPDX-License-Identifier: Apache-2.0
19+
20+
"""Tests for ncurses frontend argument parsing."""
21+
22+
import sys
23+
24+
25+
class TestParseArgs:
26+
"""Test argument parsing for ncurses frontend."""
27+
28+
def test_default_hide_unmonitored_false(self, monkeypatch):
29+
"""Test that hide_unmonitored defaults to False."""
30+
monkeypatch.setattr(sys, 'argv', ['ncurses_frontend'])
31+
from greenwave_monitor.ncurses_frontend import parse_args
32+
parsed_args, _ = parse_args()
33+
assert parsed_args.hide_unmonitored is False
34+
35+
def test_hide_unmonitored_long_flag(self, monkeypatch):
36+
"""Test --hide-unmonitored flag enables hide_unmonitored."""
37+
monkeypatch.setattr(sys, 'argv', ['ncurses_frontend', '--hide-unmonitored'])
38+
from greenwave_monitor.ncurses_frontend import parse_args
39+
parsed_args, _ = parse_args()
40+
assert parsed_args.hide_unmonitored is True
41+
42+
def test_ros_args_passthrough(self, monkeypatch):
43+
"""Test that ROS arguments are passed through."""
44+
monkeypatch.setattr(
45+
sys, 'argv',
46+
['ncurses_frontend', '--hide-unmonitored', '--ros-args', '-r', '__node:=my_node']
47+
)
48+
from greenwave_monitor.ncurses_frontend import parse_args
49+
parsed_args, ros_args = parse_args()
50+
assert parsed_args.hide_unmonitored is True
51+
assert '--ros-args' in ros_args
52+
assert '-r' in ros_args
53+
assert '__node:=my_node' in ros_args

0 commit comments

Comments
 (0)