Skip to content

Fix #958: highlight IPv6 + allow editing built-in keyword rules#962

Merged
binaricat merged 1 commit into
mainfrom
fix/958-ipv6-highlight-and-editable-defaults
May 12, 2026
Merged

Fix #958: highlight IPv6 + allow editing built-in keyword rules#962
binaricat merged 1 commit into
mainfrom
fix/958-ipv6-highlight-and-editable-defaults

Conversation

@binaricat
Copy link
Copy Markdown
Owner

@binaricat binaricat commented May 12, 2026

Summary

Closes both halves of #958 in a single PR:

  1. bug: the built-in "URL, IP & MAC" highlight rule only matched IPv4, so IPv6 addresses (the issue screenshots show 2001:11:22:33::5 and fe80::d2dd:bff:fe79:f2bb) were never highlighted.
  2. feature: "would like to be able to modify the default rules" — built-in rules are now fully editable from the settings UI.

Changes

1. IPv6 regex

Added IPV6_HIGHLIGHT_PATTERN in domain/models.ts and merged it into the existing 'ip-mac' default rule's patterns array (per the issue follow-up: "fold it into the existing rule"). Covers:

  • Full 8-group form: 2001:0db8:85a3:0000:0000:8a2e:0370:7334
  • Mid-compressed: 2001:11:22:33::5 (issue example 1)
  • Link-local compressed: fe80::d2dd:bff:fe79:f2bb (issue example 2)
  • Loopback: ::1
  • All variants of :: at the head / middle / tail

Out of scope for this first pass (intentionally omitted, can become a follow-up issue): zone IDs (%eth0 suffix) and IPv4-mapped (::ffff:192.0.2.1). The carve-out is documented in the constant's comment.

No migration step needed for existing users: the existing "fill in missing default rules" logic in normalizeKeywordHighlightRules, combined with the customized change below, automatically refreshes the patterns of any ip-mac rule the user has not customized.

2. Editable built-in rules

Added an optional customized?: boolean to KeywordHighlightRule:

  • customized unset / false (the default state): normalize overwrites with the latest default patterns/label (while preserving the user's color/enabled). This means any future pattern upgrade we ship (like IPv6 in this PR) automatically reaches every user who hasn't customized.
  • customized set to true: normalize keeps the user's label/patterns/color/enabled exactly as saved.

Corresponding UI changes in SettingsTerminalTab.tsx:

  • Built-in rules now also show the edit pencil icon. Clicking it reuses the existing AddCustomRuleDialog.
  • The pattern input is upgraded from Input to Textarea, one regex per line. Built-ins like 'error' (which ships seven patterns) can now be viewed and edited in one go.
  • Saving an edit to a built-in rule automatically flips customized to true.
  • A customized built-in rule shows a small ↺ icon to restore the shipped label/patterns (the user's color is preserved).
  • The footer's "Reset default colors" button is broadened into "Reset built-ins to defaults".

Tests

New domain/keywordHighlight.test.ts — 6 tests:

  • IPv6 regex matches both issue examples + loopback + full form
  • IPv4 / MAC still match (no regression)
  • Plain hex blobs are not falsely matched
  • normalize migrates a legacy non-customized ip-mac rule (without IPv6) up to the new defaults
  • normalize keeps user-edited values verbatim when customized: true
  • normalize leaves user custom rules untouched
npm test → 808 pass / 0 fail / 3 skipped

npx tsc --noEmit is clean on the changed files (other pre-existing repo-wide TS errors are unrelated to this PR).

Test plan

  • Unit tests cover both the regex and the normalize behavior
  • Manual: open a terminal where SSH output contains 2001:11:22:33::5 and fe80::d2dd:bff:fe79:f2bb, confirm both are highlighted
  • Manual: Settings → Terminal → Keyword highlighting, hover the built-in "URL, IP & MAC" row to see the pencil; clicking it should show all 4 patterns (URL / IPv4 / IPv6 / MAC). Editing one and restarting netcatty should keep the edit
  • Manual: click the ↺ icon on a customized built-in rule — patterns restore to defaults; the custom color is preserved
  • Manual: the footer "Reset built-ins to defaults" button restores every built-in in one click while leaving custom user rules alone

🤖 Generated with Claude Code

Two changes addressing both halves of #958:

1. IPv6 highlighting
   The built-in 'URL, IP & MAC' rule only shipped URL, IPv4 and MAC
   patterns, so compressed IPv6 addresses such as 2001:11:22:33::5 or
   fe80::d2dd:bff:fe79:f2bb were never highlighted. Add an IPv6 regex
   covering full and compressed forms (including ::1 and leading-/trailing-
   :: variants) and merge it into the same 'ip-mac' rule's patterns. The
   normalizer's existing "fill missing defaults" path means existing users
   pick this up on next start with no migration step.

2. Editable built-in rules
   Add an optional `customized` flag to KeywordHighlightRule. When false /
   absent, normalize re-syncs the rule's label/patterns with the shipped
   defaults (so future default-pattern upgrades reach users automatically).
   When true, normalize keeps the user's label/patterns/color/enabled
   verbatim, allowing built-ins like 'ip-mac' to be tailored.

   SettingsTerminalTab:
   - Pencil icon now appears on built-ins too. Editing one routes through
     the same dialog and flips `customized` on save.
   - The pattern field becomes a Textarea so multi-pattern built-ins (e.g.
     'error' ships seven spellings) can all be edited in one go.
   - A per-rule "↺" reset icon appears on customized built-ins and restores
     the shipped label/patterns while preserving the user's color/enabled.
   - The footer's "Reset to default colors" button is broadened into
     "Reset built-ins to defaults", restoring every built-in to shipped
     label/patterns/color and clearing `customized`.

Tests:
   New domain/keywordHighlight.test.ts (6 tests) covers IPv6 matches for
   both #958 examples plus loopback and full-form, IPv4/MAC still match,
   normalize migrates legacy non-customized 'ip-mac' to include IPv6,
   normalize preserves customized patterns, and normalize keeps user
   custom rules verbatim. Full suite: 808/0/3.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@binaricat binaricat merged commit 67c5571 into main May 12, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant