Class: BashParser
- Inherits:
-
Object
- Object
- BashParser
- Defined in:
- lib/bashparser.rb
Constant Summary collapse
- INACTIVE =
nil
- ESCAPE_BYTE =
27
- CURSOR_MOVEMENT_ESCAPE_CHARS =
['H', 'J']
Class Method Summary collapse
-
.is_complete_escape_code(escape_code) ⇒ Object
assumes escape character is removed.
- .seperate_by_escape_codes(input) ⇒ Object
Instance Method Summary collapse
- #display_screen(all_input = nil) ⇒ Object
-
#initialize ⇒ BashParser
constructor
A new instance of BashParser.
- #parse_input(input) ⇒ Object
- #reset_buffer ⇒ Object
- #save_input_to_file(input, file_name) ⇒ Object
Constructor Details
#initialize ⇒ BashParser
Returns a new instance of BashParser.
13 14 15 |
# File 'lib/bashparser.rb', line 13 def initialize reset_buffer end |
Class Method Details
.is_complete_escape_code(escape_code) ⇒ Object
assumes escape character is removed
75 76 77 78 |
# File 'lib/bashparser.rb', line 75 def self.is_complete_escape_code(escape_code)#assumes escape character is removed return false if escape_code == '' or escape_code == nil escape_code[-1] != escape_code[-1].dup.swapcase end |
.seperate_by_escape_codes(input) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/bashparser.rb', line 45 def self.seperate_by_escape_codes(input) return_data = [] escape_code_list = [] input = input + ESCAPE_BYTE.chr #Insures last string is inserted into return_data escape_code = INACTIVE string = '' input.each_byte do |byte| char = byte.chr if byte == ESCAPE_BYTE escape_code = '' if string != '' return_data << [string, escape_code_list ] string = '' escape_code_list = [] end elsif escape_code != INACTIVE escape_code += char if is_complete_escape_code(escape_code) escape_code_list << "#{ESCAPE_BYTE.chr}#{escape_code}" escape_code = INACTIVE end else string += char end end return_data end |
Instance Method Details
#display_screen(all_input = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/bashparser.rb', line 17 def display_screen(all_input = nil) data = [] if all_input != nil reset_buffer data = parse_input(all_input) else data = get_buffer_contents end data.each { |line| puts line } end |
#parse_input(input) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/bashparser.rb', line 28 def parse_input(input) input.each_byte do |byte| write_byte_to_buffer(byte) if @escape_code == INACTIVE read_for_escape_codes(byte) end get_buffer_contents end |
#reset_buffer ⇒ Object
6 7 8 9 10 11 |
# File 'lib/bashparser.rb', line 6 def reset_buffer @x = 0 @y = 0 @buffer = [] @escape_code = INACTIVE end |
#save_input_to_file(input, file_name) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/bashparser.rb', line 36 def save_input_to_file(input, file_name) #used for debugging purposes File.open(file_name, 'w') do |f| input.dup.each_byte do |byte| f.putc(byte) end end end |