omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    In-Line Color Markup Support Script

    Pythonista
    color color codes concept
    1
    1
    1359
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Ro
      Ro last edited by Ro

      Recently I had a great idea that would allow Pythonista users to be able to use colorama (or other color markup) in their programs rather than using console functions!

      How it would work

      The program would run in the background as a thread and would intercept new stdout messages! Rather then being printed, the program would parse the message and check for color tags (eg. \033[44m)! If the program detects a color tag it could then change the color of the corrisponding text at the segment of the tag[1]!

      With this: more PC python programs that can run on pythonista and use in-line color tags!!!

      
      # [1] Example
      
      ...
      if r"\033" in message: # check for \033 colors
      	color = parse_colors(message) # needed function
      	sys.stdout.write(text_before_colorized)
      	if color == "[44": # parsing
      		console.set_color(0,0,1)
      		sys.stdout.write(text_after_colorized)
      	sys.stdout.write("\n") # ending print
      	...
      
      # There are many flaws with this example code but it shows the basic idea of how some of it would work!
      
      # ToDo: Parse multiple color codes in string
      # ToDo: Ignore r"messages"
      # ToDo: Ignore non-strings
      # ToDo: Make thread immune to KeyboardInturrupt
      # ToDo: Add kill method to thread
      # ToDo: Support multiple color markups
      # Error: >>> print "message",
      # would not remove the "\n" are parsing
      
      # End Result:
      
      # >>> print "normal color \033[44m blue color"
      # normal color  blue color
      #               ^        ^ this would be blue
      
      

      I wanted to share this idea with the community because I can't find time to make it and rather than just let the good idea die: I would like to share it with people who may be intrested in using it!

      1 Reply Last reply Reply Quote 0
      • First post
        Last post
      Powered by NodeBB Forums | Contributors