6 VALID_CONSOLE_MODES = [:console, :search, :searchback]
7 SEARCH_MODES = [:search, :searchback]
8 PROMPT = {:console => ':', :search => '/', :searchback => '?'}
20 @@historyfreeze = false
22 for mode in VALID_CONSOLE_MODES
32 @@infotime = Time.at(0)
34 @@last_search_mode = nil
39 def validate_pos(wrapping = false)
44 @@pos += @@str.size + 1
45 @@pos = 0 if @@pos < 0
49 elsif @@pos >= @@str.size
50 @@pos = @@str.size - 1
54 def len() @@str.size + 1 end
57 movi(UI.console_line, @@pos + 1)
60 def move_relative(n=0)
62 @@historyfreeze = false
65 return unless newpos.between? 0, @@str.size
70 def move_absolute(n=0)
72 @@historyfreeze = false
80 puti(UI.console_line, pos, str)
83 def insert(str, at=nil)
85 @@historyfreeze = false
95 @@historyfreeze = false
101 # if at < 0 or at >= @str.size
103 # elsif at == @str.size - 1
109 # @str = @str[0...at] + @str[at+1..-1]
135 when '<redraw>'; Info.request_redraw = true
137 when '<up>'; history :backward
138 when '<down>'; history :forward
139 when '<right>'; move_relative +1
140 when '<left>'; move_relative -1
142 when '<tab>'; tabcomplete :forward
143 when '<s-tab>'; tabcomplete :backward
144 when '<end>'; move_absolute -1
145 when '<home>'; move_absolute 0
153 when ' '..'~'; insert(c)
157 ## valid modes: :console, :search, :searchback
158 def main_loop(mode=:console)
168 def open(str = '', mode=:console, pos = -1)
172 if SEARCH_MODES.include? mode
173 @@last_search_mode = mode
182 write "#{arg.class}: #{arg.message}"
184 write "Error: #{arg}"
186 write "Unknown or unspecified error!"
189 for bt in Exception === arg ? arg.backtrace : caller(1)
198 @@infotime = Time.now
206 t = Query.get_time_left
208 Convert.relative_time_to_string(t)
212 attr_set(*Color.console.base)
213 clear_content if !@info and Time.now - @@infotime > 10
215 txt = "#{Opt.filter} "
216 txt << "brain[#{Query.db_size}] viewing[#{UI.list.size}] "
217 txt << "left[#{time_left}]"
218 filter = " #{$now.strftime("%A %b %d#{$now.day.suffix}, %H:%M")} "
219 txt = txt.ljust(cols-filter.size)[0..cols]
221 puts 0, txt.ljust(cols-1)[0..cols-1]
223 attr_at(cols-filter.size+1, UI.console_line, -1, *Color.console.date)
224 attr_at(0, UI.console_line, Opt.filter.size, *Color.console.tags)
227 # color_bold_at(UI.console_line, 0, Opt.filter.size, -1, -1)
230 attr_set(*Color.console.error)
232 attr_set(*Color.console.info)
235 puts 0, txt.ljust(cols-1)[0..cols-1]
237 attr_set(*Color.console.base)
246 attr_set(*Color.console.base)
247 rest = cols - @@str.size - 2
249 str = (PROMPT[@@mode] + @@str + ' ' * rest)
250 if str.size > cols - 1
251 str = str[str.size-cols+1 .. -1]
257 def tabcomplete(direction = :forward)
259 if direction == :forward
261 test = @@tabwords[@@tabindex]
265 elsif direction == :backward
268 @@tabindex = @@tabwords.size - 1
269 # if @@tabwords.respond_to?(:size)
270 # @@tabindex = @@tabwords.size - 1
273 # for item in @@tabwords
277 # @@tabindex = size - 1
284 test = @@tabwords[@@tabindex]
286 @@str[@@tabfreeze...@@tabend] = test
287 @@pos = @@tabfreeze + test.size
292 string = @@str[0...@@pos]
293 words = string.split(' ')
294 words << '' if @@str[@@pos-1] == ?\s
296 @@tabwords = Completer.new(words.first, Cache.cmd.__table__.keys)
298 @@tabwords = Command.tabcomp(string, @@pos, words.size - 1)
300 @@tabwordsize = (words.last.size rescue 0)
301 @@tabfreeze = @@pos - @@tabwordsize
309 unless @@str.empty? or @@history[@@mode].last == @@str
310 @@history[@@mode].unshift @@str
311 @@history[@@mode].pop if @@history[@@mode].size > (Opt.history_size || 30)
313 @@historyfreeze = false
317 unless @@historyfreeze
318 @@historyfreeze = true
319 @@historywords = Completer.new(@@str, @@history[@@mode])
324 @@historyindex += 1 unless @@historyindex >= @@historywords.size - 1
325 elsif dir == :forward
326 @@historyindex -= 1 unless @@historyindex <= 0
331 test = @@historywords[@@historyindex]