tty-platform
tty-platform copied to clipboard
Incorrectly detected platform on Windows
trafficstars
Describe the problem
The platform is not detected correctly on a Windows machine.
On the PC I work on the contents of RbConfig::CONFIG['arch'] is x64-mingw-ucrt
Actual behaviour
TTY::Platform.new.windows? # false
Gem.windows? # true
Expected behaviour
TTY::Platform.new.windows? # true
Describe your environment
- OS version: Windows 11
- Ruby version: 3.3.4
- TTY::Platform version: 0.3.0
Hi @Fjan 👋
Thanks for raising this issue.
The pattern that I use to match Windows includes the mingw, so it should theoretically detect the Windows system.
Therefore, I'd be interested to know what you get for the following values:
RbConfig::CONFIG["host_os"] # => ?
platform = TTY::Platform.new
platform.windows? # => ?
platform.unix? # => ?
platform.linux? # => ?
platform.mac? # => ?
platform.cpu # => ?
platform.os # => ?
platform.version # => ?
Looking at Gem.windows? implementation, the RbConfig::CONFIG["host_os"] is checked instead. The TTY::Platform accepts architecture as an argument, it would be great to see what results you get:
platform = TTY::Platform.new(RbConfig::CONFIG["host_os"])
platform.windows? # => ?
platform.unix? # => ?
platform.linux? # => ?
platform.mac? # => ?
platform.cpu # => ?
platform.os # => ?
platform.version # => ?
Hi @piotrmurach This what I get on that machine, hope this helps.
irb(main):002> RbConfig::CONFIG["host_os"]
=> "mingw32"
irb(main):003> platform = TTY::Platform.new
=> #<TTY::Platform:0x000001eaff09d008 @cpu="x64", @os="unknown", @version=nil>
irb(main):004> platform.windows?
=> false
irb(main):005> platform.unix?
=> false
irb(main):006> platform.linux?
=> false
irb(main):007> platform.cpu
=> "x64"
irb(main):008> platform.os
=> "unknown"
irb(main):009> platform.version
=> nil
irb(main):010> platform = TTY::Platform.new( RbConfig::CONFIG["host_os"] )
=> #<TTY::Platform:0x000001eaff09e3b8 @cpu=nil, @os="mingw32", @version=nil>
irb(main):011> platform.windows?
=> true
irb(main):012> platform.cpu
=> nil
irb(main):013> platform.os
=> "mingw32"
irb(main):014> platform.version
=> nil