-
Notifications
You must be signed in to change notification settings - Fork 391
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
Add custom dir suffix colors #231
Open
JustinHallquist
wants to merge
13
commits into
athityakumar:main
Choose a base branch
from
JustinHallquist:add-custom-dir-suffix-colors
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d38f444
add custom dir suffix colors
c68ce13
remove period dir delimiter until feedback
70c162d
remove period dir delimiter until feedback
2bf8633
generalize suffixes
e2c54d7
fix lint issues
909ebb7
fix merge conflicts
ad546f4
require forwardable
81ddcbf
use folders var
0e5a9c3
reduce complexity of options
e457b20
Merge branch 'master' into add-custom-dir-suffix-colors
avdv 7ea7775
merge master and fix conflicts/dead code
de329ab
address merge conflicts
de87d0d
fix merge conflicts
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 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 |
---|---|---|
|
@@ -288,13 +288,15 @@ def symlink_info(content) | |
end | ||
|
||
def slash?(content) | ||
content.directory? ? '/'.colorize(@colors[:dir]) : ' ' | ||
content.directory? ? '/'.colorize(dir_color(content)) : ' ' | ||
end | ||
|
||
def fetch_string(path, content, key, color, increment) | ||
@count[increment] += 1 | ||
value = increment == :folders ? @folders[key] : @files[key] | ||
|
||
logo = value.gsub(/\\u[\da-f]{4}/i) { |m| [m[-4..-1].to_i(16)].pack('U') } | ||
|
||
name = content.name | ||
name = make_link(path, name) if @hyperlink | ||
|
||
|
@@ -316,6 +318,17 @@ def ls_line(chunk) | |
print "\n" | ||
end | ||
|
||
def dir_color(content) | ||
return @colors[:dir] unless @colors[:dir_suffixes] | ||
name = content.name | ||
|
||
suffix_arr = @colors[:dir_suffixes].find do |suffix| | ||
name.end_with? suffix[0].to_s | ||
end | ||
|
||
suffix_arr ? @colors[:dir_suffixes][suffix_arr.first] : @colors[:dir] | ||
end | ||
|
||
def file_color(file, key) | ||
color_key = case | ||
when file.chardev? then :chardev | ||
|
@@ -327,24 +340,34 @@ def file_color(file, key) | |
@colors[color_key] | ||
end | ||
|
||
def options(content) | ||
if content.directory? | ||
key = content.name.to_sym | ||
key = @folder_aliases[key] unless @folders.key? key | ||
key = :folder if key.nil? | ||
color = @colors[:dir] | ||
group = :folders | ||
else | ||
key = content.name.split('.').last.downcase.to_sym | ||
key = @file_aliases[key] unless @files.key? key | ||
key = :file if key.nil? | ||
color = file_color(content, key) | ||
group = @files.key?(key) ? :recognized_files : :unrecognized_files | ||
end | ||
def dir_options(content) | ||
group = :folders | ||
color = dir_color(content) | ||
key = | ||
if @folders.include?(key) && @folder_keys.include?(key) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
@folder_aliases[key] | ||
else | ||
:folder | ||
end | ||
|
||
[key, color, group] | ||
end | ||
|
||
def file_options(content) | ||
key = content.name.split('.').last.downcase.to_sym | ||
key = @file_aliases[key] unless @files.key? key | ||
key = :file if key.nil? | ||
color = file_color(content, key) | ||
group = @files.key?(key) ? :recognized_files : :unrecognized_files | ||
|
||
[key, color, group] | ||
end | ||
|
||
def options(content) | ||
return dir_options(content) if content.directory? | ||
file_options(content) | ||
end | ||
|
||
def tree_traverse(path, prespace, indent) | ||
contents = init_contents(path) | ||
contents.each do |content| | ||
|
This file contains 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 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
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.
The color is in
suffix_arr[1]
, no need to fetch it again from the@colors
hash.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.
thanks for pointing that out, updated