Class: ArcadiaSh
- Inherits:
-
TkToplevel
- Object
- TkToplevel
- ArcadiaSh
- Defined in:
- lib/a-core.rb
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#wait ⇒ Object
readonly
Returns the value of attribute wait.
Instance Method Summary collapse
- #exec(_cmd) ⇒ Object
- #exec_buffer ⇒ Object
- #exec_prompt(_cmd) ⇒ Object
-
#initialize ⇒ ArcadiaSh
constructor
A new instance of ArcadiaSh.
- #input(_char) ⇒ Object
- #out(_str, *tags) ⇒ Object
- #prepare_exec(_cmd) ⇒ Object
- #prompt ⇒ Object
Constructor Details
#initialize ⇒ ArcadiaSh
Returns a new instance of ArcadiaSh.
2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 |
# File 'lib/a-core.rb', line 2270 def initialize super title 'ArcadiaSh' iconphoto(Arcadia.image_res(ARCADIA_RING_GIF)) if Arcadia.instance.tcltk_info.level >= '8.4.9' geometry = '800x200+10+10' geometry(geometry) @text = TkText.new(self, Arcadia.style('text')){ wrap 'none' undo true insertofftime 200 insertontime 200 highlightthickness 0 insertbackground #000000 insertwidth 6 } @text.set_focus @text.tag_configure('error', 'foreground' => '#d93421') @text.tag_configure('response', 'foreground' => '#2c51d9') @text.extend(TkScrollableWidget).show #@input_buffer = '' @wait = true @result = false prompt @text.bind_append("KeyPress"){|e| input(e.keysym)} end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
2269 2270 2271 |
# File 'lib/a-core.rb', line 2269 def result @result end |
#wait ⇒ Object (readonly)
Returns the value of attribute wait.
2269 2270 2271 |
# File 'lib/a-core.rb', line 2269 def wait @wait end |
Instance Method Details
#exec(_cmd) ⇒ Object
2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 |
# File 'lib/a-core.rb', line 2347 def exec(_cmd) return if _cmd.nil? || _cmd.length ==0 @b_exec.destroy if defined?(@b_exec) out("submitted...\n") case _cmd when 'clear' @text.delete('0.0','end') else begin if OS.windows? p = IO::popen("#{_cmd} 2>&1") out(p.read, 'response') @result = true else require "open3" Open3.popen3("#{_cmd}"){|stdin, stdout, stderr| stdout.each do |line| out(line,'response') @result = true end stderr.each do |line| out(line,'error') @result = false end } end rescue Exception => e out("#{e.}\n",'error') @result = false end end @b_exit.destroy if defined?(@b_exit) prompt @text.see('end') end |
#exec_buffer ⇒ Object
2296 2297 2298 2299 2300 2301 |
# File 'lib/a-core.rb', line 2296 def exec_buffer @text.set_insert("end") input_buffer = @text.get(@index_cmd_begin,"insert") out("\n") exec(input_buffer) end |
#exec_prompt(_cmd) ⇒ Object
2337 2338 2339 2340 |
# File 'lib/a-core.rb', line 2337 def exec_prompt(_cmd) out("#{_cmd}\n") exec(_cmd) end |
#input(_char) ⇒ Object
2303 2304 2305 2306 2307 2308 2309 |
# File 'lib/a-core.rb', line 2303 def input(_char) case _char when 'Return' Thread.new{exec_buffer} Tk.callback_break end end |
#out(_str, *tags) ⇒ Object
2384 2385 2386 |
# File 'lib/a-core.rb', line 2384 def out(_str,*) @text.insert('end',_str,*) end |
#prepare_exec(_cmd) ⇒ Object
2342 2343 2344 2345 |
# File 'lib/a-core.rb', line 2342 def prepare_exec(_cmd) #@input_buffer=_cmd out("#{_cmd}") end |
#prompt ⇒ Object
2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 |
# File 'lib/a-core.rb', line 2311 def prompt @b_exit = TkButton.new(@text, 'command'=>proc{@wait=false}, 'text'=>'Exit', 'padx'=>0, 'pady'=>0, 'width'=>5, 'foreground' => 'white', 'background' => '#d92328', 'relief'=>'flat') TkTextWindow.new(@text, "end", 'window'=> @b_exit) @b_exec = TkButton.new(@text, 'command'=>proc{Thread.new{exec_buffer}}, 'text'=>'Exec', 'padx'=>0, 'pady'=>0, 'width'=>5, 'foreground' => 'white', 'background' => '#1ba626', 'relief'=>'flat') TkTextWindow.new(@text, "end", 'window'=> @b_exec) out("\n") out(">>> ") @index_cmd_begin = @text.index('insert') end |