Skip to content
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

Use UTF-8 on Windows to read directory entries #319

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/colorls/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ def ls

private

@@encoding = begin # rubocop:disable Style/ClassVars
if ENV['OS'] == 'Windows_NT' && RUBY_PLATFORM !~ /cygwin/
# use UTF-8 to read entries of directories on windows
Encoding::UTF_8
else
Encoding.find('filesystem')
end
end

def init_colors(colors)
@colors = colors
@modes = Hash.new do |hash, key|
Expand All @@ -79,7 +88,7 @@ def init_contents(path)
info = FileInfo.new(path, link_info = @long)

if info.directory?
@contents = Dir.entries(path)
@contents = Dir.entries(path, encoding: @@encoding)

filter_hidden_contents

Expand Down