-
-
Notifications
You must be signed in to change notification settings - Fork 414
Sidebar code separation #770
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
14 commits
Select commit
Hold shift + click to select a range
af74339
fix(sidebar separation): Export all sidebar fields and methods
lazysegtree 1e896a9
fix(sidebar separation): Remove unnecessary anonymous struct for side…
lazysegtree 3331cd8
fix(sidebar separation): Make get_data functions exported
lazysegtree 5995be1
fix(sidebar separation): Separate sidebar, and some required utilitie…
lazysegtree 529596b
fix(sidebar separation): Move sidebar pinned operations to sidebar pa…
lazysegtree c2fdf69
fix(sidebar separation): Move update state and update searchbar to si…
lazysegtree 286d475
fix(sidebar separation): Move rendering and some other functionality …
lazysegtree 0fead58
fix(sidebar separation): Make all fields of sidebarModel unexported
lazysegtree 512e275
fix(sidebar separation): Restructured files
lazysegtree ff41a1e
fix(sidebar separation): Move toggling pinned directory to sidebar
lazysegtree 425955e
docs: Add ReadMe for sidebar
lazysegtree 5ac72de
Merge pull request #767 from yorukot/sidebar_separation
lazysegtree e654b25
fix(sidebar separation): Make directory related functionality unexported
lazysegtree 488cf8d
fix: PR comments: Add unit tests for icon_utils
lazysegtree 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package common | ||
|
|
||
| import ( | ||
| "path/filepath" | ||
| "strings" | ||
|
|
||
| "github.com/yorukot/superfile/src/config/icon" | ||
| ) | ||
|
|
||
| func GetElementIcon(file string, isDir bool, nerdFont bool) icon.Style { | ||
| ext := strings.TrimPrefix(filepath.Ext(file), ".") | ||
| name := file | ||
|
|
||
| if !nerdFont { | ||
| return icon.Style{ | ||
| Icon: "", | ||
| Color: Theme.FilePanelFG, | ||
| } | ||
| } | ||
|
|
||
| if isDir { | ||
| resultIcon := icon.Folders["folder"] | ||
| betterIcon, hasBetterIcon := icon.Folders[name] | ||
| if hasBetterIcon { | ||
| resultIcon = betterIcon | ||
| } | ||
| return resultIcon | ||
| } | ||
| // default icon for all files. try to find a better one though... | ||
| resultIcon := icon.Icons["file"] | ||
| // resolve aliased extensions | ||
| extKey := strings.ToLower(ext) | ||
| alias, hasAlias := icon.Aliases[extKey] | ||
| if hasAlias { | ||
| extKey = alias | ||
| } | ||
|
|
||
| // see if we can find a better icon based on extension alone | ||
| betterIcon, hasBetterIcon := icon.Icons[extKey] | ||
| if hasBetterIcon { | ||
| resultIcon = betterIcon | ||
| } | ||
|
|
||
| // now look for icons based on full names | ||
| fullName := name | ||
|
|
||
| fullName = strings.ToLower(fullName) | ||
| fullAlias, hasFullAlias := icon.Aliases[fullName] | ||
| if hasFullAlias { | ||
| fullName = fullAlias | ||
| } | ||
| bestIcon, hasBestIcon := icon.Icons[fullName] | ||
| if hasBestIcon { | ||
| resultIcon = bestIcon | ||
| } | ||
| if resultIcon.Color == "NONE" { | ||
| return icon.Style{ | ||
| Icon: resultIcon.Icon, | ||
| Color: Theme.FilePanelFG, | ||
| } | ||
| } | ||
| return resultIcon | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| package common | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/yorukot/superfile/src/config/icon" | ||
| ) | ||
|
|
||
| func TestGetElementIcon(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| file string | ||
| isDir bool | ||
| nerdFont bool | ||
| expected icon.Style | ||
| }{ | ||
| { | ||
| name: "Non-nerdfont returns empty icon", | ||
| file: "test.txt", | ||
| isDir: false, | ||
| nerdFont: false, | ||
| expected: icon.Style{ | ||
| Icon: "", | ||
| Color: Theme.FilePanelFG, | ||
| }, | ||
| }, | ||
| { | ||
| name: "Directory with nerd font", | ||
| file: "folder", | ||
| isDir: true, | ||
| nerdFont: true, | ||
| expected: icon.Folders["folder"], | ||
| }, | ||
| { | ||
| name: "File with known extension", | ||
| file: "test.js", | ||
| isDir: false, | ||
| nerdFont: true, | ||
| expected: icon.Icons["js"], | ||
| }, | ||
| { | ||
| name: "Full name takes priority over extension", | ||
| file: "gulpfile.js", | ||
| isDir: false, | ||
| nerdFont: true, | ||
| expected: icon.Icons["gulpfile.js"], | ||
| }, | ||
| { | ||
| name: ".git directory", | ||
| file: ".git", | ||
| isDir: true, | ||
| nerdFont: true, | ||
| expected: icon.Folders[".git"], | ||
| }, | ||
| { | ||
| name: "superfile directory", | ||
| file: "superfile", | ||
| isDir: true, | ||
| nerdFont: true, | ||
| expected: icon.Folders["superfile"], | ||
| }, | ||
| { | ||
| name: "package.json file", | ||
| file: "package.json", | ||
| isDir: false, | ||
| nerdFont: true, | ||
| expected: icon.Icons["package"], | ||
| }, | ||
| { | ||
| name: "File with unknown extension", | ||
| file: "test.xyz", | ||
| isDir: false, | ||
| nerdFont: true, | ||
| expected: icon.Style{ | ||
| Icon: icon.Icons["file"].Icon, | ||
| // Theme is not defined here, so this will be blank | ||
| Color: Theme.FilePanelFG, | ||
| }, | ||
| }, | ||
| { | ||
| name: "File with aliased name", | ||
| file: "dockerfile", | ||
| isDir: false, | ||
| nerdFont: true, | ||
| expected: icon.Icons["dockerfile"], | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| result := GetElementIcon(tt.file, tt.isDir, tt.nerdFont) | ||
| if result.Icon != tt.expected.Icon || result.Color != tt.expected.Color { | ||
| t.Errorf("GetElementIcon() = %v, want %v", result, tt.expected) | ||
| } | ||
| }) | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
@coderabbitai
Please generate a task description for this PR. I will give someone this task. He doesn't know anything about this product. we have a sidebar with implementation scattered across.
move stuff to sidebar package.
Make side functions exported so that they are accessible outside
Move src/internal/common/utils to a separate src/internal/utils package
Ensure nothing breaks
Organize code into correct files.
Any other refactoring that I missed ?
Add Anything else that I missed, which is done in this PR, and should be in the ask description.
Keep it in 6-7 points or less. Format should be markdown. Make sure to highlight what needs to be done, not how or where.
Give basic context about Superfile and what the requirements are.The problem description should be stated such that a reasonably competent software engineer could write the correct PR for it without too much familiarity with the repo. Write it in a way that a LLM could generate a correct PR for it.
Also, generate a TL;DR
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.
@lazysegtree
Task Description: Sidebar Code Consolidation and Refactoring
TL;DR
Consolidate scattered sidebar implementation into a dedicated
sidebarpackage, export necessary functions, reorganize utilities, and ensure backward compatibility throughout the codebase.Context
Superfile is a modern terminal file manager written in Go. It features a sidebar UI component that displays pinned directories, well-known system directories (like Documents, Downloads), and external media/disk partitions. Users can navigate, search, and rename items within the sidebar.
Problem
The sidebar implementation is currently scattered across multiple files in the main
internalpackage. Functions are not properly encapsulated, utilities are mixed with other code, and the architecture makes maintenance and testing difficult.Requirements
Create a dedicated sidebar package at
src/internal/ui/sidebarand consolidate all sidebar-related code (state management, rendering, navigation, directory operations) into this package.Export functions that need external access by converting them from lowercase to PascalCase naming convention (e.g.,
listUp→ListUp,sidebarModel→Model).Reorganize utility functions by moving
src/internal/common/utilstosrc/internal/utils, making it a standalone package independent of the common package.Update all import paths and references throughout the entire codebase to reflect the new package structure without breaking existing functionality.
Organize code logically within the sidebar package by separating concerns into appropriate files (e.g., rendering logic, navigation, directory operations, disk utilities, type definitions).
Maintain backward compatibility by ensuring all existing features (sidebar navigation, search, rename, pinned directories) continue to work exactly as before.
This refactoring improves code organization, testability, and maintainability without introducing new features or changing user-facing behavior.
🧠 Learnings used