Jq: Colored pagination

Created on 23 Apr 2015  Â·  3Comments  Â·  Source: stedolan/jq

Objective: Ability to paginate colored output.

I didn't find any documentation regarding a pagination switch within the jq tool. The only quick recourse for a user is to pipe the jq output to a less like utility. However, this does not yield the colored output.

If the colors were rendered as raw control characters - piping the colored output to less -R would make this feature a possibility.

support

Most helpful comment

Do jq -C jq args | less -R

On Wed, Apr 22, 2015, 18:19 neowulf33 [email protected] wrote:

Objective: Ability to paginate colored output.

I didn't find any documentation regarding a pagination switch within the
jq tool. The only quick recourse for a user is to pipe the jq output to a
less like utility. However, this does not yield the colored output.

If the colors were rendered as raw control characters - piping the colored
output to less -R would make this feature a possibility.

—
Reply to this email directly or view it on GitHub
https://github.com/stedolan/jq/issues/764.

All 3 comments

Do jq -C jq args | less -R

On Wed, Apr 22, 2015, 18:19 neowulf33 [email protected] wrote:

Objective: Ability to paginate colored output.

I didn't find any documentation regarding a pagination switch within the
jq tool. The only quick recourse for a user is to pipe the jq output to a
less like utility. However, this does not yield the colored output.

If the colors were rendered as raw control characters - piping the colored
output to less -R would make this feature a possibility.

—
Reply to this email directly or view it on GitHub
https://github.com/stedolan/jq/issues/764.

Cool that works! Thanks.

Thanks for @wtlangford 's solution. It works as expected.

But I found write -C ... | less -R again and again is very boring. Especially when I need modify the arguments frequently.

Put the following function at bashrc or zshrc will release your fingers:

jqjq() {
    # -F tell less exit if output content can be displayed on one screen
    jq -C "$@" | less -FR
}

Then you use jqjq the same way as jq. When the content is too long, less will automatically take over it.

jqjq args

If you don't like to use another command, add one more line:

alias jq='jqjq'

Now everything doesn't change. Pager will be used when necessory.

jq args
Was this page helpful?
0 / 5 - 0 ratings

Related issues

rubensayshi picture rubensayshi  Â·  3Comments

ghost picture ghost  Â·  4Comments

kaihendry picture kaihendry  Â·  4Comments

mcandre picture mcandre  Â·  3Comments

thelonious picture thelonious  Â·  4Comments