1010 Union ,
1111)
1212
13- # Prefer statically linked gnureadline if available (for macOS compatibility due to issues with libedit)
13+ #########################################################################################################################
14+ # NOTE ON LIBEDIT:
15+ #
16+ # On Linux/Mac, the underlying readline API may be implemented by libedit instead of GNU readline.
17+ # We don't support libedit because it doesn't implement all the readline features cmd2 needs.
18+ #
19+ # For example:
20+ # cmd2 sets a custom display function using Python's readline.set_completion_display_matches_hook() to
21+ # support many of its advanced tab completion features (e.g. tab completion tables, displaying path basenames,
22+ # colored results, etc.). This function "sets or clears the rl_completion_display_matches_hook callback in the
23+ # underlying library". libedit has never implemented rl_completion_display_matches_hook. It merely sets it to NULL
24+ # and never references it.
25+ #
26+ # The workaround for Python environments using libedit is to install the gnureadline Python library.
27+ #########################################################################################################################
28+
29+ # Prefer statically linked gnureadline if available due to issues with libedit
1430try :
1531 # noinspection PyPackageRequirements
1632 import gnureadline as readline # type: ignore[import]
1733except ImportError :
18- # Try to import readline, but allow failure for convenience in Windows unit testing
19- # Note: If this actually fails, you should install readline on Linux or Mac or pyreadline on Windows
34+ # Try to import readline, but allow failure for convenience in Windows unit testing.
35+ # Note: If this actually fails, you should install gnureadline on Linux/ Mac or pyreadline on Windows.
2036 try :
2137 # noinspection PyUnresolvedReferences
2238 import readline # type: ignore[no-redef]
@@ -125,7 +141,7 @@ def pyreadline_remove_history_item(pos: int) -> None:
125141 readline .remove_history_item = pyreadline_remove_history_item
126142
127143elif 'gnureadline' in sys .modules or 'readline' in sys .modules :
128- # We don't support libedit
144+ # We don't support libedit. See top of this file for why.
129145 if 'libedit' not in readline .__doc__ :
130146 try :
131147 # Load the readline lib so we can access members of it
@@ -146,7 +162,7 @@ def pyreadline_remove_history_item(pos: int) -> None:
146162 if not _rl_warn_reason :
147163 _rl_warn_reason = (
148164 "no supported version of readline was found. To resolve this, install\n "
149- "pyreadline on Windows or gnureadline on Mac."
165+ "pyreadline on Windows or gnureadline on Linux/ Mac."
150166 )
151167 rl_warning = "Readline features including tab completion have been disabled because\n " + _rl_warn_reason + '\n \n '
152168else :
0 commit comments