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

Official windows support #401

Merged
merged 3 commits into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
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
30 changes: 19 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ language:
os:
- linux

cache:
bundler: true
directories:
- $HOME/AppData/Local/Temp/chocolatey
- /C/tools/msys64
cache: bundler

rvm:
- '2.5'
Expand All @@ -25,7 +21,6 @@ jobs:

allow_failures:
- rvm: truffleruby-head
- os: windows

include:
- os: osx
Expand All @@ -36,14 +31,27 @@ jobs:
before_cache:
- |-
# https://unix.stackexchange.com/a/137322/107554
$msys2 pacman --sync --clean --noconfirm
pacman --sync --clean --noconfirm
- bundle clean
before_install:
- ruby --version
- gem --version
- choco install msys2 --params /NoUpdate
- powershell -Command 'Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass ; & c:\tools\ruby27\bin\ridk.ps1' install dev_tools
- |
if [[ ! -f /C/tools/msys64/--msys2-- ]]; then
rm -rf /C/tools/msys64
choco uninstall -y mingw
choco upgrade --no-progress -y msys2 --params /NoUpdate
ridk.cmd install dev_tools
fi
- touch /C/tools/msys64/--msys2--
install:
- bundle install --retry=3
- bundle install --path vendor/bundle --retry=3
- export MSYS=winsymlinks:nativestrict
cache:
directories:
- $HOME/AppData/Local/Temp/chocolatey
- /C/tools/msys64
- vendor/bundle

before_install:
- gem --version
Expand Down Expand Up @@ -85,7 +93,7 @@ script:
- colorls --color=auto
- colorls --color=never
- colorls --color=always
- colorls --tree
- colorls --tree spec
- colorls --tree=1
- LC_ALL=C colorls spec/fixtures/
- LC_ALL=C colorls --git spec/fixtures/
Expand Down
15 changes: 13 additions & 2 deletions lib/colorls/core.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# frozen_string_literal: true

module ColorLS
# on Windows (were the special 'nul' device exists) we need to use UTF-8
@file_encoding = File.exist?('nul') ? Encoding::UTF_8 : Encoding::ASCII_8BIT

def self.file_encoding
@file_encoding
end

class Core
def initialize(input, all: false, report: false, sort: false, show: false,
mode: nil, git_status: false, almost_all: false, colors: [], group: nil,
Expand Down Expand Up @@ -79,7 +86,7 @@ def init_contents(path)
info = FileInfo.new(path, link_info: @long)

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

filter_hidden_contents

Expand Down Expand Up @@ -283,14 +290,18 @@ def symlink_info(content)
end
end

def out_encode(str)
str.encode(Encoding.default_external, undef: :replace, replace: '')
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.show
name = make_link(path, name) if @hyperlink
name += content.directory? ? '/' : ' '
entry = "#{logo.encode(Encoding.default_external, undef: :replace, replace: '')} #{name}"
entry = "#{out_encode(logo)} #{out_encode(name)}"

"#{long_info(content)} #{git_info(content)} #{entry.colorize(color)}#{symlink_info(content)}"
end
Expand Down
10 changes: 8 additions & 2 deletions spec/color_ls/flags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
end

context 'with --sort=time' do
entries = Dir.entries(FIXTURES).grep(/^[^.]/).shuffle.freeze
entries = Dir.entries(FIXTURES, encoding: Encoding::UTF_8).grep(/^[^.]/).shuffle.freeze
mtime = Time.new(2017, 11, 7, 2, 2, 2).freeze

files = entries.each_with_index do |e, i|
Expand Down Expand Up @@ -276,7 +276,13 @@
context 'symlinked directory with trailing separator' do
let(:args) { ['-x', File.join(FIXTURES, 'symlinks', 'Supportlink', File::SEPARATOR)] }

it { expect { subject }.to output(/yaml_sort_checker.rb/).to_stdout }
it 'should show the file in the linked directory' do
if File.symlink? File.join(FIXTURES, 'symlinks', 'Supportlink')
expect { subject }.to output(/yaml_sort_checker.rb/).to_stdout
else
skip "symlinks not supported"
end
end
end

context 'when passing invalid flags' do
Expand Down