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

macOS Big Sur input() removes colors #113533

Open
enty8080 opened this issue Dec 28, 2023 · 7 comments
Open

macOS Big Sur input() removes colors #113533

enty8080 opened this issue Dec 28, 2023 · 7 comments
Labels
OS-mac type-bug An unexpected behavior, bug, or error

Comments

@enty8080
Copy link

enty8080 commented Dec 28, 2023

Bug report

Bug description:

Providing screenshot because of colors:

Screenshot 2023-12-28 at 03 53 02

More details:

The same code works on Linux Ubuntu LTS and both input() and print() are colored.

NOTE: \001 and \002 are necessary for preventing libreadline from breaking prompt on tab completion. However removing them fixes the problem with colors. Unfortunately I can't go without them because otherwise libreadline breaks prompt:

Thanks in advance,
Ivan Nikolskiy (@enty8080)

CPython versions tested on:

3.11

Operating systems tested on:

macOS

@enty8080 enty8080 added the type-bug An unexpected behavior, bug, or error label Dec 28, 2023
@ronaldoussoren
Copy link
Contributor

The one of the answers to the stackoverflow question indicates there's little we can do here: readline on macOS uses the system libedit and apparently that's broken for this feature.

@ronaldoussoren
Copy link
Contributor

That said, the stackoverflow question also documents a way to fix the libedit sources and the fix they mention can probably be used to implement a hot fix by directly calling some native libedit APIs (not through its readline implementation).

@enty8080
Copy link
Author

I also tried to write prompt through sys.stdout.write so all the colors will be available and then called blank input(). However in this case, when you use backspace, it breaks the prompt too (erases it).

@ronaldoussoren
Copy link
Contributor

That said, the stackoverflow question also documents a way to fix the libedit sources and the fix they mention can probably be used to implement a hot fix by directly calling some native libedit APIs (not through its readline implementation).

I was too positive here. The EditLine instance used in the readline emulation is private to that library and cannot be accessed which means we cannot work around this.

This is a bug in the system version of libedit, the version at https://www.thrysoee.dk/editline/ does not have this bug.

@ned-deily

@enty8080
Copy link
Author

Looks like readline on my system does not use libedit (from otool)

$ otool -L /usr/local/readline/8.1/lib/libreadline.8.1.dylib
/usr/local/readline/8.1/lib/libreadline.8.1.dylib:
	/usr/local/readline/8.1/lib/libreadline.8.dylib (compatibility version 8.1.0, current version 8.1.0)
	/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)

felix@Felixs-Air ~ % find /opt -name 'libreadline*' -type f 2>/dev/null     
/opt/homebrew/Cellar/readline/8.2.7/lib/libreadline.8.2.dylib
/opt/homebrew/Cellar/readline/8.2.7/lib/libreadline.a

$ otool -L /opt/homebrew/Cellar/readline/8.2.7/lib/libreadline.8.2.dylib
/opt/homebrew/Cellar/readline/8.2.7/lib/libreadline.8.2.dylib:
	/opt/homebrew/opt/readline/lib/libreadline.8.dylib (compatibility version 8.2.0, current version 8.2.0)
	/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.100.5)

$ otool -L /opt/homebrew/opt/readline/lib/libreadline.8.dylib
/opt/homebrew/opt/readline/lib/libreadline.8.dylib:
	/opt/homebrew/opt/readline/lib/libreadline.8.dylib (compatibility version 8.2.0, current version 8.2.0)
	/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.100.5)

@dtrodrigues
Copy link
Contributor

What's the output of python3 -c "import readline; print(readline._READLINE_LIBRARY_VERSION)" and otool -L $(python3 -c "import readline; print(readline.__file__)")? Where did you get your Python from?

@enty8080
Copy link
Author

output 1:

EditLine wrapper

output 2:

/opt/homebrew/Cellar/python@3.11/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload/readline.cpython-311-darwin.so:
	/usr/lib/libedit.3.dylib (compatibility version 2.0.0, current version 3.0.0)
	/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.100.5)

I see it now. I got python3 from homebrew.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-mac type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants