Class: Fugit::Console

Inherits:
Panel
  • Object
show all
Defined in:
lib/fugit/console.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ Console

Returns a new instance of Console.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fugit/console.rb', line 7

def initialize(parent)
  super(parent, ID_ANY)

  @input = TextCtrl.new(self, ID_ANY, nil, nil, Size.new(20, 20), TE_PROCESS_ENTER)
  @output = TextCtrl.new(self, ID_ANY, nil, nil, Size.new(20, 20), NO_BORDER|TE_MULTILINE|TE_READONLY|TE_DONTWRAP)

  box = BoxSizer.new(VERTICAL)
  box.add(@output, 1, EXPAND)
  box.add(@input, 0, EXPAND)
  self.set_sizer(box)

  evt_text_enter(@input.get_id(), :on_run_command)
end

Instance Attribute Details

#inputObject

Returns the value of attribute input.



5
6
7
# File 'lib/fugit/console.rb', line 5

def input
  @input
end

#outputObject

Returns the value of attribute output.



5
6
7
# File 'lib/fugit/console.rb', line 5

def output
  @output
end

Instance Method Details

#on_run_command(event) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/fugit/console.rb', line 21

def on_run_command(event)
  cmd = @input.get_value
  begin
    result = IO.popen(cmd).readlines
    @output.append_text("> #{cmd}\n#{result}\n")
  rescue
    @output.append_text("> #{cmd}\nThere was an error running the command\n")
  end
  @input.clear
end