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.



1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
# File 'lib/a-core.rb', line 1698

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.



1697
1698
1699
# File 'lib/a-core.rb', line 1697

def result
  @result
end

#waitObject (readonly)

Returns the value of attribute wait.



1697
1698
1699
# File 'lib/a-core.rb', line 1697

def wait
  @wait
end

Instance Method Details

#exec(_cmd) ⇒ Object



1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
# File 'lib/a-core.rb', line 1775

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



1724
1725
1726
1727
1728
1729
# File 'lib/a-core.rb', line 1724

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



1765
1766
1767
1768
# File 'lib/a-core.rb', line 1765

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

#input(_char) ⇒ Object



1731
1732
1733
1734
1735
1736
1737
# File 'lib/a-core.rb', line 1731

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

#out(_str, *tags) ⇒ Object



1812
1813
1814
# File 'lib/a-core.rb', line 1812

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

#prepare_exec(_cmd) ⇒ Object



1770
1771
1772
1773
# File 'lib/a-core.rb', line 1770

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

#promptObject



1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
# File 'lib/a-core.rb', line 1739

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