Class: ArcadiaSh

Inherits:
TkToplevel
  • Object
show all
Defined in:
lib/a-core.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeArcadiaSh

Returns a new instance of ArcadiaSh.



2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
# File 'lib/a-core.rb', line 2116

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

#resultObject (readonly)

Returns the value of attribute result.



2115
2116
2117
# File 'lib/a-core.rb', line 2115

def result
  @result
end

#waitObject (readonly)

Returns the value of attribute wait.



2115
2116
2117
# File 'lib/a-core.rb', line 2115

def wait
  @wait
end

Instance Method Details

#exec(_cmd) ⇒ Object



2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
# File 'lib/a-core.rb', line 2193

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 RUBY_PLATFORM =~ /mingw|mswin/
       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_bufferObject



2142
2143
2144
2145
2146
2147
# File 'lib/a-core.rb', line 2142

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



2183
2184
2185
2186
# File 'lib/a-core.rb', line 2183

def exec_prompt(_cmd)
  out("#{_cmd}\n")
  exec(_cmd)
end

#input(_char) ⇒ Object



2149
2150
2151
2152
2153
2154
2155
# File 'lib/a-core.rb', line 2149

def input(_char)
  case _char
    when 'Return'
      Thread.new{exec_buffer}
      Tk.callback_break
  end
end

#out(_str, *tags) ⇒ Object



2230
2231
2232
# File 'lib/a-core.rb', line 2230

def out(_str,*tags)
  @text.insert('end',_str,*tags)
end

#prepare_exec(_cmd) ⇒ Object



2188
2189
2190
2191
# File 'lib/a-core.rb', line 2188

def prepare_exec(_cmd)
  #@input_buffer=_cmd
  out("#{_cmd}")
end

#promptObject



2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
# File 'lib/a-core.rb', line 2157

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