You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using the code below (Taken from a example snippet), i was experimenting to see if i could use this within my program.
However, it seems that colors don't work when taking a user-input (Can be seen in image below).
I tried using a fix that was mentioned in #46 but that yielded no positive result.
# -*- coding: UTF-8 -*-# Example snippet to use in a PYTHONSTARTUP filefromcprintimport*try:
importpyreadline.rlmain#pyreadline.rlmain.config_path=r"c:\xxx\pyreadlineconfig.ini"importreadline, atexitimportpyreadline.unicode_helper###Normally the codepage for pyreadline is set to be sys.stdout.encoding#if you need to change this uncomment the following line#pyreadline.unicode_helper.pyreadline_codepage="utf8"exceptImportError:
print("Module readline not available.")
else:
#import tab completion functionalityimportrlcompleter#Override completer from rlcompleter to disable automatic ( on callablecompleter_obj=rlcompleter.Completer()
defnop(val, word):
returnwordcompleter_obj._callable_postfix=nopreadline.set_completer(completer_obj.complete)
#activate tab completionreadline.parse_and_bind("tab: complete")
readline.read_history_file()
atexit.register(readline.write_history_file)
delreadline, rlcompleter, atexit# # # # # # # # # # # # # # # # # # # # # v # My actual code # v # # ## # # # # # # # # # # # # # # # # # try:
color_input=cconvert(f"[L]Input [R]Text [GR]Here [Y]:")
while1:
print(color_input)
input(color_input)
exceptKeyboardInterrupt:
exit()
I think you need to uncomment this line: #pyreadline.unicode_helper.pyreadline_codepage="utf8".
Because, readline as used in the built-in input() is using codepage for determining the coding of the input. Using color codes may confuse this function.
Also, please print the Hex output of your color_input string.
PS. Source code for the Python input() builtin is located in the c-code function: builtin_input_impl(PyObject *module, PyObject *prompt)
Your first line should be: # -*- coding: utf_8 -*- and not # -*- coding: UTF-8 -*-.
I now see that you are using the example startup in the pyreadline package, located at: /c/Python310/Lib/site-packages/pyreadline/configuration/startup.py
You should probably get rid of this as your startup file, and try without, and on the latest Python version (which already have VT support through the shells we use under WIn10.)
Activity
eabase commentedon Jan 14, 2022
You need to look into the function of
input()andcconvert().Just try to override the input one, or roll your own.
(Didn't find it in cprint.)
readline?(It's very sketchy to delete already imported modules!)
eabase commentedon Jan 14, 2022
I think you need to uncomment this line:
#pyreadline.unicode_helper.pyreadline_codepage="utf8".Because, readline as used in the built-in input() is using codepage for determining the coding of the input. Using color codes may confuse this function.
Also, please print the Hex output of your
color_inputstring.PS. Source code for the Python input() builtin is located in the c-code function:
builtin_input_impl(PyObject *module, PyObject *prompt)eabase commentedon Jan 14, 2022
Your first line should be:# -*- coding: utf_8 -*-and not# -*- coding: UTF-8 -*-.I now see that you are using the example startup in the
pyreadlinepackage, located at:/c/Python310/Lib/site-packages/pyreadline/configuration/startup.pyYou should probably get rid of this as your startup file, and try without, and on the latest Python version (which already have VT support through the shells we use under WIn10.)