+ 1

How do i color text??

How do i color text??

8th Aug 2017, 8:58 PM
Adam Thompson
Adam Thompson - avatar
7 Réponses
+ 7
Colors don't works in sololearn output almost because of the ways in/output is handling... by capturing output stream and send it to a web output ^^ (so, you're right: in sololearn playground that will 'corrupt' the output ;P) However, I don't think ANSI controls have to be used for anything else than specific targeted platform, so you know which are less or more supported or not ;)
9th Aug 2017, 2:53 PM
visph
visph - avatar
+ 4
Even if on almost console/terminal you can color text, that's not ever the case... The real way to color text in Python (or any non user sided web language) mean using GUI (Graphical User Interface) instead of CLI (Command Line Interface -- only text) through the use of GUI frameworks (modules) and highly depends of wich one you choose to use (there are plenty of such available).
9th Aug 2017, 9:05 AM
visph
visph - avatar
+ 3
@visph Do you have a Windows box where you could try this (it's not ANSI)? https://code.sololearn.com/c3QbcL54mfAG/?ref=app
9th Aug 2017, 2:20 PM
Kirk Schafer
Kirk Schafer - avatar
+ 3
@Kirk: no, I haven't a Window easily reachable, and even more with a Python interpreter installed... Anyway, ANSI controls are useful, and not difficult to use: the escape string prefix should be "\33[", followed by the needed sequence (ie get red text with print("\33[31m") ;)) [edit] To get all codes color and more: https://en.m.wikipedia.org/wiki/ANSI_escape_code#Colors
9th Aug 2017, 2:29 PM
visph
visph - avatar
+ 3
[edited] ANSI is great; I totally get it (upvotes on all your ANSI help when I see it). It's useful for BBS's... but those extra characters are in the video buffer and if there's no compatible terminal the text is difficult to use. The call/method is faithful to what going on inside: set the color control bytes in video memory. It doesn't interfere with the output buffer, which is why SoloLearn doesn't show any difference. It may not matter to a soul here... I've just started to realize that some patrons have very old stuff (or are using, e.g. DOSbox for old code). awesome; thanks for that link. ...Python might not run but the technique hints...
9th Aug 2017, 2:45 PM
Kirk Schafer
Kirk Schafer - avatar
+ 2
ANSI color commands work in many terminals: https://code.sololearn.com/WRSLH8ZxPmDw/?ref=app They don't work on SoloLearn. If for some reason the web version doesn't work for you, you can take this code and enable ANSI mode locally...just set "ANSI_ok = True": https://code.sololearn.com/c6cJ0KHmoxJt/?ref=app
8th Aug 2017, 11:28 PM
Kirk Schafer
Kirk Schafer - avatar
0
visph and Kirk Schafer - Apart from python, is there any possible way by which text formatting could be done to specific output characters on the screen in C++ in a non Linux/Unix platform using ANSI escape commands? Seems like it's not possible to do so on Sololearn's console. https://www.sololearn.com/discuss/1221222/?ref=app
17th Apr 2018, 1:14 PM
Rahul George
Rahul George - avatar