class ArcadiaSh
Attributes
result[R]
wait[R]
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/a-core.rb, line 2740 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","%K"){|_keysym| input(_keysym)} end
Public Instance Methods
exec(_cmd)
click to toggle source
# File lib/a-core.rb, line 2817 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.message}\n",'error') @result = false end end @b_exit.destroy if defined?(@b_exit) prompt @text.see('end') end
exec_buffer()
click to toggle source
# File lib/a-core.rb, line 2766 def exec_buffer @text.set_insert("end") input_buffer = @text.get(@index_cmd_begin,"insert") out("\n") exec(input_buffer) end
exec_prompt(_cmd)
click to toggle source
# File lib/a-core.rb, line 2807 def exec_prompt(_cmd) out("#{_cmd}\n") exec(_cmd) end
input(_char)
click to toggle source
# File lib/a-core.rb, line 2773 def input(_char) case _char when 'Return' Thread.new{exec_buffer} Tk.callback_break end end
out(_str,*tags)
click to toggle source
# File lib/a-core.rb, line 2854 def out(_str,*tags) @text.insert('end',_str,*tags) end
prepare_exec(_cmd)
click to toggle source
# File lib/a-core.rb, line 2812 def prepare_exec(_cmd) #@input_buffer=_cmd out("#{_cmd}") end
prompt()
click to toggle source
# File lib/a-core.rb, line 2781 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