Class: FXIrb
- Inherits:
-
FXText
- Object
- FXText
- FXIrb
- Includes:
- Responder, Singleton
- Defined in:
- lib/fxirb.rb
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
Class Method Summary collapse
Instance Method Summary collapse
- #create ⇒ Object
- #emptyline? ⇒ Boolean
- #getline ⇒ Object
- #gets ⇒ Object
- #indented? ⇒ Boolean
-
#initialize(p, tgt, sel, opts) ⇒ FXIrb
constructor
A new instance of FXIrb.
- #newLineEntered ⇒ Object
- #onKeyPress(sender, sel, event) ⇒ Object
- #onKeyRelease(sender, sel, event) ⇒ Object
- #onLeftBtnPress(sender, sel, event) ⇒ Object
- #onLeftBtnRelease(sender, sel, event) ⇒ Object
- #onMiddleBtnPress(sender, sel, event) ⇒ Object
- #processCommandLine(cmd) ⇒ Object
- #restart ⇒ Object
- #rmline ⇒ Object
- #sendCommand(cmd) ⇒ Object
- #write(obj) ⇒ Object
Constructor Details
#initialize(p, tgt, sel, opts) ⇒ FXIrb
Returns a new instance of FXIrb.
122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/fxirb.rb', line 122 def initialize(p, tgt, sel, opts) @parent = p FXMAPFUNC(SEL_KEYRELEASE, 0, "onKeyRelease") FXMAPFUNC(SEL_KEYPRESS, 0, "onKeyPress") FXMAPFUNC(SEL_LEFTBUTTONPRESS,0,"onLeftBtnPress") FXMAPFUNC(SEL_MIDDLEBUTTONPRESS,0,"onMiddleBtnPress") FXMAPFUNC(SEL_LEFTBUTTONRELEASE,0,"onLeftBtnRelease") super setFont(FXFont.new(FXApp.instance, "lucida console", 9)) end |
Instance Attribute Details
#input ⇒ Object (readonly)
Returns the value of attribute input.
108 109 110 |
# File 'lib/fxirb.rb', line 108 def input @input end |
Class Method Details
.init(p, tgt, sel, opts) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/fxirb.rb', line 110 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 |
Instance Method Details
#create ⇒ Object
134 135 136 137 |
# File 'lib/fxirb.rb', line 134 def create super restart end |
#emptyline? ⇒ Boolean
262 263 264 |
# File 'lib/fxirb.rb', line 262 def emptyline? getline == "" end |
#getline ⇒ Object
252 253 254 |
# File 'lib/fxirb.rb', line 252 def getline extractText(@anchor, getLength-@anchor) end |
#gets ⇒ Object
317 318 319 320 321 322 323 324 |
# File 'lib/fxirb.rb', line 317 def gets @anchor = getLength if !@inputAdded Thread.stop end @inputAdded = false return @input[0].gets end |
#indented? ⇒ Boolean
266 267 268 |
# File 'lib/fxirb.rb', line 266 def indented? extractText(@anchor-2, 2) == " " end |
#newLineEntered ⇒ Object
290 291 292 |
# File 'lib/fxirb.rb', line 290 def newLineEntered processCommandLine(extractText(@anchor, getLength-@anchor)) end |
#onKeyPress(sender, sel, event) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/fxirb.rb', line 169 def onKeyPress(sender,sel,event) case event.code when Fox::KEY_Return, Fox::KEY_KP_Enter setCursorPos(getLength) super when Fox::KEY_Up,Fox::KEY_KP_Up str = @im.prevCmd.chop if str != "" removeText(@anchor, getLength-@anchor) write(str) end when Fox::KEY_Down,Fox::KEY_KP_Down str = @im.nextCmd.chop if str != "" removeText(@anchor, getLength-@anchor) write(str) end when Fox::KEY_Left,Fox::KEY_KP_Left if getCursorPos > @anchor super end when Fox::KEY_Delete,Fox::KEY_KP_Delete,Fox::KEY_BackSpace if getCursorPos > @anchor super end when Fox::KEY_Home, Fox::KEY_KP_Home setCursorPos(@anchor) when Fox::KEY_End, Fox::KEY_KP_End setCursorPos(getLength) when Fox::KEY_Page_Up, Fox::KEY_KP_Page_Up, Fox::KEY_Page_Down, Fox::KEY_KP_Page_Down when Fox::KEY_bracketright #auto-dedent if the } or ] is on a line by itself if (emptyline? or (getline == "en")) and indented? str = getline @anchor -= 2 rmline appendText(str) setCursorPos(getLength) end super when Fox::KEY_u if (event.state & CONTROLMASK) != 0 str = extractText(getCursorPos, getLength - getCursorPos) rmline appendText(str) setCursorPos(@anchor) end super when Fox::KEY_k if (event.state & CONTROLMASK) != 0 str = extractText(@anchor, getCursorPos-@anchor) rmline appendText(str) setCursorPos(getLength) end super when Fox::KEY_d if (event.state & CONTROLMASK) != 0 restart =begin #Ctrl - D rmline appendText(exit) sendCommand("exit") newLineEntered =end else # test for 'end' so we can dedent if (getline == "en") and indented? str = getline @anchor -= 2 rmline appendText(str) setCursorPos(getLength) end end super else super end end |
#onKeyRelease(sender, sel, event) ⇒ Object
161 162 163 164 165 166 167 |
# File 'lib/fxirb.rb', line 161 def onKeyRelease(sender, sel, event) case event.code when Fox::KEY_Return, Fox::KEY_KP_Enter newLineEntered end return 1 end |
#onLeftBtnPress(sender, sel, event) ⇒ Object
270 271 272 273 274 |
# File 'lib/fxirb.rb', line 270 def onLeftBtnPress(sender,sel,event) @store_anchor = @anchor setFocus super end |
#onLeftBtnRelease(sender, sel, event) ⇒ Object
276 277 278 279 280 281 |
# File 'lib/fxirb.rb', line 276 def onLeftBtnRelease(sender,sel,event) super @anchor = @store_anchor setCursorPos(@anchor) setCursorPos(getLength) end |
#onMiddleBtnPress(sender, sel, event) ⇒ Object
283 284 285 286 287 288 |
# File 'lib/fxirb.rb', line 283 def onMiddleBtnPress(sender,sel,event) pos=getPosAt(event.win_x,event.win_y) if pos >= @anchor super end end |
#processCommandLine(cmd) ⇒ Object
294 295 296 297 298 299 |
# File 'lib/fxirb.rb', line 294 def processCommandLine(cmd) #write("[#{cmd}]") @input[1].puts cmd @inputAdded = true @irb.run end |
#restart ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/fxirb.rb', line 139 def restart setFocus setText("") # IRB initialization @inputAdded = false @input = IO.pipe $DEFAULT_OUTPUT = self @im = FXIRBInputMethod.new if @irb @irb.kill @irb = Thread.new { IRB.restart(@im) } else @irb = Thread.new { IRB.start_in_fxirb(@im) } end end |
#rmline ⇒ Object
256 257 258 259 260 |
# File 'lib/fxirb.rb', line 256 def rmline str = getline removeText(@anchor, getLength-@anchor) str end |
#sendCommand(cmd) ⇒ Object
301 302 303 304 305 306 307 |
# File 'lib/fxirb.rb', line 301 def sendCommand(cmd) setCursorPos(getLength) makePositionVisible(getLength) unless isPosVisible(getLength) cmd += "\n" appendText(cmd) processCommandLine(cmd) end |
#write(obj) ⇒ Object
309 310 311 312 313 314 315 |
# File 'lib/fxirb.rb', line 309 def write(obj) str = obj.to_s appendText(str) setCursorPos(getLength) makePositionVisible(getLength) unless isPosVisible(getLength) return str.length end |