freeride-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [FR-devel] FXIrb (was: IRB plugin)


From: Gilles Filippini
Subject: Re: [FR-devel] FXIrb (was: IRB plugin)
Date: Wed, 03 Jul 2002 22:55:17 +0200

Gilles Filippini wrote:
> 
> I've been myself working on a kind of FXIrb widget. While it uses
> FXScintilla, I think FXText should actually be sufficient.
> I still have to clean the code here and there then I'll send it to the
> list so we could share our views.
> 

Here it is. See the attached FXIrb.rb file. Status: *alpha*
Please note that you'll need FXRuby-1.0.11 plus the attached patch.
#! /usr/bin/env ruby

# TODO
# - ^D
# - map standard error
# - readonly everywhere but for the command line
# - readline

require "fox"
require "fox/scintilla"
require "irb"
require "singleton"

include Fox

STDOUT.sync = true

module IOEmulate # Named after RubyWin's IOEmulate module
        def gets
                return FXIrb.instance.gets
        end

        def p(obj)
                return FXIrb.instance.write(obj.to_s + "\n")
        end

        def putc(ch)
                FXIrb.instance.write("" << ch)
        end
end

include IOEmulate

module IRB
  class FXIRBInputMethod < StdioInputMethod
    def gets 
      print @prompt
      str = IOEmulate.gets
      if /^exit/ =~ str
        exit
      end
      @address@hidden += 1] = str
    end
  end

  def IRB.start_in_fxirb
    IRB.initialize(nil)
    IRB.parse_opts
    IRB.load_modules

    im = FXIRBInputMethod.new
    irb = Irb.new(nil, im)

    @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
    @CONF[:MAIN_CONTEXT] = irb.context
    trap("SIGINT") do
      irb.signal_handle
    end
    
    catch(:IRB_EXIT) do
      irb.eval_input
    end
    print "\n"
        end

end

class FXIrb < FXScintilla
        include Singleton
        include Responder

        ID_EDITOR, ID_LAST = enum(FXScintilla::ID_LAST, 2)

        def FXIrb.init(p, tgt, sel, opts)
                unless @__instance__
                        Thread.critical = true
                        begin
                                @__instance__ ||= new(p, tgt, sel, opts)
                        ensure
                                Thread.critical = false
                        end
                end
                return @__instance__
        end

        def initialize(p, tgt, sel, opts)
                FXMAPFUNC(SEL_COMMAND, 0, "onCmdNotify")

                super
                styleSetFont(STYLE_DEFAULT, "fixed")
                styleSetSize(STYLE_DEFAULT, 12)
                styleClearAll
                setMarginWidthN(0, 0)
                setMarginWidthN(1, 0)
                setMarginWidthN(2, 0)
        end

        def create
                super
                setFocus
                # IRB initialization
                @input = IO.pipe
                $> = self
                @irb = Thread.new {
                        sleep(1)
                        IRB.start_in_fxirb
                }
        end

        def onCmdNotify(sender, sel, notification)
                case notification.nmhdr.code
                when SCN_CHARADDED
                        if notification.ch == "\n"[0]
                                newLineEntered
                        end
                end
                return 1
        end

        def getRange(start, last)
                tr1 = TextRange.new(start, last, last-start+1)
                getTextRange(tr1)
                return tr1.lpstrText

        end

        def newLineEntered
                processCommandLine(getRange(@anchor, getTextLength))
        end

        def processCommandLine(cmd)
                @input[1].puts cmd
        end

        def sendCommand(cmd)
                documentEnd
                cmd += "\n"
                addText(cmd.length, cmd)
                processCommandLine(cmd)
        end

        def write(obj)
                str = obj.to_s
                addText(str.length, str)
                documentEnd
                return str.length
        end

        def gets
                @anchor = getTextLength
                return @input[0].gets
        end

end

# Stand alone run
if __FILE__ == $0
        application = FXApp.new("FXIrb", "ruby")
  application.threadsEnabled = true
        Thread.abort_on_exception = true
        application.init(ARGV)
        window = FXMainWindow.new(application, "FXIrb", nil, nil, DECOR_ALL, 0, 
0, 580, 600)
        FXIrb.init(window, nil, 0, LAYOUT_FILL_X|LAYOUT_FILL_Y)
        application.create
        window.show(PLACEMENT_SCREEN)
        application.run
end
*** ext/fox/scintilla_wrap.cpp  Thu Jun 20 16:09:13 2002
--- ext/fox/scintilla_wrap.cpp.new      Sat Jun 29 08:40:32 2002
***************
*** 385,390 ****
--- 385,393 ----
          case T_FALSE:
            lp=(lParam==Qtrue) ? 1 : 0;
            break;
+         case T_DATA:
+           lp=reinterpret_cast<sptr_t>(DATA_PTR(lParam));
+           break;
          default:
            lp=0;
            break;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]