Class: Mysh::Console

Inherits:
Object show all
Defined in:
lib/mysh/sources/console.rb

Overview

A wrapper for the mysh console terminal.

Instance Method Summary collapse

Constructor Details

#initializeConsole

Setup the console wrapper.



10
11
12
# File 'lib/mysh/sources/console.rb', line 10

def initialize
  @eoi = false
end

Instance Method Details

#eoi?Boolean

Have we reached the end of input?

Returns:

  • (Boolean)


42
43
44
# File 'lib/mysh/sources/console.rb', line 42

def eoi?
  @eoi
end

#get_commandObject

Get the initial line of command input.



15
16
17
18
19
20
21
# File 'lib/mysh/sources/console.rb', line 15

def get_command
  puts MNV[:pre_prompt] if MNV.key?(:pre_prompt)
  get(prompt: MNV[:prompt])
rescue MiniReadlinePLE => err
  retry unless handle_get_error(err, :prompt)
  exit
end

#get_command_extra(str) ⇒ Object

Get additional lines of continued commands.



24
25
26
27
28
29
# File 'lib/mysh/sources/console.rb', line 24

def get_command_extra(str)
  get(prompt: MNV[:post_prompt] + '\\', prefix: str[0])
rescue MiniReadlinePLE => err
  retry unless handle_get_error(err, :post_prompt)
  exit
end

#handle_get_error(err, selector) ⇒ Object

Handle a readline error



32
33
34
35
36
37
38
39
# File 'lib/mysh/sources/console.rb', line 32

def handle_get_error(err, selector)
  puts "Error #{err.class}: #{err}"
  puts err.backtrace if MNV[:debug]

  MNV[selector].empty?
ensure
  MNV[selector] = ""
end