[macruby-changes] [4725] DietRB/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Fri Oct 8 04:05:24 PDT 2010
Revision: 4725
http://trac.macosforge.org/projects/ruby/changeset/4725
Author: eloy.de.enige at gmail.com
Date: 2010-10-08 04:05:23 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
stash previous hacking
From: Eloy Duran <eloy.de.enige at gmail.com>
Modified Paths:
--------------
DietRB/trunk/bin/dietrb
DietRB/trunk/lib/irb/context.rb
DietRB/trunk/lib/irb.rb
Added Paths:
-----------
DietRB/trunk/lib/irb/driver/
DietRB/trunk/lib/irb/driver/readline.rb
DietRB/trunk/lib/irb/driver/socket.rb
DietRB/trunk/lib/irb/driver/tty.rb
Modified: DietRB/trunk/bin/dietrb
===================================================================
--- DietRB/trunk/bin/dietrb 2010-10-08 11:05:11 UTC (rev 4724)
+++ DietRB/trunk/bin/dietrb 2010-10-08 11:05:23 UTC (rev 4725)
@@ -32,7 +32,8 @@
IRB.formatter.filter_from_backtrace << /^#{__FILE__}/
if ARGV.empty?
- irb(self, TOPLEVEL_BINDING.dup)
+ # irb(self, TOPLEVEL_BINDING.dup)
+ IRB::Driver::Socket.new.run
else
path = ARGV.shift
context = IRB::Context.new(self, TOPLEVEL_BINDING.dup)
Modified: DietRB/trunk/lib/irb/context.rb
===================================================================
--- DietRB/trunk/lib/irb/context.rb 2010-10-08 11:05:11 UTC (rev 4724)
+++ DietRB/trunk/lib/irb/context.rb 2010-10-08 11:05:23 UTC (rev 4725)
@@ -28,7 +28,8 @@
attr_reader :object, :binding, :line, :source, :processors
attr_accessor :io, :formatter
- def initialize(object, explicit_binding = nil)
+ def initialize(driver, object, explicit_binding = nil)
+ @driver = driver
@object = object
@binding = explicit_binding || object.instance_eval { binding }
@line = 1
@@ -56,23 +57,23 @@
# it to all processors.
#
# The buffer is cleared if an Interrupt exception is raised.
- def readline_from_io
- input = io.readline(formatter.prompt(self))
- @processors.each { |processor| input = processor.input(input) }
- input
- rescue Interrupt
- clear_buffer
- ""
- end
+ # def readline_from_io
+ # input = io.readline(formatter.prompt(self))
+ # @processors.each { |processor| input = processor.input(input) }
+ # input
+ # rescue Interrupt
+ # clear_buffer
+ # ""
+ # end
- def run
- self.class.make_current(self) do
- while line = readline_from_io
- continue = process_line(line)
- break unless continue
- end
- end
- end
+ # def run
+ # self.class.make_current(self) do
+ # while line = readline_from_io
+ # continue = process_line(line)
+ # break unless continue
+ # end
+ # end
+ # end
# Returns whether or not the user wants to continue the current runloop.
# This can only be done at a code block indentation level of 0.
@@ -87,6 +88,9 @@
#
# process_line("quit") # => false
def process_line(line)
+ # TODO spec
+ @processors.each { |processor| line = processor.input(line) }
+
@source << line
return false if @source.terminate?
@@ -102,6 +106,10 @@
true
end
+ def prompt
+ formatter.prompt(self)
+ end
+
def input_line(line)
io.puts(formatter.prompt(self) + line)
process_line(line)
@@ -112,7 +120,8 @@
end
def io
- @io ||= IRB.io
+ # @io ||= IRB.io
+ @driver
end
def clear_buffer
@@ -129,11 +138,11 @@
end
end
-module Kernel
- # Creates a new IRB::Context with the given +object+ and runs it.
- def irb(object, binding = nil)
- IRB::Context.new(object, binding).run
- end
-
- private :irb
-end
+# module Kernel
+# # Creates a new IRB::Context with the given +object+ and runs it.
+# def irb(object, binding = nil)
+# IRB::Context.new(object, binding).run
+# end
+#
+# private :irb
+# end
Added: DietRB/trunk/lib/irb/driver/readline.rb
===================================================================
--- DietRB/trunk/lib/irb/driver/readline.rb (rev 0)
+++ DietRB/trunk/lib/irb/driver/readline.rb 2010-10-08 11:05:23 UTC (rev 4725)
@@ -0,0 +1,22 @@
+require 'readline'
+require 'irb/driver/tty'
+require 'irb/ext/history'
+require 'irb/ext/completion'
+
+module IRB
+ module Driver
+ class Readline < TTY
+ def initialize(input = $stdin, output = $stdout)
+ super
+ ::Readline.input = @input
+ ::Readline.output = @output
+ end
+
+ def readline
+ ::Readline.readline(context.prompt, true)
+ end
+ end
+ end
+end
+
+IRB.driver = IRB::Driver::Readline.new
\ No newline at end of file
Added: DietRB/trunk/lib/irb/driver/socket.rb
===================================================================
--- DietRB/trunk/lib/irb/driver/socket.rb (rev 0)
+++ DietRB/trunk/lib/irb/driver/socket.rb 2010-10-08 11:05:23 UTC (rev 4725)
@@ -0,0 +1,35 @@
+# require 'irb/driver/readline'
+require 'irb/driver/tty'
+require 'socket'
+
+TOPLEVEL_OBJECT = self
+
+module IRB
+ module Driver
+ class Socket
+ # DEFAULTS = {
+ # :tty_exit_on_eof => false,
+ # :term => "\r\0"
+ # }
+
+ def initialize(host = '127.0.0.1', port = 7829)
+ # @options = DEFAULTS.merge(options)
+ @host, @port = host, port
+ @server = TCPServer.new(host, port)
+ end
+
+ def run
+ $stderr.puts "[!] Running IRB server on #{@host}:#{@port}"
+ loop do
+ connection = @server.accept
+ # TODO libedit doesn't use the right input and output!!
+ # IRB.driver = IRB::Driver::Readline.new(connection, connection)
+ IRB.driver = IRB::Driver::TTY.new(connection, connection)
+ context = IRB::Context.new(IRB.driver, TOPLEVEL_OBJECT, TOPLEVEL_BINDING.dup)
+ IRB.driver.run(context)
+ connection.close
+ end
+ end
+ end
+ end
+end
\ No newline at end of file
Added: DietRB/trunk/lib/irb/driver/tty.rb
===================================================================
--- DietRB/trunk/lib/irb/driver/tty.rb (rev 0)
+++ DietRB/trunk/lib/irb/driver/tty.rb 2010-10-08 11:05:23 UTC (rev 4725)
@@ -0,0 +1,104 @@
+module IRB
+ class Context
+ class << self
+ # attr_accessor :current
+ def current
+ Thread.current[:context]
+ end
+
+ def current=(context)
+ Thread.current[:context] = context
+ end
+
+ # TODO move into driver
+ def make_current(context)
+ before, self.current = self.current, context
+ yield
+ ensure
+ self.current = before
+ end
+ end
+ end
+
+ class << self
+ # attr_accessor :driver
+ # def driver
+ # @driver ||= Driver::TTY.new
+ # end
+
+ def driver=(driver)
+ Thread.current[:driver] = driver
+ end
+
+ def driver
+ Thread.current[:driver]
+ end
+ end
+
+ module Driver
+ class TTY
+ def initialize(input = $stdin, output = $stdout)
+ @input = input
+ @output = output
+ @running = false
+ end
+
+ def context
+ Context.current
+ end
+
+ def readline
+ @output.print(context.prompt)
+ @input.gets
+ end
+
+ def consume
+ readline
+ rescue Interrupt
+ context.clear_buffer
+ ""
+ end
+
+ def run(context)
+ with_io do
+ Context.make_current(context) do
+ while line = consume
+ continue = context.process_line(line)
+ break unless continue
+ end
+ end
+ end
+ end
+
+ def puts(*args)
+ @output.puts(*args)
+ end
+
+ def print(*args)
+ @output.print(*args)
+ @output.flush
+ end
+
+ def with_io
+ if @input_before.nil?
+ @input_before, @output_before = $stdin, $stdout
+ $stdin, $stdout = @input, @output
+ end
+ yield
+ ensure
+ $stdin, $stdout = @input_before, @output_before
+ end
+ end
+ end
+end
+
+IRB.driver = IRB::Driver::TTY.new
+
+module Kernel
+ # Creates a new IRB::Context with the given +object+ and runs it.
+ def irb(object, binding = nil)
+ IRB.driver.run(IRB::Context.new(IRB.driver, object, binding))
+ end
+
+ private :irb
+end
\ No newline at end of file
Modified: DietRB/trunk/lib/irb.rb
===================================================================
--- DietRB/trunk/lib/irb.rb 2010-10-08 11:05:11 UTC (rev 4724)
+++ DietRB/trunk/lib/irb.rb 2010-10-08 11:05:23 UTC (rev 4725)
@@ -5,15 +5,17 @@
# Copyright (C) 2009-2010, Eloy Duran <eloy.de.enige at gmail.com>
require 'irb/context'
-require 'irb/io'
+
+# require 'irb/io'
+# require 'irb/driver/tty'
+# require 'irb/driver/readline'
+require 'irb/driver/socket'
+
require 'irb/source'
require 'irb/version'
require 'irb/deprecated'
-require 'irb/ext/history'
-require 'irb/ext/completion'
-
# if !ENV['SPECCING'] && defined?(RUBY_ENGINE) && RUBY_ENGINE == "macruby"
# require 'irb/ext/macruby'
# end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101008/6e9b776c/attachment-0001.html>
More information about the macruby-changes
mailing list