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.



2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
# File 'lib/a-core.rb', line 2239

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.



2238
2239
2240
# File 'lib/a-core.rb', line 2238

def result
  @result
end

#waitObject (readonly)

Returns the value of attribute wait.



2238
2239
2240
# File 'lib/a-core.rb', line 2238

def wait
  @wait
end

Instance Method Details

#exec(_cmd) ⇒ Object



2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
# File 'lib/a-core.rb', line 2316

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



2265
2266
2267
2268
2269
2270
# File 'lib/a-core.rb', line 2265

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



2306
2307
2308
2309
# File 'lib/a-core.rb', line 2306

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

#input(_char) ⇒ Object



2272
2273
2274
2275
2276
2277
2278
# File 'lib/a-core.rb', line 2272

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

#out(_str, *tags) ⇒ Object



2353
2354
2355
# File 'lib/a-core.rb', line 2353

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

#prepare_exec(_cmd) ⇒ Object



2311
2312
2313
2314
# File 'lib/a-core.rb', line 2311

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

#promptObject



2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
# File 'lib/a-core.rb', line 2280

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