Skip to content

Commit

Permalink
Merge pull request #67 from rsutphin/use_configured_streams_for_jruby
Browse files Browse the repository at this point in the history
Use the configured streams on JRuby with JLine
  • Loading branch information
JEG2 committed Feb 23, 2013
2 parents 4b42ae9 + b0d81a8 commit 2012c16
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/highline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ def self.const_missing(name)
#
def initialize( input = $stdin, output = $stdout,
wrap_at = nil, page_at = nil, indent_size=3, indent_level=0 )
super()
@input = input
@output = output

Expand All @@ -193,6 +192,8 @@ def initialize( input = $stdin, output = $stdout,
@gather = nil
@answers = nil
@key = nil

initialize_system_extensions if respond_to?(:initialize_system_extensions)
end

include HighLine::SystemExtensions
Expand Down
10 changes: 5 additions & 5 deletions lib/highline/system_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class HighLine
module SystemExtensions
JRUBY = defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'

def initialize
if JRUBY
if JRUBY
def initialize_system_extensions
require 'java'
if JRUBY_VERSION =~ /^1.7/
java_import 'jline.console.ConsoleReader'

@java_console = ConsoleReader.new($stdin.to_inputstream, $stdout.to_outputstream)
@java_console = ConsoleReader.new(@input.to_inputstream, @output.to_outputstream)
@java_console.set_history_enabled(false)
@java_console.set_bell_enabled(true)
@java_console.set_pagination_enabled(false)
Expand All @@ -28,8 +28,8 @@ def initialize
java_import 'jline.ConsoleReader'
java_import 'jline.Terminal'

@java_input = Channels.newInputStream($stdin.to_channel)
@java_output = OutputStreamWriter.new(Channels.newOutputStream($stdout.to_channel))
@java_input = Channels.newInputStream(@input.to_channel)
@java_output = OutputStreamWriter.new(Channels.newOutputStream(@output.to_channel))
@java_terminal = Terminal.getTerminal
@java_console = ConsoleReader.new(@java_input, @java_output)
@java_console.setUseHistory(false)
Expand Down

0 comments on commit 2012c16

Please sign in to comment.