##// END OF EJS Templates
Add a new option `n` to limit history search hits
Takafumi Arakaki -
Show More
@@ -290,7 +290,7 b' class HistoryAccessor(Configurable):'
290 return reversed(list(cur))
290 return reversed(list(cur))
291
291
292 def search(self, pattern="*", raw=True, search_raw=True,
292 def search(self, pattern="*", raw=True, search_raw=True,
293 output=False):
293 output=False, n=None):
294 """Search the database using unix glob-style matching (wildcards
294 """Search the database using unix glob-style matching (wildcards
295 * and ?).
295 * and ?).
296
296
@@ -302,6 +302,9 b' class HistoryAccessor(Configurable):'
302 If True, search the raw input, otherwise, the parsed input
302 If True, search the raw input, otherwise, the parsed input
303 raw, output : bool
303 raw, output : bool
304 See :meth:`get_range`
304 See :meth:`get_range`
305 n : None or int
306 If an integer is given, it defines the limit of
307 returned entries.
305
308
306 Returns
309 Returns
307 -------
310 -------
@@ -311,9 +314,16 b' class HistoryAccessor(Configurable):'
311 if output:
314 if output:
312 tosearch = "history." + tosearch
315 tosearch = "history." + tosearch
313 self.writeout_cache()
316 self.writeout_cache()
314 return self._run_sql("WHERE %s GLOB ?" % tosearch, (pattern,),
317 sqlform = "WHERE %s GLOB ?" % tosearch
315 raw=raw, output=output)
318 params = (pattern,)
316
319 if n is not None:
320 sqlform += " ORDER BY session DESC, line DESC LIMIT ?"
321 params += (n,)
322 cur = self._run_sql(sqlform, params, raw=raw, output=output)
323 if n is not None:
324 cur = iter(reversed(list(cur)))
325 return cur
326
317 def get_range(self, session, start=1, stop=None, raw=True,output=False):
327 def get_range(self, session, start=1, stop=None, raw=True,output=False):
318 """Retrieve input by session.
328 """Retrieve input by session.
319
329
General Comments 0
You need to be logged in to leave comments. Login now