Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #99. Removes ancient readline and custom tab completion code in favor of native + std rlcompleter. #100

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed readline.so.mac
Binary file not shown.
62 changes: 18 additions & 44 deletions seash.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,45 +57,27 @@
# Needed for parsing user commands and executing command functions
import seash_dictionary

# We need to expose the readline object file to OSX because the default object
# file for Python 2.7 on OSX is not compatible with our tab completion module.
import os
import sys

# Only rename if we're running on OSX
rename_readline_so_file = sys.platform == 'darwin'
HIDDEN_READLINE_SO_FN = 'readline.so.mac'
EXPOSED_READLINE_SO_FN = 'readline.so'

# Make sure we don't overwrite an existing readline.so if it exists.
# We need to do this because os.rename() doesn't raise any errors
# if the destination file already exists.
if (rename_readline_so_file and
EXPOSED_READLINE_SO_FN not in os.listdir('.')):
try:
os.rename(HIDDEN_READLINE_SO_FN, EXPOSED_READLINE_SO_FN)
except OSError:
# There was a problem reading readline.so.mac
rename_readline_so_file = False

tabcompletion = True
try:
try:
# Required for windows tab-completion.
# This is the readline module provided by pyreadline 1.7.1.
# http://pypi.python.org/pypi/pyreadline

tabcompletion = True # By default, we should have tab completion on.

# Next, we import readline, which we use for command-line editing
# within seash.
try: # Try importing readline and then rlcompleter if that is successful.
try: # Try importing packaged Windows version of readline first.
import readline_windows as readline
except ImportError:
# This error occurs when trying to import win_readline on mac/linux.
# We use the default readline module for mac/linux.
# Nope, not windows (presumably)
# Try whatever readline is immediately available in the environment.
import readline
import tab_completer
except ImportError:

# If we managed to import one or the other readline,
# import standard rlcompleter module to provide tab completion
# support for directories and files.
import rlcompleter
except ImportError: # If all readline imports fail or rlcompleter import failed
tabcompletion = False

# Don't hide mac readline.so if we didn't expose it
if rename_readline_so_file:
os.rename(EXPOSED_READLINE_SO_FN, HIDDEN_READLINE_SO_FN)


# Used for re-enabling modules on the last run
import seash_modules
Expand Down Expand Up @@ -143,17 +125,14 @@ def command_loop(test_command_list):

# Set up the tab completion environment (Added by Danny Y. Huang)
if tabcompletion:
# Initializes seash's tab completer
completer = tab_completer.Completer()
readline.parse_and_bind("bind ^I rl_complete")
readline.parse_and_bind("tab: complete")
# Determines when a new tab complete instance should be initialized,
# which, in this case, is never, so the tab completer will always take
# the entire user's string into account
readline.set_completer_delims("")
# Sets the completer function that readline will utilize
readline.set_completer(completer.complete)
else:
warnings.warn("Auto tab completion is off, because it is not available on your operating system.",ImportWarning)
warnings.warn("Auto tab completion is off, because it is not available on your operating system.", ImportWarning)


# If passed a list of commands, do not prompt for user input
Expand Down Expand Up @@ -197,11 +176,6 @@ def command_loop(test_command_list):
else:
while True:
try:
if tabcompletion:
# Updates the list of variable values in the tab complete class
completer.set_target_list()
completer.set_keyname_list()

# Saving state after each command? (Added by Danny Y. Huang)
if environment_dict['autosave'] and environment_dict['defaultkeyname']:
try:
Expand Down
254 changes: 0 additions & 254 deletions tab_completer.py

This file was deleted.