From b79647f36c1694e1b8b4a600fffb7bbf7c58b6b7 Mon Sep 17 00:00:00 2001 From: louisss1016 <245680232+louisss1016@users.noreply.github.com> Date: Thu, 5 Nov 2026 10:51:28 +0800 Subject: [PATCH] feat(cli): allow highlight row on click by default --- InteractiveHtmlBom/core/config.py | 8 ++++++- InteractiveHtmlBom/web/util.js | 2 +- tests/test_module.py | 40 +++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/InteractiveHtmlBom/core/config.py b/InteractiveHtmlBom/core/config.py index 55371e0e..790f9207 100644 --- a/InteractiveHtmlBom/core/config.py +++ b/InteractiveHtmlBom/core/config.py @@ -37,7 +37,8 @@ class Config: default_checkboxes = ['Sourced', 'Placed'] html_config_fields = [ 'dark_mode', 'show_pads', 'show_fabrication', 'show_silkscreen', - 'highlight_pin1', 'redraw_on_drag', 'board_rotation', 'checkboxes', + 'highlight_pin1', 'highlight_row_on_click', 'redraw_on_drag', + 'board_rotation', 'checkboxes', 'bom_view', 'layer_view', 'offset_back_rotation', 'kicad_text_formatting', 'mark_when_checked', 'custom_metadata' ] @@ -51,6 +52,7 @@ class Config: show_fabrication = False show_silkscreen = True redraw_on_drag = True + highlight_row_on_click = False highlight_pin1 = highlight_pin1_choices[0] board_rotation = 0 offset_back_rotation = False @@ -374,6 +376,9 @@ def add_options(cls, parser, version): choices=cls.highlight_pin1_choices, nargs='?', help='Highlight first pin.') + parser.add_argument('--highlight-row-on-click', + help='Highlight BOM rows on click by default.', + action='store_true') parser.add_argument('--no-redraw-on-drag', help='Do not redraw pcb on drag by default.', action='store_true') @@ -612,6 +617,7 @@ def set_from_args(self, args): self.show_fabrication = args.show_fabrication self.show_silkscreen = not args.hide_silkscreen self.highlight_pin1 = args.highlight_pin1 + self.highlight_row_on_click = args.highlight_row_on_click self.redraw_on_drag = not args.no_redraw_on_drag # Stored in 5 degree steps, wrap to -180..180 range self.board_rotation = args.board_rotation // 5 diff --git a/InteractiveHtmlBom/web/util.js b/InteractiveHtmlBom/web/util.js index 0d1d8da0..b7a46ac7 100644 --- a/InteractiveHtmlBom/web/util.js +++ b/InteractiveHtmlBom/web/util.js @@ -580,7 +580,7 @@ function initDefaults() { } initBooleanSetting("dnpOutline", false, "dnpOutlineCheckbox", dnpOutline); initBooleanSetting("redrawOnDrag", config.redraw_on_drag, "dragCheckbox", setRedrawOnDrag); - initBooleanSetting("highlightRowOnClick", false, "highlightRowOnClickCheckbox", setHighlightRowOnClick); + initBooleanSetting("highlightRowOnClick", config.highlight_row_on_click === true, "highlightRowOnClickCheckbox", setHighlightRowOnClick); initBooleanSetting("darkmode", config.dark_mode, "darkmodeCheckbox", setDarkMode); var fields = ["checkboxes", "References"].concat(config.fields).concat(["Quantity"]); diff --git a/tests/test_module.py b/tests/test_module.py index 231b2aae..7d97b076 100644 --- a/tests/test_module.py +++ b/tests/test_module.py @@ -1,2 +1,42 @@ +import json +import os +from pathlib import Path +import re +import subprocess +import sys + +import pytest + + def test_module_import(): import InteractiveHtmlBom # noqa + + +@pytest.mark.parametrize('args, expected', [([], False), (['--highlight-row-on-click'], True)]) +def test_cli_highlight_row_on_click(tmp_path, args, expected): + board = tmp_path / 'board.json' + board.write_text(json.dumps({ + 'spec_version': 1, + 'pcbdata': { + 'edges_bbox': {'minx': 0, 'miny': 0, 'maxx': 10, 'maxy': 10}, + 'edges': [], + 'drawings': {}, + 'footprints': [], + 'metadata': {'title': '', 'revision': '', 'company': '', 'date': ''}, + }, + 'components': [], + }), encoding='utf-8') + + generator = (Path(__file__).resolve().parents[1] / + 'InteractiveHtmlBom/generate_interactive_bom.py') + result = subprocess.run( + [sys.executable, str(generator), str(board), '--no-browser', *args], + env=dict(os.environ, INTERACTIVE_HTML_BOM_NO_DISPLAY='1'), + capture_output=True, text=True, timeout=90, + ) + assert result.returncode == 0, result.stdout + result.stderr + + html = (tmp_path / 'bom' / 'ibom.html').read_text(encoding='utf-8') + match = re.search(r'^var config = (.+)$', html, re.M) + assert match is not None + assert json.loads(match.group(1)).get('highlight_row_on_click', False) is expected