10
10
Union ,
11
11
)
12
12
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
14
30
try :
15
31
# noinspection PyPackageRequirements
16
32
import gnureadline as readline # type: ignore[import]
17
33
except 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.
20
36
try :
21
37
# noinspection PyUnresolvedReferences
22
38
import readline # type: ignore[no-redef]
@@ -125,7 +141,7 @@ def pyreadline_remove_history_item(pos: int) -> None:
125
141
readline .remove_history_item = pyreadline_remove_history_item
126
142
127
143
elif '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.
129
145
if 'libedit' not in readline .__doc__ :
130
146
try :
131
147
# Load the readline lib so we can access members of it
@@ -146,7 +162,7 @@ def pyreadline_remove_history_item(pos: int) -> None:
146
162
if not _rl_warn_reason :
147
163
_rl_warn_reason = (
148
164
"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."
150
166
)
151
167
rl_warning = "Readline features including tab completion have been disabled because\n " + _rl_warn_reason + '\n \n '
152
168
else :
0 commit comments