Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit makes the following changes: * Move JRuby-specific console logic to io/console/jruby * Add console.rb to load appropriate impl for the current engine * Adjust tags to match passing tests * Add test_io_console to MRI stdlib suite See ruby/io-console#11
- Loading branch information
Showing
12 changed files
with
91 additions
and
85 deletions.
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
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 |
---|---|---|
@@ -1,67 +1,5 @@ | ||
# This implementation of io/console is a little hacky. It shells out to `stty` | ||
# for most operations, which does not work on Windows, in secured environments, | ||
# and so on. In addition, because on Java 6 we can't actually launch | ||
# subprocesses with tty control, stty will not actually manipulate the | ||
# controlling terminal. | ||
# | ||
# For platforms where shelling to stty does not work, most operations will | ||
# just be pass-throughs. This allows them to function, but does not actually | ||
# change any tty flags. | ||
# | ||
# Finally, since we're using stty to shell out, we can only manipulate stdin/ | ||
# stdout tty rather than manipulating whatever terminal is actually associated | ||
# with the IO we're calling against. This will produce surprising results if | ||
# anyone is actually using io/console against non-stdio ttys...but that case | ||
# seems like it would be pretty rare. | ||
# | ||
# Note: we are incorporating this into 1.7.0 since RubyGems uses io/console | ||
# when pushing gems, in order to mask the password entry. Worst case is that | ||
# we don't actually disable echo and the password is shown...we will try to | ||
# do a better version of this in 1.7.1. | ||
|
||
require 'rbconfig' | ||
|
||
require 'io/console/common' | ||
|
||
# If Windows, always use the stub version | ||
if RbConfig::CONFIG['host_os'] =~ /(mswin)|(win32)|(ming)/ | ||
require 'io/console/stub_console' | ||
if RUBY_ENGINE == 'jruby' | ||
require 'io/console/jruby' | ||
else | ||
|
||
# If Linux or BSD, try to load the native version | ||
if RbConfig::CONFIG['host_os'].downcase =~ /darwin|openbsd|freebsd|netbsd|linux/ | ||
begin | ||
|
||
# Attempt to load the native Linux and BSD console logic | ||
require 'io/console/native_console' | ||
ready = true | ||
|
||
rescue Exception => ex | ||
|
||
warn "failed to load native console support: #{ex}" if $VERBOSE | ||
ready = false | ||
|
||
end | ||
end | ||
|
||
# Native failed, try to use stty | ||
if !ready | ||
begin | ||
|
||
require 'io/console/stty_console' | ||
ready = true | ||
|
||
rescue Exception | ||
|
||
warn "failed to load stty console support: #{ex}" if $VERBOSE | ||
ready = false | ||
|
||
end | ||
end | ||
|
||
# If still not ready, just use stubbed version | ||
if !ready | ||
require 'io/console/stub_console' | ||
end | ||
|
||
end | ||
require 'io/console.so' | ||
end |
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# This implementation of io/console is a little hacky. It shells out to `stty` | ||
# for most operations, which does not work on Windows, in secured environments, | ||
# and so on. In addition, because on Java 6 we can't actually launch | ||
# subprocesses with tty control, stty will not actually manipulate the | ||
# controlling terminal. | ||
# | ||
# For platforms where shelling to stty does not work, most operations will | ||
# just be pass-throughs. This allows them to function, but does not actually | ||
# change any tty flags. | ||
# | ||
# Finally, since we're using stty to shell out, we can only manipulate stdin/ | ||
# stdout tty rather than manipulating whatever terminal is actually associated | ||
# with the IO we're calling against. This will produce surprising results if | ||
# anyone is actually using io/console against non-stdio ttys...but that case | ||
# seems like it would be pretty rare. | ||
# | ||
# Note: we are incorporating this into 1.7.0 since RubyGems uses io/console | ||
# when pushing gems, in order to mask the password entry. Worst case is that | ||
# we don't actually disable echo and the password is shown...we will try to | ||
# do a better version of this in 1.7.1. | ||
|
||
require 'rbconfig' | ||
|
||
require_relative 'jruby/common' | ||
|
||
# If Windows, always use the stub version | ||
if RbConfig::CONFIG['host_os'] =~ /(mswin)|(win32)|(ming)/ | ||
require_relative 'jruby/stub_console' | ||
else | ||
|
||
# If Linux or BSD, try to load the native version | ||
if RbConfig::CONFIG['host_os'].downcase =~ /darwin|openbsd|freebsd|netbsd|linux/ | ||
begin | ||
|
||
# Attempt to load the native Linux and BSD console logic | ||
require_relative 'jruby/native_console' | ||
ready = true | ||
|
||
rescue Exception => ex | ||
|
||
warn "failed to load native console support: #{ex}" if $VERBOSE | ||
ready = false | ||
|
||
end | ||
end | ||
|
||
# Native failed, try to use stty | ||
if !ready | ||
begin | ||
|
||
require_relative 'jruby/stty_console' | ||
ready = true | ||
|
||
rescue Exception | ||
|
||
warn "failed to load stty console support: #{ex}" if $VERBOSE | ||
ready = false | ||
|
||
end | ||
end | ||
|
||
# If still not ready, just use stubbed version | ||
if !ready | ||
require_relative 'jruby/stub_console' | ||
end | ||
|
||
end |
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
lib/ruby/stdlib/io/console/native_console.rb → ...stdlib/io/console/jruby/native_console.rb
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
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
# frozen_string_literal: false | ||
exclude :test_cooked, 'depends on unimplemented PTY functionality' | ||
exclude :test_echo, 'depends on unimplemented PTY functionality' | ||
# exclude :test_cooked, 'depends on unimplemented PTY functionality' | ||
# exclude :test_echo, 'depends on unimplemented PTY functionality' | ||
exclude :test_getpass, 'not portable' | ||
exclude :test_iflush, 'depends on unimplemented PTY functionality' | ||
exclude :test_ioflush, 'depends on unimplemented PTY functionality' | ||
exclude :test_ioflush2, 'depends on unimplemented PTY functionality' | ||
exclude :test_noecho, 'depends on unimplemented PTY functionality' | ||
exclude :test_noecho2, 'depends on unimplemented PTY functionality' | ||
exclude :test_oflush, 'depends on unimplemented PTY functionality' | ||
exclude :test_raw, 'depends on unimplemented PTY functionality' | ||
exclude :test_raw!, 'depends on unimplemented PTY functionality' | ||
# exclude :test_iflush, 'depends on unimplemented PTY functionality' | ||
# exclude :test_ioflush, 'depends on unimplemented PTY functionality' | ||
# exclude :test_ioflush2, 'depends on unimplemented PTY functionality' | ||
# exclude :test_noecho, 'depends on unimplemented PTY functionality' | ||
# exclude :test_noecho2, 'depends on unimplemented PTY functionality' | ||
# exclude :test_oflush, 'depends on unimplemented PTY functionality' | ||
# exclude :test_raw, 'depends on unimplemented PTY functionality' | ||
# exclude :test_raw!, 'depends on unimplemented PTY functionality' | ||
exclude :test_raw_minchar, 'depends on unimplemented PTY functionality' | ||
exclude :test_raw_timeout, 'depends on unimplemented PTY functionality' | ||
exclude :test_setecho, 'depends on unimplemented PTY functionality' | ||
exclude :test_setecho2, 'depends on unimplemented PTY functionality' | ||
exclude :test_winsize, 'depends on unimplemented PTY functionality' | ||
exclude :test_set_winsize_invalid_dev, 'depends on unimplemented PTY functionality' | ||
# exclude :test_setecho, 'depends on unimplemented PTY functionality' | ||
# exclude :test_setecho2, 'depends on unimplemented PTY functionality' | ||
# exclude :test_winsize, 'depends on unimplemented PTY functionality' |
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