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.



1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
# File 'lib/a-core.rb', line 1287

def initialize
  super
  title 'ArcadiaSh'
  geometry = '800x200+10+10'
  geometry(geometry)
  @text = TkScrollText.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.show
  @text.show_v_scroll
  @text.show_h_scroll
  #@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.



1286
1287
1288
# File 'lib/a-core.rb', line 1286

def result
  @result
end

#waitObject (readonly)

Returns the value of attribute wait.



1286
1287
1288
# File 'lib/a-core.rb', line 1286

def wait
  @wait
end

Instance Method Details

#exec(_cmd) ⇒ Object



1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
# File 'lib/a-core.rb', line 1365

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



1314
1315
1316
1317
1318
1319
# File 'lib/a-core.rb', line 1314

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



1355
1356
1357
1358
# File 'lib/a-core.rb', line 1355

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

#input(_char) ⇒ Object



1321
1322
1323
1324
1325
1326
1327
# File 'lib/a-core.rb', line 1321

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

#out(_str, *tags) ⇒ Object



1402
1403
1404
# File 'lib/a-core.rb', line 1402

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

#prepare_exec(_cmd) ⇒ Object



1360
1361
1362
1363
# File 'lib/a-core.rb', line 1360

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

#promptObject



1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
# File 'lib/a-core.rb', line 1329

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