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.


2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
# File 'lib/a-core.rb', line 2740

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","%K"){|_keysym| input(_keysym)}
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result


2739
2740
2741
# File 'lib/a-core.rb', line 2739

def result
  @result
end

#waitObject (readonly)

Returns the value of attribute wait


2739
2740
2741
# File 'lib/a-core.rb', line 2739

def wait
  @wait
end

Instance Method Details

#exec(_cmd) ⇒ Object


2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
# File 'lib/a-core.rb', line 2817

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 OS.windows?
        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


2766
2767
2768
2769
2770
2771
# File 'lib/a-core.rb', line 2766

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


2807
2808
2809
2810
# File 'lib/a-core.rb', line 2807

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

#input(_char) ⇒ Object


2773
2774
2775
2776
2777
2778
2779
# File 'lib/a-core.rb', line 2773

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

#out(_str, *tags) ⇒ Object


2854
2855
2856
# File 'lib/a-core.rb', line 2854

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

#prepare_exec(_cmd) ⇒ Object


2812
2813
2814
2815
# File 'lib/a-core.rb', line 2812

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

#promptObject


2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
# File 'lib/a-core.rb', line 2781

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