Skip to content

input color not working on windows(10)[19042] #71

Open

Description

@JessaTehCrow

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 file
from cprint import *
try:
    import pyreadline.rlmain
    #pyreadline.rlmain.config_path=r"c:\xxx\pyreadlineconfig.ini"
    import readline, atexit
    import pyreadline.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"
except ImportError:
    print("Module readline not available.")
else:
    #import tab completion functionality
    import rlcompleter

    #Override completer from rlcompleter to disable automatic ( on callable
    completer_obj = rlcompleter.Completer()
    def nop(val, word):
        return word
    completer_obj._callable_postfix = nop
    readline.set_completer(completer_obj.complete)

    #activate tab completion
    readline.parse_and_bind("tab: complete")
    readline.read_history_file()
    atexit.register(readline.write_history_file)
    del readline, rlcompleter, atexit

# # # # # # # # # # # # # # # # # # 
# # # v # My actual code # v # # #
# # # # # # # # # # # # # # # # # # 

try:
    color_input = cconvert(f"[L]Input [R]Text [GR]Here [Y]:")
    while 1:
        print(color_input)
        input(color_input)

except KeyboardInterrupt:
    exit()

image

Activity

  1. eabase commented on Jan 14, 2022

    @eabase

    You need to look into the function of input() and cconvert().
    Just try to override the input one, or roll your own.

    • What package is cconvert() coming from?
      (Didn't find it in cprint.)
    • Why did you unload readline?
      (It's very sketchy to delete already imported modules!)
  2. eabase commented on Jan 14, 2022

    @eabase

    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)

  3. eabase commented on Jan 14, 2022

    @eabase

    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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions