Module: Shoes::Debugger

Defined in:
lib/shoes/debugger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#byethrObject

Returns the value of attribute byethr



69
70
71
# File 'lib/shoes/debugger.rb', line 69

def byethr
  @byethr
end

#cmdObject

Returns the value of attribute cmd



69
70
71
# File 'lib/shoes/debugger.rb', line 69

def cmd
  @cmd
end

#gets_cvObject

Returns the value of attribute gets_cv



69
70
71
# File 'lib/shoes/debugger.rb', line 69

def gets_cv
  @gets_cv
end

#gets_mutexObject

Returns the value of attribute gets_mutex



69
70
71
# File 'lib/shoes/debugger.rb', line 69

def gets_mutex
  @gets_mutex
end

#strObject

Returns the value of attribute str



69
70
71
# File 'lib/shoes/debugger.rb', line 69

def str
  @str
end

Instance Method Details

#setup(path) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/shoes/debugger.rb', line 78

def setup path
 $stdout.puts "Debugger setup called"
 # Byebug::Runner.new.run
 dbg = Byebug::Runner.new
 $PROGRAM_NAME = path
 # patch in IO
 intf = Byebug::MimickBye.new self
 Byebug.handler.interface = intf # expect trouble
 @str, @cmd = [], ""
 stack :width => 1.0, :height => 1.0 do
   stack :width => 1.0, :height => 30 do
     background white
     para "Shoes debugger ready.", :stroke => red
   end
   @scroll =
     stack :width => 1.0, :height => -50, :scroll => true do
       @console = para @str, :font => "Monospace 14px", :wrap => "char"
       @console.cursor = -1
     end
 end
 # Now it gets tricky - need a new thread that runs byebug (and it's gets() )
 # and we want to make sure the Console window is on screen
 # and we need a mutex + condition variable
 @gets_mutex = Mutex.new
 @gets_cv = ConditionVariable.new
 $stderr.puts "S-Thr: #{Thread.current.inspect}"
 $stderr.puts "S-MTX: #{@gets_mutex.object_id}"
 $stderr.puts "S-CV: #{@gets_cv.object_id}"

 start do # after gui is running
   @byethr = Byebug::DebugThread.new {
     Byebug.debug_load($PROGRAM_NAME, true) # this starts byebug loop
     $stderr.puts 'byebug return'
     #test - echo
     #loop {
     #  str = intf.readline('test: ')
     #  intf.puts "got: #{str}\n"
     #}
   }
 end
 
 @cmd = ""
 @console.cursor = -1
   keypress do |k|
    case k
    when "\n"
       @str += ["#{@cmd}\n"]
       # signal that we have a line to process.
       $stderr.puts "S-Thr: #{Thread.current.inspect}"
       $stderr.puts "S-MTX: #{@gets_mutex.object_id}"
       $stderr.puts "S-CV: #{@gets_cv.object_id}"
       @gets_mutex.synchronize {
         $stderr.puts "signaling"
         intf.cmdl = "#{@cmd}\n"
         @gets_cv.signal
         $stderr.puts "signal done"
       }
       #write_string "#{@cmd}\n" # just echo for now
       @cmd = ""
       @console.cursor = -1
    when String
      @cmd.insert(@console.cursor, k)
    when :backspace
      @cmd.slice!(@console.cursor)
    when :delete
      @cmd.slice!(@console.cursor += 1) if @console.cursor < -1
    when :tab
      @cmd += "  "
    when :alt_q
      quit
    when :alt_c
      self.clipboard = @cmd
    when :alt_v
      @cmd += self.clipboard
    when :left
      @console.cursor -= 1 unless @cmd.length < -@console.cursor
    when :right
      @console.cursor += 1 if @console.cursor < -1
    when :up
      if @history[:pointer] > 0
         @history[:pointer] -= 1
         @cmd = @history[:cmd][@history[:pointer]].dup
      end
    when :down
      if @history[:pointer] < @history[:cmd].size
         @history[:pointer] += 1
         @cmd = @history[:cmd][@history[:pointer]].dup
      end
    end
    @console.replace *(@str + [@cmd])
    @scroll.scroll_top = @scroll.scroll_max
  end
end

#write_string(outstr) ⇒ Object



71
72
73
74
75
76
# File 'lib/shoes/debugger.rb', line 71

def write_string  outstr
  #puts "write: #{@str} #{outstr}"
  @str += [outstr]
  @console.replace *(@str)
  @scroll.scroll_top = @scroll.scroll_max
end