This question already has answers here:
List of ANSI color escape sequences
(6 answers)
C color text in terminal applications in windows
(3 answers)
Closed last year.
I want to make a text in color in C. I tried using some method below but this does not seem work on all platforms and C versions.
printf("\033[1;31m");
printf("Hello World\n");
printf("\033[0m");
On Windows 10 this seems to work ok, but on other systems I get this printed as text such as ←[1;31m or nothing prints at all.
Is there a more standard way to color a text which is more universal accross Windows and Unix systems?
Related
This question already has answers here:
console print w/o scrolling
(7 answers)
Closed 1 year ago.
I have a program that is a simulation, it updates constantly and writes messages in terminal, however, this causes the terminal to constantly scroll with new lines. I am wondering if there is a way to make terminal print lines and then clear after 10 seconds and then update?
Many terminals accept special escape codes allowing the programmer to move the cursor, set the colour and many more functions.
To use it good people wrote the ncurses library https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/
This question already has answers here:
Capture characters from standard input without waiting for enter to be pressed
(21 answers)
Closed 6 years ago.
I cant use scanf() because to receive integer input you need to press ENTER (when you are running the program).
Use curses library and use getch function to read a key without pressing enter. This works on linux and i think you can also use it on windows
If you are in Windows, then use getch() from conio.h
If you are in Unix/Linux.. you will probably need some terminal/tty adjustments. Check here:
What is Equivalent to getch() & getche() in Linux?
This question already has an answer here:
Game in linux terminal: Changing images: printing over already printed text
(1 answer)
Closed 8 years ago.
Hey so I want to make a game like Snake or Dwarf Fortress in a console/terminal. I want to print a game field with *'s and other symbols and change them without moving to console upwards. How can I do this?
Use a library like ncurses. It is meant for building console-based UIs.
This question already has answers here:
How to format date and time string in C++
(6 answers)
How to print time in format: 2009‐08‐10 18:17:54.811
(7 answers)
Closed 9 years ago.
I have been searching on the net on how to get and store the current date in yyyymmdd format. There are many code out there but it formats the dos %date%:%time% output to required specs.
The problem with that is, I need it to work universally across all regional settings. I can't find the code example to do that.
Can anyone help? If this is not possible, then is there a way to change the regional setting temporarily write the file and change it back to what it was?
This question already has answers here:
Color text in terminal applications in UNIX [duplicate]
(4 answers)
Closed 8 years ago.
I am using a Solaris server in my engineering course. Running code through SecureCRT and the gcc compiler. A task we have is to have the user input a string, and for the program to reverse it. The input string needs to show up in red, and I do not know what code manipulates colors to screen.
See Image for input /output
I tried running the code from the first link below, and it didnt output in any colors. It still shows all of the words in the standard black and white
Look into ncurses. It's a library built to handle this sort of thing, among other formatting.
start_color() in curses might be a good start.