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

Add File/Dir formatters for mswin platform #48

Merged
merged 7 commits into from
Oct 26, 2022

Conversation

gromnitsky
Copy link
Contributor

The mswin platform is Ruby build with the Visual Studio C++ compiler. Unlike msys2 or cygwin builds, it knows no unix features.

Without this patch, typing URI.open 'https://www.google.com' in irb throws an error, for AmazingPrint tries to shell out to ls(1) to get info about a tmp file & there is no ls executable on Windows.

This PL emulates powershell Get-ChildItem cmdlet output, e.g.:

> irb --prompt simple -r.\lib\amazing_print -ropen-uri
>> AmazingPrint.irb!
:output_value
>> URI.open 'https://www.google.com'
#<File:C:/Users/alex/AppData/Local/Temp/open-uri20200801-10928-k09w4s>
-a----       2020-08-01     22:58          14715 C:/Users/alex/AppData/Local/Temp/open-uri20200801-10928-k09w4s
>> Dir.open File.join ENV['USERPROFILE'], 'AppData'
#<Dir:C:\Users\alex/AppData>
d--h--       2019-06-18     18:00                C:\Users\alex/AppData

I added :unix & :mswin tags to several rspec examples, thus you can run rspec under Linux as before without noticing Windows-specific tests.

@gromnitsky gromnitsky force-pushed the mswin-file-formatter branch from c5198ac to 897075e Compare August 2, 2020 11:45
HarlemSquirrel
HarlemSquirrel previously approved these changes Oct 10, 2021
Copy link
Member

@HarlemSquirrel HarlemSquirrel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me! Thank you for opening this and I apologize for not reviewing it earlier.

Please resolve the conflicts when you have a chance and we can merge this in 😊

paddor
paddor previously approved these changes Oct 26, 2022
colorize(ls.empty? ? file.inspect : "#{file.inspect}\n#{ls.chop}", :file)
end

def info
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can provide two different implementations of #info according to RUBY_PLATFORM?
Like this:

if RUBY_PLATFORM.include?('mswin')
  def info
    # ...
  end
else
  def info
    # ...
  end
end

@@ -3,6 +3,7 @@
require 'shellwords'

require_relative 'base_formatter'
require_relative 'mswin_helper' if RUBY_PLATFORM.include?('mswin')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it makes sense to use the platform tester from RubyGems: Gem.win_platform?

@paddor paddor dismissed stale reviews from HarlemSquirrel and themself via 507a9a0 October 26, 2022 08:33
@paddor paddor merged commit 8c0ae33 into amazing-print:master Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants