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.



41
42
43
44
45
46
47
48
49
# File 'lib/fxirb.rb', line 41

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.



39
40
41
# File 'lib/fxirb.rb', line 39

def gets_mode
  @gets_mode
end

Returns the value of attribute print_prompt.



39
40
41
# File 'lib/fxirb.rb', line 39

def print_prompt
  @print_prompt
end

Instance Method Details

#getsObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/fxirb.rb', line 51

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



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

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



111
112
113
114
115
116
117
118
119
# File 'lib/fxirb.rb', line 111

def next_cmd
	return "" if @gets_mode

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

#prev_cmdObject



101
102
103
104
105
106
107
108
109
# File 'lib/fxirb.rb', line 101

def prev_cmd
	return "" if @gets_mode

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