-
Notifications
You must be signed in to change notification settings - Fork 15
Add --only flag for file filtering #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,7 @@ type Model struct { | |
|
|
||
| ref string | ||
| staged bool | ||
| only []string // filter to show only matching files | ||
| noStatusBar bool | ||
| focus pane | ||
| width int | ||
|
|
@@ -115,7 +116,8 @@ type ModelConfig struct { | |
| NoColors bool // disable all colors including syntax highlighting | ||
| NoStatusBar bool // hide the status bar | ||
| NoConfirmDiscard bool // skip confirmation prompt when discarding annotations | ||
| Wrap bool // enable line wrapping | ||
| Wrap bool // enable line wrapping | ||
| Only []string // show only these files (match by exact path or path suffix) | ||
| Colors Colors | ||
| } | ||
|
|
||
|
|
@@ -138,6 +140,7 @@ func NewModel(renderer Renderer, store *annotation.Store, highlighter SyntaxHigh | |
| highlighter: highlighter, | ||
| ref: cfg.Ref, | ||
| staged: cfg.Staged, | ||
| only: cfg.Only, | ||
| noStatusBar: cfg.NoStatusBar, | ||
| noConfirmDiscard: cfg.NoConfirmDiscard, | ||
| wrapMode: cfg.Wrap, | ||
|
|
@@ -437,13 +440,36 @@ func (m Model) handleResize(msg tea.WindowSizeMsg) (tea.Model, tea.Cmd) { | |
| return m, nil | ||
| } | ||
|
|
||
| // filterOnly returns only files matching the --only patterns, or all files if no filter is set. | ||
| // matches by exact path or path suffix (e.g. "model.go" matches "ui/model.go"). | ||
| func (m Model) filterOnly(files []string) []string { | ||
| if len(m.only) == 0 { | ||
| return files | ||
| } | ||
| var filtered []string | ||
| for _, f := range files { | ||
| for _, pattern := range m.only { | ||
| if f == pattern || strings.HasSuffix(f, "/"+pattern) { | ||
| filtered = append(filtered, f) | ||
| break | ||
| } | ||
| } | ||
| } | ||
| return filtered | ||
| } | ||
|
|
||
| func (m Model) handleFilesLoaded(msg filesLoadedMsg) (tea.Model, tea.Cmd) { | ||
| if msg.err != nil { | ||
| m.viewport.SetContent(fmt.Sprintf("error loading files: %v", msg.err)) | ||
| return m, nil | ||
| } | ||
| m.tree = newFileTree(msg.files) | ||
| m.singleFile = len(msg.files) == 1 | ||
| files := m.filterOnly(msg.files) | ||
| if len(files) == 0 && len(m.only) > 0 { | ||
| m.viewport.SetContent("no files match --only filter") | ||
| return m, nil | ||
|
Comment on lines
+466
to
+469
|
||
| } | ||
| m.tree = newFileTree(files) | ||
| m.singleFile = len(files) == 1 | ||
| if m.singleFile { | ||
| m.focus = paneDiff | ||
| m.treeWidth = 0 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ModelConfig.Wraphas extra spacing before the comment (bool // ...), which is inconsistent with gofmt output in the rest of the file. Running gofmt (or adjusting the spacing) will keep the struct formatting consistent.