How can I pipe to less or more?
ccbcreg opened this issue · 10 comments
I create some rather large json files and would like to pass or pipe the output from pjson to programs like less or more. However, I am not getting the desired results, see example below. Could you suggest a way to do this?
This works great!:
echo test.js | pjson
{
"australia": {
"iso": "AU",
"name": "Australia"
}
}
I'd like to be able to pass the output from pjson to less or more like so:
echo test.js | pjson | less
{ESC[39;49;00m
ESC[39;49;00mESC[34;01m"australia"ESC[39;49;00m:ESC[39;49;00m ESC[39;49;00m{ESC[39;49;00m
ESC[39;49;00mESC[34;01m"iso"ESC[39;49;00m:ESC[39;49;00m ESC[39;49;00mESC[33m"AU"ESC[39;49;00m,ESC[39;49;00m ESC[39;49;00m
ESC[39;49;00mESC[34;01m"name"ESC[39;49;00m:ESC[39;49;00m ESC[39;49;00mESC[33m"Australia"ESC[39;49;00m
ESC[39;49;00m}ESC[39;49;00m
}ESC[39;49;00m
Any suggestions?
I'm not sure how to handle piped output, it's definitely just printing the colors.
I'll investigate anyways, if somebody knows mention it here I could add it.
I think you'd probably need to do echo test.js | pjson --no-color | less
(with the imaginary --no-color
flag). Less isn't very bright when it comes to colors...
Haha look at this guys:
curl https://github.com/igorgue.json | pjson | less -RSFX
So awesome!
I'd close the issue if I get a +1
Works for me! Thank you Igor.
Didn't work for me :( got the formatting but no color.
@aerovistae Did a little bit of research and I'm not sure how to fix the issue. Does less
prints in color?
Reopened the issue, to see what's up.
This might be of interest -- https://github.com/alghanmi/terminal_color_test -- pipe this through less, with the appropriate flags set -- -R
, I think?
@winny- interesting, wonder if there's an option in Pygments to do that, looking at the code here, looks to me I need to use the format
function directly, I wonder if I upgrade Pygments it'll work out, anyways, I'll take a look later, here's the piece of the code I think is where I gonna have to do something else: https://bitbucket.org/birkenfeld/pygments-main/src/a287342ee7165f50fdd54e3500be48256222cff6/pygments/__init__.py?at=default#cl-79
@igorgue Oh, no. I only mentioned alghanmi/terminal_color_test to demonstrate an easy way to make sure color is working properly.
As mentioned earlier, color can be enabled via passing the -t
flag to pjson
in conjunction to the -R
flag for less
. Example: