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.



1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
# File 'lib/a-core.rb', line 1685

def initialize
  super
  title 'ArcadiaSh'
  iconphoto(TkPhotoImage.new('dat'=>ARCADIA_RING_GIF))
  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.



1684
1685
1686
# File 'lib/a-core.rb', line 1684

def result
  @result
end

#waitObject (readonly)

Returns the value of attribute wait.



1684
1685
1686
# File 'lib/a-core.rb', line 1684

def wait
  @wait
end

Instance Method Details

#exec(_cmd) ⇒ Object



1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
# File 'lib/a-core.rb', line 1762

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



1711
1712
1713
1714
1715
1716
# File 'lib/a-core.rb', line 1711

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



1752
1753
1754
1755
# File 'lib/a-core.rb', line 1752

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

#input(_char) ⇒ Object



1718
1719
1720
1721
1722
1723
1724
# File 'lib/a-core.rb', line 1718

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

#out(_str, *tags) ⇒ Object



1799
1800
1801
# File 'lib/a-core.rb', line 1799

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

#prepare_exec(_cmd) ⇒ Object



1757
1758
1759
1760
# File 'lib/a-core.rb', line 1757

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

#promptObject



1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
# File 'lib/a-core.rb', line 1726

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