Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

Have colors in "ls", depending on file status #87

Closed
wants to merge 99 commits into from

Conversation

holzschu
Copy link
Contributor

Builiding on release #71 by @IMcD23 , this PR activates "color mode" for ls: directories are in blue, executable files in red, etc. Colors can be configured by setting the environment variable LSCOLORS. "color mode" can be deactivated by unsetting the variable CLICOLOR.

Color mode is automatically deactivated when the output of ls is sent to another command (e.g. ls | grep)

dvrh9bwwaaa7tg0

(curl, for example). Minimum fix to display both.
@ian-mcdowell
Copy link
Contributor

Why are there so many commits in this PR?

@ian-mcdowell
Copy link
Contributor

The colors are a bit hard to read. How does ‘ls’ determine which colors to show?

@holzschu
Copy link
Contributor Author

holzschu commented Feb 11, 2018

From what I gathered, foreground color is set from LSCOLORS, by pairs of letters.
First letter = foreground color, color number = letter minus 'a'. Bold if capital letter.
2nd letter = background color, "x" if not changed, color number = letter minus 'a'
In that example, LSCOLORS = "ExFxBxDxCxegedabagacad".
First color = directory, 2nd color = symbolic link, 4th = executable (see enum Colors in ls/print.c).

So that would be directories = color #4 + bold, links = color #5 + bold, executables = color #3 + bold (so the color of executables is set by \033[33m and \033[1m). Inside Blink, with the same LSCOLORS (and the same binaries), I get different colors:
img_0063

@ian-mcdowell
Copy link
Contributor

I’ll take a look at the color handling in ANSITextState.swift

Perhaps those colors need to be adjusted...

@holzschu
Copy link
Contributor Author

I think I should also check where the "bold" escape sequence is placed.

@ian-mcdowell
Copy link
Contributor

I want to start building some test cases for these kind of things. Could you send me a sample color output string, with escape characters?

@holzschu
Copy link
Contributor Author

holzschu commented Feb 13, 2018

Here is the output for the same directory, before parsing:

cacert.pem    ctd.cpp    echoTest    input    known_hosts
^[[1m^[[34mlua^[[39;49m^[[0m
path
^[[1m^[[32mtest^[[39;49m^[[0m
test.tar.gz
^[[1m^[[35mtest2^[[39;49m^[[0m

Where ^[[ is the escape sequence (esc + [). According to https://en.wikipedia.org/wiki/ANSI_escape_code , that should be lua in bold blue, test in bold green and test2 in bold magenta.

Raw version:
ls_result.txt

@louisdh
Copy link
Owner

louisdh commented Mar 20, 2018

This PR only changes code in ios_system, and was opened before ios_system was included as a git submodule. I suppose this PR can be closed now? Assuming these changes are available on the master branch of the ios_system repo.

@holzschu
Copy link
Contributor Author

Yes, it can be closed.

@louisdh louisdh closed this Mar 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants