Skip to content

Commit

Permalink
Update default colorization (#904)
Browse files Browse the repository at this point in the history
* colorization experiment

* todo

* Add dependency on github.com/johnkerl/lumin

* lumin dependency

* more badges in README.md

* on-line help for bold/underine/reverse

* update webdocs
  • Loading branch information
johnkerl authored Jan 30, 2022
1 parent 1a8d7ed commit bef2fa7
Show file tree
Hide file tree
Showing 19 changed files with 259 additions and 489 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ See also [building from source](https://miller.readthedocs.io/en/latest/build.ht

# Build status

[![Go-port multi-platform build status](https://github.com/johnkerl/miller/actions/workflows/go.yml/badge.svg)](https://github.com/johnkerl/miller/actions)
[![Multi-platform build status](https://github.com/johnkerl/miller/actions/workflows/go.yml/badge.svg)](https://github.com/johnkerl/miller/actions)
[![CodeQL status](https://github.com/johnkerl/miller/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/johnkerl/miller/actions)
[![Codespell status](https://github.com/johnkerl/miller/actions/workflows/codespell.yml/badge.svg)](https://github.com/johnkerl/miller/actions)
[![Release status](https://github.com/johnkerl/miller/actions/workflows/release.yml/badge.svg)](https://github.com/johnkerl/miller/actions)

# Building from source

Expand Down
43 changes: 43 additions & 0 deletions cmd/experiments/colors/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// This is the entry point for the mlr executable.
package main

import (
"fmt"
"github.com/johnkerl/miller/internal/pkg/colorizer"
)

const boldString = "\u001b[1m"
const underlineString = "\u001b[4m"
const reversedString = "\u001b[7m"
const redString = "\u001b[1;31m"
const blueString = "\u001b[1;34m"
const defaultString = "\u001b[0m"

func main() {
fmt.Printf("Hello, world!\n")

fmt.Printf("1. before %s during %s after\n", "", "")
fmt.Printf("4. before %s during %s after\n", boldString, defaultString)
fmt.Printf("2. before %s during %s after\n", redString, defaultString)
fmt.Printf("3. before %s during %s after\n", blueString, defaultString)
fmt.Printf("5. before %s during %s after\n", redString+boldString, defaultString)
fmt.Printf("7. before %s during %s after\n", blueString, defaultString)
fmt.Printf("8. before %s during %s after\n", boldString, defaultString)
fmt.Printf("9. before %s during %s after\n", boldString, defaultString)
fmt.Println()

names := []string{
"plain",
"red",
"bold",
"bold-red",
"red-bold",
"blue-underline",
"208",
"reversed-208",
}
for _, name := range names {
colorizer.SetKeyColor(name)
fmt.Printf("testing: [%s]\n", colorizer.MaybeColorizeKey(name, true))
}
}
9 changes: 6 additions & 3 deletions docs/src/manpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,11 @@ OUTPUT-COLORIZATION FLAGS
If environment-variable settings and command-line flags are both provided, the
latter take precedence.

Please do mlr `--list-color-codes` to see the available color codes (like 170),
and `mlr --list-color-names` to see available names (like `orchid`).
Colors can be specified using names such as "red" or "orchid": please see
`mlr --list-color-names` to see available names. They can also be specified using
numbers in the range 0..255, like 170: please see `mlr --list-color-codes`.
You can also use "bold", "underline", and/or "reverse". Additionally, combinations of
those can be joined with a "-", like "red-bold", "bold-170", "bold-underline", etc.

--always-color or -C Instructs Miller to colorize output even when it
normally would not. Useful for piping output to `less
Expand Down Expand Up @@ -3131,5 +3134,5 @@ SEE ALSO



2022-01-27 MILLER(1)
2022-01-30 MILLER(1)
</pre>
9 changes: 6 additions & 3 deletions docs/src/manpage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,11 @@ OUTPUT-COLORIZATION FLAGS
If environment-variable settings and command-line flags are both provided, the
latter take precedence.

Please do mlr `--list-color-codes` to see the available color codes (like 170),
and `mlr --list-color-names` to see available names (like `orchid`).
Colors can be specified using names such as "red" or "orchid": please see
`mlr --list-color-names` to see available names. They can also be specified using
numbers in the range 0..255, like 170: please see `mlr --list-color-codes`.
You can also use "bold", "underline", and/or "reverse". Additionally, combinations of
those can be joined with a "-", like "red-bold", "bold-170", "bold-underline", etc.

--always-color or -C Instructs Miller to colorize output even when it
normally would not. Useful for piping output to `less
Expand Down Expand Up @@ -3110,4 +3113,4 @@ SEE ALSO



2022-01-27 MILLER(1)
2022-01-30 MILLER(1)
8 changes: 5 additions & 3 deletions docs/src/output-colorization.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ Quick links:
</div>
# Output colorization

As of version 6.0.0, Miller supports output-colorization. Here are examples using side-by-side black-background and white-background terminals:
As of version 6.0.0, Miller supports output colorization. This includes colors
per se, as well as bold, underline, and/or reverse. As of version 6.1.0, the
default is bold+underline for keys -- this works well as a default regardless
of your terminal's color settings -- with further customization options as
described below:

![pix/colorization.png](pix/colorization.png)

Expand All @@ -37,8 +41,6 @@ As of version 6.0.0, Miller supports output-colorization. Here are examples usin

* NIDX output format (plain text, Unix-style, with implicitly positionally indexed fields) is not colored. This is because in other formats, keys are one color and values are another. For NIDX, all output is values.

* The default colors were chosen since they look OK with white or black terminal background, and are differentiable with common varieties of human color vision.

## Mechanisms for colorization

* Miller uses ANSI escape sequences only. This does not work on Windows except on Cygwin.
Expand Down
8 changes: 5 additions & 3 deletions docs/src/output-colorization.md.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Output colorization

As of version 6.0.0, Miller supports output-colorization. Here are examples using side-by-side black-background and white-background terminals:
As of version 6.0.0, Miller supports output colorization. This includes colors
per se, as well as bold, underline, and/or reverse. As of version 6.1.0, the
default is bold+underline for keys -- this works well as a default regardless
of your terminal's color settings -- with further customization options as
described below:

![pix/colorization.png](pix/colorization.png)

Expand All @@ -21,8 +25,6 @@ As of version 6.0.0, Miller supports output-colorization. Here are examples usin

* NIDX output format (plain text, Unix-style, with implicitly positionally indexed fields) is not colored. This is because in other formats, keys are one color and values are another. For NIDX, all output is values.

* The default colors were chosen since they look OK with white or black terminal background, and are differentiable with common varieties of human color vision.

## Mechanisms for colorization

* Miller uses ANSI escape sequences only. This does not work on Windows except on Cygwin.
Expand Down
Binary file modified docs/src/pix/colorization.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/src/pix/colorization.png.000
Binary file not shown.
Binary file removed docs/src/pix/colorization2.png.000
Binary file not shown.
7 changes: 5 additions & 2 deletions docs/src/reference-main-flag-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,11 @@ How you can control colorization:
If environment-variable settings and command-line flags are both provided, the
latter take precedence.

Please do mlr `--list-color-codes` to see the available color codes (like 170),
and `mlr --list-color-names` to see available names (like `orchid`).
Colors can be specified using names such as "red" or "orchid": please see
`mlr --list-color-names` to see available names. They can also be specified using
numbers in the range 0..255, like 170: please see `mlr --list-color-codes`.
You can also use "bold", "underline", and/or "reverse". Additionally, combinations of
those can be joined with a "-", like "red-bold", "bold-170", "bold-underline", etc.


**Flags:**
Expand Down
18 changes: 9 additions & 9 deletions docs/src/scripting.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Key points here:
Then you can do

<pre class="pre-highlight-in-pair">
<b>example-shell-script example.csv</b>
<b>./example-shell-script example.csv</b>
</pre>
<pre class="pre-non-highlight-in-pair">
shape count count_fraction
Expand All @@ -75,7 +75,7 @@ circle 3 0.3
</pre>

<pre class="pre-highlight-in-pair">
<b>cat example.csv | example-shell-script</b>
<b>cat example.csv | ./example-shell-script</b>
</pre>
<pre class="pre-non-highlight-in-pair">
shape count count_fraction
Expand All @@ -85,7 +85,7 @@ circle 3 0.3
</pre>

<pre class="pre-highlight-in-pair">
<b>example-shell-script --ojson example.csv</b>
<b>./example-shell-script --ojson example.csv</b>
</pre>
<pre class="pre-non-highlight-in-pair">
[
Expand All @@ -108,7 +108,7 @@ circle 3 0.3
</pre>

<pre class="pre-highlight-in-pair">
<b>example-shell-script --ojson then filter '$count == 3' example.csv</b>
<b>./example-shell-script --ojson then filter '$count == 3' example.csv</b>
</pre>
<pre class="pre-non-highlight-in-pair">
[
Expand All @@ -132,7 +132,7 @@ etc.
Here instead of putting `#!/bin/bash` on the first line, we can put `mlr` directly:

<pre class="pre-highlight-in-pair">
<b>cat example-mlr-s-script</b>
<b>cat ./example-mlr-s-script</b>
</pre>
<pre class="pre-non-highlight-in-pair">
#!/usr/bin/env mlr -s
Expand All @@ -153,7 +153,7 @@ Points:
Then you can do

<pre class="pre-highlight-in-pair">
<b>example-mlr-s-script example.csv</b>
<b>./example-mlr-s-script example.csv</b>
</pre>
<pre class="pre-non-highlight-in-pair">
shape count count_fraction
Expand All @@ -163,7 +163,7 @@ circle 3 0.3
</pre>

<pre class="pre-highlight-in-pair">
<b>cat example.csv | example-mlr-s-script</b>
<b>cat example.csv | ./example-mlr-s-script</b>
</pre>
<pre class="pre-non-highlight-in-pair">
shape count count_fraction
Expand All @@ -173,7 +173,7 @@ circle 3 0.3
</pre>

<pre class="pre-highlight-in-pair">
<b>example-mlr-s-script --ojson example.csv</b>
<b>./example-mlr-s-script --ojson example.csv</b>
</pre>
<pre class="pre-non-highlight-in-pair">
[
Expand All @@ -196,7 +196,7 @@ circle 3 0.3
</pre>

<pre class="pre-highlight-in-pair">
<b>example-mlr-s-script --ojson then filter '$count == 3' example.csv</b>
<b>./example-mlr-s-script --ojson then filter '$count == 3' example.csv</b>
</pre>
<pre class="pre-non-highlight-in-pair">
[
Expand Down
18 changes: 9 additions & 9 deletions docs/src/scripting.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ Key points here:
Then you can do

GENMD-RUN-COMMAND
example-shell-script example.csv
./example-shell-script example.csv
GENMD-EOF

GENMD-RUN-COMMAND
cat example.csv | example-shell-script
cat example.csv | ./example-shell-script
GENMD-EOF

GENMD-RUN-COMMAND
example-shell-script --ojson example.csv
./example-shell-script --ojson example.csv
GENMD-EOF

GENMD-RUN-COMMAND
example-shell-script --ojson then filter '$count == 3' example.csv
./example-shell-script --ojson then filter '$count == 3' example.csv
GENMD-EOF

etc.
Expand All @@ -57,7 +57,7 @@ etc.
Here instead of putting `#!/bin/bash` on the first line, we can put `mlr` directly:

GENMD-RUN-COMMAND
cat example-mlr-s-script
cat ./example-mlr-s-script
GENMD-EOF

Points:
Expand All @@ -71,19 +71,19 @@ Points:
Then you can do

GENMD-RUN-COMMAND
example-mlr-s-script example.csv
./example-mlr-s-script example.csv
GENMD-EOF

GENMD-RUN-COMMAND
cat example.csv | example-mlr-s-script
cat example.csv | ./example-mlr-s-script
GENMD-EOF

GENMD-RUN-COMMAND
example-mlr-s-script --ojson example.csv
./example-mlr-s-script --ojson example.csv
GENMD-EOF

GENMD-RUN-COMMAND
example-mlr-s-script --ojson then filter '$count == 3' example.csv
./example-mlr-s-script --ojson then filter '$count == 3' example.csv
GENMD-EOF

## Miller scripts on Windows
Expand Down
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ module github.com/johnkerl/miller
// * go build github.com/johnkerl/miller/cmd/mlr
// * go install github.com/johnkerl/miller/cmd/mlr

// go get github.com/johnkerl/[email protected]
// Local development:
// replace github.com/johnkerl/lumin => /Users/kerl/git/johnkerl/lumin

go 1.15

require (
github.com/goccmack/gocc v0.0.0-20211213154817-7ea699349eca // indirect
github.com/johnkerl/lumin v1.0.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/lestrrat-go/strftime v1.0.5
github.com/mattn/go-isatty v0.0.14
Expand Down
30 changes: 2 additions & 28 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/goccmack/gocc v0.0.0-20211213154817-7ea699349eca h1:NuA6w6b01Ojdig+4K1l9p4Pp3unlv4owphbOiENm8m4=
github.com/goccmack/gocc v0.0.0-20211213154817-7ea699349eca/go.mod h1:c4Mb67Mg9+pl6OlxvnFBUiiQOSlXfh0QukINLl54OD0=
github.com/johnkerl/lumin v1.0.0 h1:CV34cHZOJ92Y02RbQ0rd4gA0C06Qck9q8blOyaPoWpU=
github.com/johnkerl/lumin v1.0.0/go.mod h1:eLf5AdQOaLvzZ2zVy4REr/DSeEwG+CZreHwNLICqv9E=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc h1:RKf14vYWi2ttpEmkA4aQ3j4u9dStX2t4M8UM6qqNsG8=
Expand All @@ -20,38 +20,12 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
Expand Down
7 changes: 5 additions & 2 deletions internal/pkg/cli/option_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -2452,8 +2452,11 @@ How you can control colorization:
If environment-variable settings and command-line flags are both provided, the
latter take precedence.
Please do mlr ` + "`--list-color-codes`" + ` to see the available color codes (like 170),
and ` + "`mlr --list-color-names`" + ` to see available names (like ` + "`orchid`" + `).
Colors can be specified using names such as "red" or "orchid": please see
` + "`mlr --list-color-names`" + ` to see available names. They can also be specified using
numbers in the range 0..255, like 170: please see ` + "`mlr --list-color-codes`" + `.
You can also use "bold", "underline", and/or "reverse". Additionally, combinations of
those can be joined with a "-", like "red-bold", "bold-170", "bold-underline", etc.
`)
}

Expand Down
Loading

0 comments on commit bef2fa7

Please sign in to comment.