Module: Bashir::Reader
- Includes:
- Commands, HighLine::SystemExtensions
- Included in:
- Bashir
- Defined in:
- lib/bashir/consts.rb,
lib/bashir/reader.rb
Defined Under Namespace
Modules: Codes
Constant Summary collapse
- ReadExit =
Class::new RuntimeError
- SwitchToRubyMode =
Class::new RuntimeError
- Space =
" "
- EOLRgx =
/\n\r?/
- WhitespaceRgx =
/\s/
- SpecialCodes =
[*33..64, *91..94, *123..126]
Constants included from Commands
Instance Method Summary collapse
- #echo(char) ⇒ Object
- #read_command_line(start) ⇒ Object
- #read_line ⇒ Object
-
#read_special(special_char) ⇒ Object
read_line.
- #read_up_to(delim = /\s/, echo = true, escapes = [].tap{ | result | loop do ch = _read result << ch p ch print ch.chr break if delim === ch.chr end }) ⇒ Object
Methods included from Commands
Instance Method Details
#echo(char) ⇒ Object
14 15 16 |
# File 'lib/bashir/reader.rb', line 14 def echo char print char if char end |
#read_command_line(start) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/bashir/reader.rb', line 29 def read_command_line start __log ">>>read_command_line #{start}" result = start.chr _read_with_handlers( result, Codes::Tab => lambda{ | read_sofar, ch | __log "caught <Tab>" "" }, Codes::EOL => lambda{ | read_sofar, ch | __log "caught <CR>" print ch.chr _exit_read }, Codes::BS => lambda{ | read_sofar, ch | __log "caught <BS>" print( Codes::Back.chr + Space + Codes::Back.chr ) unless read_sofar.empty? read_sofar.drop }, Codes::Space => lambda{ | read_so_far, ch | __log "end of command" print ch.chr read_so_far.replace( _check_command read_so_far ) __log "replaced: #{read_so_far}" ch.chr } ) rescue SwitchToRubyMode _finish_command_in_rb_mode result rescue ReadExit __log "<<<read_command_line: #{result}" result end |
#read_line ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/bashir/reader.rb', line 58 def read_line __log ">>>read_line" result = "" ch = _skip_chars( end: EOLRgx, skip: WhitespaceRgx ) case ch when SpecialCodes __log "special #{ch}" read_special ch else __log "start parsing" read_command_line ch end rescue Interrupt return nil end |
#read_special(special_char) ⇒ Object
read_line
74 75 76 |
# File 'lib/bashir/reader.rb', line 74 def read_special special_char __log ">>>read_special #{special_char}" end |
#read_up_to(delim = /\s/, echo = true, escapes = [].tap{ | result | loop do ch = _read result << ch p ch print ch.chr break if delim === ch.chr end }) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bashir/reader.rb', line 17 def read_up_to delim = /\s/, echo = true, escapes = [].tap{ | result | loop do ch = _read result << ch p ch print ch.chr break if delim === ch.chr end } end |