Class: FXIRBInputMethod

Inherits:
IRB::StdioInputMethod
  • Object
show all
Defined in:
lib/fxirb.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFXIRBInputMethod

Returns a new instance of FXIRBInputMethod.



24
25
26
27
28
29
30
31
32
# File 'lib/fxirb.rb', line 24

def initialize
	super 
	@history = 1
	@begin = nil
	@end = nil
	@print_prompt = true
	@continued_from = nil
	@gets_mode = false
end

Instance Attribute Details

#gets_modeObject

Returns the value of attribute gets_mode.



22
23
24
# File 'lib/fxirb.rb', line 22

def gets_mode
  @gets_mode
end

Returns the value of attribute print_prompt.



22
23
24
# File 'lib/fxirb.rb', line 22

def print_prompt
  @print_prompt
end

Instance Method Details

#getsObject



34
35
36
37
38
39
40
41
42
43
44
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/fxirb.rb', line 34

def gets 
	if @gets_mode
		return FXIrb.instance.get_line
	end

	if (a = @prompt.match(/(\d+)[>*]/))
		level = a[1].to_i
		continued = @prompt =~ /\*\s*$/
	else
		level = 0
	end

	if level > 0 or continued
		@continued_from ||= @line_no
	elsif @continued_from
		merge_last(@line_no-@continued_from+1)
		@continued_from = nil
	end

	l = @line.length
	@line = @line.reverse.uniq.reverse
	delta = l - @line.length
	@line_no -= delta
	@history -= delta

	if print_prompt
		print @prompt

		#indentation
		print "  "*level
	end

	str = FXIrb.instance.get_line

	@line_no += 1
	@history = @line_no + 1
	@line[@line_no] = str

	str
end

#merge_last(i) ⇒ Object

merge a block spanning several lines into one n-separated line



76
77
78
79
80
81
82
# File 'lib/fxirb.rb', line 76

def merge_last(i)
	return unless i > 1
	range = -i..-1
	@line[range] = @line[range].join
	@line_no -= (i-1)
	@history -= (i-1)
end

#next_cmdObject



94
95
96
97
98
99
100
101
102
# File 'lib/fxirb.rb', line 94

def next_cmd
	return "" if @gets_mode

	if (@line_no > 0) && (@history < @line_no)
		@history += 1
		return line(@history)
	end
	return ""
end

#prev_cmdObject



84
85
86
87
88
89
90
91
92
# File 'lib/fxirb.rb', line 84

def prev_cmd
	return "" if @gets_mode

	if @line_no > 0
		@history -= 1 unless @history <= 1
		return line(@history)
	end
	return ""
end