Skip to content

feat(tui): add interactive file type filtering via T key#493

Merged
dundee merged 2 commits intodundee:masterfrom
ShivamB25:feat/interactive-type-filter
Feb 25, 2026
Merged

feat(tui): add interactive file type filtering via T key#493
dundee merged 2 commits intodundee:masterfrom
ShivamB25:feat/interactive-type-filter

Conversation

@ShivamB25
Copy link
Contributor

@ShivamB25 ShivamB25 commented Feb 14, 2026

Summary

Adds interactive file type filtering to the TUI, addressing #486. Press T to open a type filter input in the footer where comma-separated file extensions can be entered (e.g. go,yaml,json). This mirrors the existing name filter (/ key) interaction pattern.

What changed

  • tui/filter.go: Added showTypeFilterInput(), hideTypeFilterInput(), matchesTypeFilter(), and rebuildFooter(). Refactored existing name filter methods to use rebuildFooter() for clean coexistence of both inputs. Added "Name: " label prefix to the existing name filter input for clarity.
  • tui/show.go: Added type filter check in showDir() rendering loop (directories always pass through, files filtered by extension). Added T to help text. Added active type filter display in footer. Extracted formatTypeFilterInfo() to keep showDir() within cyclomatic complexity limits.
  • tui/keys.go: Added T keybinding in handleMainActions(). Updated handleFiltering() to support TAB cycling for both filter inputs. Updated the filtering guard to check both filter states.
  • tui/tui.go: Added typeFilterValue, typeFiltering, typeFilteringInput fields. Updated fileItemSelected() to clear type filter on directory navigation.

Behavior

Action Result
Press T Opens "Type: " input in footer
Type go,yaml Real-time filtering — only .go and .yaml files shown, all directories remain visible
ESC Cancels and clears the type filter
Enter Confirms filter, returns focus to table
TAB Cycles focus back to a confirmed filter input
Navigate into a directory Both name and type filters are cleared
Both / and T active Both filters apply simultaneously (AND logic)

Extensions are case-insensitive, leading dots optional (both go and .go work), files without extensions are hidden when a type filter is active.

Tests

Added 7 new test functions in tui/filter_test.go:

  • TestTypeFiltering — core filtering with single and multi-type values
  • TestTypeFilteringWithoutCurrentDir — guard against nil currentDir
  • TestTypeFilteringKeyBindingT key activates the filter
  • TestExitTypeFiltering — ESC clears filter state
  • TestTypeFilterTabSwitch — TAB focus cycling
  • TestBothFiltersCoexist — name + type filters applied simultaneously
  • TestMatchesTypeFilter — unit tests for extension matching (case, dots, empty, dirs)

All existing tests pass. golangci-lint clean. Race detector clean.

Closes #486

Add the ability to filter items by file extension interactively in the
TUI, similar to the existing name filter (/ key). Press T to open a
type filter input where comma-separated extensions can be entered
(e.g. go,yaml,json). Filtering is real-time and directories always
pass through since they are navigational containers.

Both name and type filters can be active simultaneously with AND logic.
The footer shows the active type filter, and TAB cycles focus between
any open filter inputs and the table. Filters are cleared on directory
navigation, consistent with the existing name filter behavior.

Refactored footer management into rebuildFooter() to support multiple
coexisting filter inputs cleanly.

Closes dundee#473
@codecov
Copy link

codecov bot commented Feb 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.66%. Comparing base (ede21d2) to head (818e9e0).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #493      +/-   ##
==========================================
+ Coverage   81.42%   81.66%   +0.23%     
==========================================
  Files          49       49              
  Lines        5126     5197      +71     
==========================================
+ Hits         4174     4244      +70     
- Misses        816      817       +1     
  Partials      136      136              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ShivamB25
Copy link
Contributor Author

Added follow-up tests to address the Codecov patch gap in tui/filter.go.

  • covered showTypeFilterInput() no-color branch (!ui.UseColors)
  • covered showTypeFilterInput() changed-callback path via input handler typing
  • covered re-showing existing type filter input path

Local verification after this commit:

  • golangci-lint run -c .golangci.yml ✅
  • go test -v -race -covermode=atomic ./... ✅
  • go test ./tui -coverprofile=/tmp/tui.cover reports 0 uncovered blocks in tui/filter.go ✅

Please let CI/Codecov refresh on latest head 818e9e0.

@dundee dundee self-requested a review February 24, 2026 05:16
@dundee dundee merged commit b0bd852 into dundee:master Feb 25, 2026
9 checks passed
@dundee
Copy link
Owner

dundee commented Feb 25, 2026

Nice PR, thank you!

@ShivamB25 ShivamB25 deleted the feat/interactive-type-filter branch February 25, 2026 12:18
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.

Make File Type filters (-E, -T) available in interactive (TUI) mode

2 participants