Class | Ui::WxWidgets::Widgets::BufferedTextCtrl |
In: |
ui/wx/widgets/console.rb
|
Parent: | Wx::TextCtrl |
# File ui/wx/widgets/console.rb, line 42 def initialize(parent, name) super( parent, Wx::ID_ANY, '', Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, Wx::TE_PROCESS_ENTER, Wx::DEFAULT_VALIDATOR, name) evt_char do | event | on_char(event) end #initialize internal history buffer @history = [] @pointer = 0 @up = true end
Returns the last command issued by the user. This method should be used when the parent window captures a returnPressed event to examine the las line inputted by the user.
# File ui/wx/widgets/console.rb, line 99 def last_command() @history.last end
# File ui/wx/widgets/console.rb, line 61 def on_char(event) case (event.key_code) when Wx::K_UP if ((@history.size > 0) && (@pointer >= 0) ) if (@pointer == @history.size) @history << self.get_value end @pointer -= 1 if @pointer > 0 self.set_value( @history[@pointer] ) self.set_insertion_point_end() end when Wx::K_DOWN if ((@history.size > 0) && (@pointer < @history.size) ) @pointer += 1 if @pointer < @history.size - 1 self.set_value( @history[@pointer] ) self.set_insertion_point_end() end when Wx::K_RETURN $logger.debug(@history) #keep an eye on the last entry to avoid empty entries in the list if ((@history.size > 0) && (@history.last.strip.size == 0) ) @history.pop end line = self.get_value.strip if line.size > 0 @history << line @pointer = @history.size self.clear end $logger.debug(@history) end event.skip end