How does ls set the color of the text
How does ls set the color of the text
When you open a C source file with nano and redirect the output to a text file, you can see the escape sequences used to set the color. If you do the same with ls you get only the directory listing with no escape sequences.
How does ls change the text color?
How does ls change the text color?
- NickJohnson
- Member
- Posts: 1249
- Joined: Tue Mar 24, 2009 8:11 pm
- Location: Sunnyvale, California
Re: How does ls set the color of the text
Magic.
Also, a program can tell if stdout is a tty, using isatty(). But it's probably the magic.
Also, a program can tell if stdout is a tty, using isatty(). But it's probably the magic.
Re: How does ls set the color of the text
Is there a way I can see the raw output that the tty sees?NickJohnson wrote:Magic.
Also, a program can tell if stdout is a tty, using isatty(). But it's probably the magic.
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: How does ls set the color of the text
What does any of this have to do with OS development?
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
Re: How does ls set the color of the text
How does it not have to do with OS development? Does your OS not have a console?Love4Boobies wrote:What does any of this have to do with OS development?
I want to learn about ways to handle colored text.
Re: How does ls set the color of the text
The function printing has to have a parameter or a certain character representation in the string you pass to it, to determine if it wants to be changed to a certain color. Actually changing the colors though..
Is definitely in the wiki, i haven't checked, but i'm damn well certain they are.
Is definitely in the wiki, i haven't checked, but i'm damn well certain they are.
Re: How does ls set the color of the text
You can google 'escape sequence change text color' or wait a week or two until I finish my video driver for DexOS
- NickJohnson
- Member
- Posts: 1249
- Joined: Tue Mar 24, 2009 8:11 pm
- Location: Sunnyvale, California
Re: How does ls set the color of the text
ls uses escape sequences to color its text just like any other program. You would make more progress looking up documentation on terminal emulators than trying to reverse engineer ls.justin wrote:How does it not have to do with OS development? Does your OS not have a console?Love4Boobies wrote:What does any of this have to do with OS development?
I want to learn about ways to handle colored text.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: How does ls set the color of the text
Terminal emulationjustin wrote:Is there a way I can see the raw output that the tty sees?NickJohnson wrote:Also, a program can tell if stdout is a tty, using isatty(). But it's probably the magic.
Re: How does ls set the color of the text
If it's only about a colored ls…justin wrote:Is there a way I can see the raw output that the tty sees?NickJohnson wrote:Magic.
Also, a program can tell if stdout is a tty, using isatty(). But it's probably the magic.
Code: Select all
ls --color=always | less
- amd64pager
- Member
- Posts: 73
- Joined: Fri Nov 25, 2011 8:27 am
- Location: In the 266 squadron of the RFC,near Maranique in the Southern Front in the WW1
Re: How does ls set the color of the text
It is in this format:
string contains your string to be printed in your colour and color can be these values:
Code: Select all
#include<stdio.h>
printf("\033[%d;%dm%s\033[0m\n",color,color + 30,string);
- 0 - black
1 - red
2 - green
3 - yellow
4 - blue
5 - magenta
6 - cyan
7 - white
It's surprising what the semiconductor industry's definition of macro is and what the CS description is.
Re: How does ls set the color of the text
Thanks. This is exactly what I wanted to see.XanClic wrote: If it's only about a colored ls…Code: Select all
ls --color=always | less