mirror of
https://github.com/wassname/pyreadline.git
synced 2026-06-27 16:10:38 +08:00
Adding missing functions to readline.py
This commit is contained in:
@@ -70,6 +70,12 @@ class LineHistory(object):
|
||||
history_length = property(get_history_length, set_history_length)
|
||||
history_cursor = property(get_history_cursor, set_history_cursor)
|
||||
|
||||
def remove_history_item(self, pos):
|
||||
del self.history[pos - 1]
|
||||
|
||||
def replace_history_item(self, pos, line):
|
||||
self.history[pos - 1] = lineobj.ReadLineTextBuffer(line)
|
||||
|
||||
def clear_history(self):
|
||||
u'''Clear readline history.'''
|
||||
self.history[:] = []
|
||||
|
||||
+33
-1
@@ -9,7 +9,7 @@
|
||||
u''' an attempt to implement readline for Python in Python using ctypes'''
|
||||
import sys,os,re,time
|
||||
from glob import glob
|
||||
|
||||
from logging import warn
|
||||
import release
|
||||
|
||||
import pyreadline.lineeditor.lineobj as lineobj
|
||||
@@ -156,6 +156,14 @@ class BaseReadline(object):
|
||||
u'''Clear readline history'''
|
||||
self.mode._history.clear_history()
|
||||
|
||||
def remove_history_item(self, pos):
|
||||
u'''Remove history item specified by its position from the history.'''
|
||||
self.mode._history.remove_history_item(pos)
|
||||
|
||||
def replace_history_item(self, pos, line):
|
||||
u'''Replace history item specified by its position with the given line.'''
|
||||
self.mode._history.replace_history_item(pos, line)
|
||||
|
||||
def read_history_file(self, filename=None):
|
||||
u'''Load a readline history file. The default filename is ~/.history.'''
|
||||
if filename is None:
|
||||
@@ -188,6 +196,12 @@ class BaseReadline(object):
|
||||
log(u'get_completer')
|
||||
return self.mode.completer
|
||||
|
||||
def get_completion_type(self):
|
||||
u'''Get the completion type. Not implemented returns empty string
|
||||
'''
|
||||
log(u'get_completion_type')
|
||||
return ""
|
||||
|
||||
def get_begidx(self):
|
||||
u'''Get the beginning index of the readline tab-completion scope.'''
|
||||
return self.mode.begidx
|
||||
@@ -227,7 +241,25 @@ class BaseReadline(object):
|
||||
'''
|
||||
self.mode.pre_input_hook = function
|
||||
|
||||
def set_completion_display_matches_hook(self, function=None):
|
||||
u'''Set or remove the completion display function.
|
||||
|
||||
NOT IMPLEMENTED
|
||||
|
||||
If function is specified, it will be used as the new completion display function;
|
||||
if omitted or None, any completion display function already installed is removed.
|
||||
The completion display function is called as function(substitution, [matches],
|
||||
longest_match_length) once each time matches need to be displayed.
|
||||
'''
|
||||
warn("set_completion_display_matches_hook in pyreadline is not implemented!!")
|
||||
|
||||
#Functions that are not relevant for all Readlines but should at least have a NOP
|
||||
def redisplay(self):
|
||||
u'''Change what is displayed on the screen to reflect the current contents of the line buffer.
|
||||
|
||||
Not implemented yet
|
||||
'''
|
||||
warn("redisplay in pyreadline is not implemented!!")
|
||||
|
||||
def _bell(self):
|
||||
pass
|
||||
|
||||
+9
-29
@@ -4,30 +4,6 @@
|
||||
#of a readline module
|
||||
from pyreadline.rlmain import Readline
|
||||
|
||||
__all__ = [ 'parse_and_bind',
|
||||
'get_line_buffer',
|
||||
'insert_text',
|
||||
'clear_history',
|
||||
'read_init_file',
|
||||
'read_history_file',
|
||||
'write_history_file',
|
||||
'get_current_history_length',
|
||||
'get_history_length',
|
||||
'get_history_item',
|
||||
'set_history_length',
|
||||
'set_startup_hook',
|
||||
'set_pre_input_hook',
|
||||
'set_completer',
|
||||
'get_completer',
|
||||
'get_begidx',
|
||||
'get_endidx',
|
||||
'set_completer_delims',
|
||||
'get_completer_delims',
|
||||
'add_history',
|
||||
'callback_handler_install',
|
||||
'callback_handler_remove',
|
||||
'callback_read_char',] #Some other objects are added below
|
||||
|
||||
|
||||
# create a Readline object to contain the state
|
||||
rl = Readline()
|
||||
@@ -41,7 +17,6 @@ else:
|
||||
def GetOutputFile():
|
||||
u'''Return the console object used by readline so that it can be used for printing in color.'''
|
||||
return rl.console
|
||||
__all__.append("GetOutputFile")
|
||||
|
||||
import pyreadline.console as console
|
||||
|
||||
@@ -55,20 +30,26 @@ else:
|
||||
write_history_file = rl.write_history_file
|
||||
read_history_file = rl.read_history_file
|
||||
|
||||
get_completer_delims = rl.get_completer_delims
|
||||
get_begidx = rl.get_begidx
|
||||
get_endidx = rl.get_endidx
|
||||
get_current_history_length = rl.get_current_history_length
|
||||
get_history_length = rl.get_history_length
|
||||
get_history_item = rl.get_history_item
|
||||
get_line_buffer = rl.get_line_buffer
|
||||
set_completer = rl.set_completer
|
||||
get_completer = rl.get_completer
|
||||
get_begidx = rl.get_begidx
|
||||
get_endidx = rl.get_endidx
|
||||
get_completer_delims = rl.get_completer_delims
|
||||
get_completion_type = rl.get_completion_type
|
||||
|
||||
remove_history_item = rl.remove_history_item
|
||||
replace_history_item = rl.replace_history_item
|
||||
redisplay = rl.redisplay
|
||||
|
||||
set_completer_delims = rl.set_completer_delims
|
||||
set_history_length = rl.set_history_length
|
||||
set_pre_input_hook = rl.set_pre_input_hook
|
||||
set_startup_hook = rl.set_startup_hook
|
||||
set_completion_display_matches_hook = rl.set_completion_display_matches_hook
|
||||
|
||||
callback_handler_install=rl.callback_handler_install
|
||||
callback_handler_remove=rl.callback_handler_remove
|
||||
@@ -76,4 +57,3 @@ else:
|
||||
|
||||
console.install_readline(rl.readline)
|
||||
|
||||
__all__.append("rl")
|
||||
Reference in New Issue
Block a user