mirror of
https://github.com/wassname/pyreadline.git
synced 2026-06-30 16:40:09 +08:00
pyreadline: Default silent bell. Change to name of configfile. Change to configfile syntax. Renamed pyreadline.py to rlmain.py
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
#Commands for moving
|
||||
parse_and_bind("Home", "beginning_of_line")
|
||||
parse_and_bind("End", "end_of_line")
|
||||
parse_and_bind("Left", "backward_char")
|
||||
parse_and_bind("Control-b", "backward_char")
|
||||
parse_and_bind("Right", "forward_char")
|
||||
parse_and_bind("Control-f", "forward_char")
|
||||
parse_and_bind("Alt-f", "forward_word")
|
||||
parse_and_bind("Alt-b", "backward_word")
|
||||
parse_and_bind("Clear", "clear_screen")
|
||||
parse_and_bind("Control-l", "clear_screen")
|
||||
parse_and_bind("Control-a", "beginning_of_line")
|
||||
parse_and_bind("Control-e", "end_of_line")
|
||||
#parse_and_bind("Control-l", "redraw_current_line")
|
||||
|
||||
#Commands for Manipulating the History
|
||||
parse_and_bind("Return", "accept_line")
|
||||
parse_and_bind("Control-p", "previous_history")
|
||||
parse_and_bind("Control-n", "next_history")
|
||||
parse_and_bind("Up", "history_search_backward")
|
||||
parse_and_bind("Down", "history_search_forward")
|
||||
parse_and_bind("Alt-<", "beginning_of_history")
|
||||
parse_and_bind("Alt->", "end_of_history")
|
||||
parse_and_bind("Control-r", "reverse_search_history")
|
||||
parse_and_bind("Control-s", "forward_search_history")
|
||||
parse_and_bind("Alt-p", "non_incremental_reverse_search_history")
|
||||
parse_and_bind("Alt-n", "non_incremental_forward_search_history")
|
||||
|
||||
#Commands for Changing Text
|
||||
parse_and_bind("Delete", "delete_char")
|
||||
parse_and_bind("Control-d", "delete_char")
|
||||
parse_and_bind("BackSpace", "backward_delete_char")
|
||||
parse_and_bind("Control-Shift-v", "quoted_insert")
|
||||
parse_and_bind("Control-space", "self_insert")
|
||||
|
||||
#Killing and Yanking
|
||||
parse_and_bind("Control-k", "kill_line")
|
||||
parse_and_bind("Control-shift-k", "kill_whole_line")
|
||||
parse_and_bind("Meta-d", "kill_word")
|
||||
parse_and_bind("Control-w", "unix_word_rubout")
|
||||
parse_and_bind("Meta-Delete", "backward_kill_word")
|
||||
|
||||
#Copy paste
|
||||
parse_and_bind("Control-m", "set_mark")
|
||||
parse_and_bind("Control-q", "copy_region_to_clipboard")
|
||||
parse_and_bind("Control-v", "paste")
|
||||
parse_and_bind("Alt-v", "ipython_paste")
|
||||
parse_and_bind("Control-y", "paste")
|
||||
parse_and_bind("Control-z", "undo")
|
||||
parse_and_bind("Control-_", "undo")
|
||||
|
||||
#Other
|
||||
bell_style("none") #modes: none, audible, visible(not implemented)
|
||||
show_all_if_ambiguous("on")
|
||||
mark_directories("on")
|
||||
completer_delims(" \t\n\"\\'`@$><=;|&{(")
|
||||
@@ -1,3 +1,21 @@
|
||||
2006-01-23 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu>
|
||||
|
||||
* Default is now to insert non bound characters.
|
||||
* rename pyreadline.py to rlmain.py
|
||||
* rename of config file to pyreadlineconfig.ini
|
||||
* Change to config file syntax
|
||||
* bell is now silent as deafult
|
||||
* removed specific keybinding code for keypad
|
||||
|
||||
2006-01-22 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu>
|
||||
|
||||
* Default is now to insert non bound characters unless they are
|
||||
pressed together with control.
|
||||
* Added try except to read_inputrc
|
||||
* Fixed cleanup bug in keysyms, missing saveattr on console
|
||||
* Removed specific codepage code from keysyms
|
||||
|
||||
|
||||
2006-01-22 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu>
|
||||
|
||||
* Cleaned up bell handling to make sure you can disable bell with the
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
#Commands for moving
|
||||
bind_key("Home", "beginning_of_line")
|
||||
bind_key("End", "end_of_line")
|
||||
bind_key("Left", "backward_char")
|
||||
bind_key("Control-b", "backward_char")
|
||||
bind_key("Right", "forward_char")
|
||||
bind_key("Control-f", "forward_char")
|
||||
bind_key("Alt-f", "forward_word")
|
||||
bind_key("Alt-b", "backward_word")
|
||||
bind_key("Clear", "clear_screen")
|
||||
bind_key("Control-l", "clear_screen")
|
||||
bind_key("Control-a", "beginning_of_line")
|
||||
bind_key("Control-e", "end_of_line")
|
||||
#bind_key("Control-l", "redraw_current_line")
|
||||
|
||||
#Commands for Manipulating the History
|
||||
bind_key("Return", "accept_line")
|
||||
bind_key("Control-p", "previous_history")
|
||||
bind_key("Control-n", "next_history")
|
||||
bind_key("Up", "history_search_backward")
|
||||
bind_key("Down", "history_search_forward")
|
||||
bind_key("Alt-<", "beginning_of_history")
|
||||
bind_key("Alt->", "end_of_history")
|
||||
bind_key("Control-r", "reverse_search_history")
|
||||
bind_key("Control-s", "forward_search_history")
|
||||
bind_key("Alt-p", "non_incremental_reverse_search_history")
|
||||
bind_key("Alt-n", "non_incremental_forward_search_history")
|
||||
|
||||
#Commands for Changing Text
|
||||
bind_key("Delete", "delete_char")
|
||||
bind_key("Control-d", "delete_char")
|
||||
bind_key("BackSpace", "backward_delete_char")
|
||||
bind_key("Control-Shift-v", "quoted_insert")
|
||||
bind_key("Control-space", "self_insert")
|
||||
|
||||
#Killing and Yanking
|
||||
bind_key("Control-k", "kill_line")
|
||||
bind_key("Control-shift-k", "kill_whole_line")
|
||||
bind_key("Meta-d", "kill_word")
|
||||
bind_key("Control-w", "unix_word_rubout")
|
||||
bind_key("Meta-Delete", "backward_kill_word")
|
||||
|
||||
#Copy paste
|
||||
bind_key("Control-m", "set_mark")
|
||||
bind_key("Control-q", "copy_region_to_clipboard")
|
||||
bind_key("Control-v", "paste")
|
||||
bind_key("Alt-v", "ipython_paste")
|
||||
bind_key("Control-y", "paste")
|
||||
bind_key("Control-z", "undo")
|
||||
bind_key("Control-_", "undo")
|
||||
|
||||
#Other
|
||||
bell_style("none") #modes: none, audible, visible(not implemented)
|
||||
show_all_if_ambiguous("on")
|
||||
mark_directories("on")
|
||||
completer_delims(" \t\n\"\\'`@$><=;|&{(")
|
||||
#debug_output("on") #Not implemented yet
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from pyreadline import *
|
||||
|
||||
from rlmain import *
|
||||
__all__ = [ 'parse_and_bind',
|
||||
'get_line_buffer',
|
||||
'insert_text',
|
||||
@@ -16,4 +15,5 @@ __all__ = [ 'parse_and_bind',
|
||||
'get_endidx',
|
||||
'set_completer_delims',
|
||||
'get_completer_delims',
|
||||
'add_history' ]
|
||||
'add_history',
|
||||
'GetOutputFile']
|
||||
|
||||
@@ -182,7 +182,8 @@ class Console(object):
|
||||
self.SetConsoleMode(self.hin, 0xf)
|
||||
info = CONSOLE_SCREEN_BUFFER_INFO()
|
||||
self.GetConsoleScreenBufferInfo(self.hout, byref(info))
|
||||
self.attr = info.wAttributes # remember the initial colors
|
||||
self.attr = info.wAttributes
|
||||
self.saveattr = info.wAttributes # remember the initial colors
|
||||
background = self.attr & 0xf0
|
||||
for escape in self.escape_to_color:
|
||||
if self.escape_to_color[escape] is not None:
|
||||
@@ -687,7 +688,7 @@ def install_readline(hook):
|
||||
readline_hook = hook
|
||||
# get the address of PyOS_ReadlineFunctionPointer so we can update it
|
||||
PyOS_RFP = c_int.from_address(Console.GetProcAddress(sys.dllhandle,
|
||||
"PyOS_ReadlineFunctionPointer"))
|
||||
"PyOS_ReadlineFunctionPointer"))
|
||||
# save a reference to the generated C-callable so it doesn't go away
|
||||
if sys.version < '2.3':
|
||||
readline_ref = HOOKFUNC22(hook_wrapper)
|
||||
|
||||
@@ -104,14 +104,6 @@ def key_text_to_keyinfo(keytext):
|
||||
|
||||
VkKeyScan = windll.user32.VkKeyScanA
|
||||
|
||||
codepage=windll.kernel32.GetConsoleCP()
|
||||
outputcodepage=windll.kernel32.GetConsoleOutputCP()
|
||||
|
||||
#This method does not seem to work for use of swedish characters on codepage 850
|
||||
#VkKeyScan results in -1 for those keys
|
||||
printable_chars_in_codepage={1252:"\xe5\xe4\xf6\xc5\xc4\xd6\xa8\xb4\xa7\xbd\xa4\xa3",
|
||||
}.get(codepage,"")
|
||||
|
||||
def char_to_keyinfo(char, control=False, meta=False, shift=False):
|
||||
vk = VkKeyScan(ord(char))
|
||||
if vk & 0xffff == 0xffff:
|
||||
|
||||
@@ -12,12 +12,10 @@ import exceptions
|
||||
|
||||
import win32con as c32
|
||||
|
||||
import console as console
|
||||
from console import log
|
||||
from keysyms import key_text_to_keyinfo,printable_chars_in_codepage
|
||||
|
||||
import clipboard as clipboard
|
||||
import ctypes
|
||||
import console
|
||||
import clipboard
|
||||
from console import log
|
||||
from keysyms import key_text_to_keyinfo
|
||||
|
||||
enable_win32_clipboard=True
|
||||
|
||||
@@ -65,10 +63,24 @@ class Readline:
|
||||
# variables you can control with parse_and_bind
|
||||
self.show_all_if_ambiguous = 'off'
|
||||
self.mark_directories = 'on'
|
||||
self.bell_style = 'audible'
|
||||
self.bell_style = 'none'
|
||||
self.mark=-1
|
||||
self.read_inputrc()
|
||||
log("\n".join(self.rl_settings_to_string()))
|
||||
|
||||
def rl_settings_to_string(self):
|
||||
out=["%-20s: %s"%("show all if ambigous",self.show_all_if_ambiguous)]
|
||||
out.append("%-20s: %s"%("mark_directories",self.mark_directories))
|
||||
out.append("%-20s: %s"%("bell_style",self.bell_style))
|
||||
out.append("%-20s: %s"%("mark_directories",self.mark_directories))
|
||||
out.append("------------- key bindings ------------")
|
||||
out.append("%7s %7s %7s %7s %7s %7s"%("Control","Meta","Shift","Keycode","Character","Function"))
|
||||
bindings=[(k[0],k[1],k[2],k[3],repr(chr(k[3])),v.__name__)for k,v in self.key_dispatch.iteritems()]
|
||||
bindings.sort()
|
||||
for key in bindings:
|
||||
out.append("%7s %7s %7s %7d %7s %7s"%(key))
|
||||
return out
|
||||
|
||||
def _bell(self):
|
||||
'''ring the bell if requested.'''
|
||||
if self.bell_style == 'none':
|
||||
@@ -177,8 +189,8 @@ class Readline:
|
||||
dispatch_func = self.key_dispatch[event.keyinfo]
|
||||
except KeyError:
|
||||
# unknown? try printing it anyway
|
||||
if event.keyinfo[0]!=True:
|
||||
self.self_insert(event) #insert only if ctrl is not pressed
|
||||
#if event.keyinfo[0]!=True:
|
||||
self.self_insert(event) #insert only if ctrl is not pressed
|
||||
#c.bell()
|
||||
continue
|
||||
r = None
|
||||
@@ -790,7 +802,7 @@ class Readline:
|
||||
repr of array'''
|
||||
if enable_win32_clipboard:
|
||||
txt=clipboard.get_clipboard_text_and_convert(
|
||||
enable_ipython_paste_list_of_lists)
|
||||
enable_ipython_paste_list_of_lists)
|
||||
if enable_ipython_paste_for_paths:
|
||||
if len(txt)<300 and ("\t" not in txt) and ("\n" not in txt):
|
||||
txt=txt.replace("\\","/").replace(" ",r"\ ")
|
||||
@@ -1059,18 +1071,13 @@ class Readline:
|
||||
def _bind_key(self, key, func):
|
||||
'''setup the mapping from key to call the function.'''
|
||||
keyinfo = key_text_to_keyinfo(key)
|
||||
# print key,keyinfo,func.__name__
|
||||
self.key_dispatch[keyinfo] = func
|
||||
|
||||
def emacs_editing_mode(self, e): # (C-e)
|
||||
'''When in vi command mode, this causes a switch to emacs editing
|
||||
mode.'''
|
||||
#insert printable chars available from codepage
|
||||
for char in printable_chars_in_codepage:
|
||||
self._bind_key(char, self.self_insert)
|
||||
|
||||
# make ' ' to ~ self insert
|
||||
for c in range(ord(' '), 127):
|
||||
self._bind_key('"%s"' % chr(c), self.self_insert)
|
||||
# I often accidentally hold the shift or control while typing space
|
||||
self._bind_key('Shift-space', self.self_insert)
|
||||
self._bind_key('Control-space', self.self_insert)
|
||||
@@ -1113,27 +1120,7 @@ class Readline:
|
||||
self._bind_key('Control-k', self.kill_line)
|
||||
self._bind_key('Control-m', self.set_mark)
|
||||
self._bind_key('Control-q', self.copy_region_to_clipboard)
|
||||
|
||||
# self._bind_key('Control-shift-k', self.kill_whole_line)
|
||||
# Add keybindings for numpad
|
||||
# first the number keys
|
||||
self._bind_key('NUMPAD0', self.self_insert)
|
||||
self._bind_key('NUMPAD1', self.self_insert)
|
||||
self._bind_key('NUMPAD2', self.self_insert)
|
||||
self._bind_key('NUMPAD3', self.self_insert)
|
||||
self._bind_key('NUMPAD4', self.self_insert)
|
||||
self._bind_key('NUMPAD5', self.self_insert)
|
||||
self._bind_key('NUMPAD6', self.self_insert)
|
||||
self._bind_key('NUMPAD7', self.self_insert)
|
||||
self._bind_key('NUMPAD8', self.self_insert)
|
||||
self._bind_key('NUMPAD9', self.self_insert)
|
||||
# then the others: / * - +
|
||||
self._bind_key('Divide', self.self_insert)
|
||||
self._bind_key('Multiply', self.self_insert)
|
||||
self._bind_key('Add', self.self_insert)
|
||||
self._bind_key('Subtract', self.self_insert)
|
||||
# the decimal separator: '.' on US keyboards, ',' on DE one's
|
||||
self._bind_key('VK_DECIMAL', self.self_insert)
|
||||
|
||||
|
||||
def vi_editing_mode(self, e): # (M-C-j)
|
||||
@@ -1141,7 +1128,7 @@ class Readline:
|
||||
mode.'''
|
||||
pass
|
||||
|
||||
def read_inputrc(self,inputrcpath=os.path.expanduser("~/.pyinputrc")):
|
||||
def read_inputrc(self,inputrcpath=os.path.expanduser("~/pyreadlineconfig.ini")):
|
||||
def pb(key,name):
|
||||
if hasattr(self,name):
|
||||
self._bind_key(key,getattr(self,name))
|
||||
@@ -1155,13 +1142,19 @@ class Readline:
|
||||
self.mark_directories=mode
|
||||
def completer_delims(mode):
|
||||
self.completer_delims=mode
|
||||
loc={"parse_and_bind":pb,
|
||||
loc={"bind_key":pb,
|
||||
"bell_style":setbellstyle,
|
||||
"mark_directories":mark_directories,
|
||||
"show_all_if_ambiguous":show_all_if_ambiguous,
|
||||
"completer_delims":completer_delims,}
|
||||
if os.path.isfile(inputrcpath):
|
||||
execfile(inputrcpath,loc,loc)
|
||||
if os.path.isfile(inputrcpath):
|
||||
try:
|
||||
execfile(inputrcpath,loc,loc)
|
||||
except:
|
||||
#Or should we force output otherwise python -v is necessary?
|
||||
#print >>sys.stderr, "Error reading .pyinputrc"
|
||||
raise ReadlineError("Error reading .pyinputrc")
|
||||
|
||||
|
||||
|
||||
def CTRL(c):
|
||||
Reference in New Issue
Block a user