Discussion:
[iterm2-discuss] formatting JSON
Nick Richards
2018-10-25 20:20:58 UTC
Permalink
How about a pop-up window which can both unescape (\"key\" : \"value\" =>
"key" : "value") and format any block of text alt-clicked upon?

iTerm2 currently can recognize links you alt-click on. How about it tries
to find the biggest enclosed JSON or escaped-JSON, spanning one or multiple
lines, and pop-up a little helper scrollable window?

I'd REALLY like that.
is iterm2 able to 'prettify' JSON before it displays it?
https://stedolan.github.io/jq/
cool, haven't heard of this before. thanks for the recommendation!
Looks like jq is available via brew
aztec:~ rhornsby$ brew info jq
jq: stable 1.5 (bottled), HEAD
Lightweight and flexible command-line JSON processor
https://stedolan.github.io/jq/
--
You received this message because you are subscribed to the Google Groups "iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
George Nachman
2018-10-26 19:23:17 UTC
Permalink
I'm glad this thread came up again today as this capability will exist in
iTerm2 version 3.3 as a status bar extension. Here's a script that
implements it:

https://iterm2.com/python-api/examples/jsonpretty.html

This stuff is still in development and will probably break from time to
time, but I'd love to get feedback on it.
Post by Nick Richards
How about a pop-up window which can both unescape (\"key\" : \"value\" =>
"key" : "value") and format any block of text alt-clicked upon?
iTerm2 currently can recognize links you alt-click on. How about it tries
to find the biggest enclosed JSON or escaped-JSON, spanning one or multiple
lines, and pop-up a little helper scrollable window?
I'd REALLY like that.
is iterm2 able to 'prettify' JSON before it displays it?
https://stedolan.github.io/jq/
cool, haven't heard of this before. thanks for the recommendation!
Looks like jq is available via brew
aztec:~ rhornsby$ brew info jq
jq: stable 1.5 (bottled), HEAD
Lightweight and flexible command-line JSON processor
https://stedolan.github.io/jq/
--
You received this message because you are subscribed to the Google Groups
"iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Nick Richards
2018-10-26 22:07:23 UTC
Permalink
A happy coincidence. Thanks for the quick response to my inquiry.

Fascinating. Just watched the MOV on Patreon by you George (link
https://www.patreon.com/posts/custom-status-21946224). This should do
the trick.

Seems to me that my use-case could be implemented by me with v3.3:
"Unescape and Re-Pretty until satisfied." I'm often dealing with encoded
JSON(JSON(JSON))) and the bracket range-selection (Option+Cmd+DoubleClick
on the bracket) + browser pop-up for collecting / rendering web content +
scripting features would facilitate that usage nicely.

Possibly I'd customize the script and add controls (similar to the
iTerm2v3.3 status bar?) for the web view itself to be able to "re-pretty
and unescape" the body, "going deeper" so to speak. Enabling how one may
recursively Go To Definition on an unknown symbol, then when satisfied one
may unwind their stack back to whatever code they were developing.

OT: White on black works fine for a new webview. Might be nice in the
future if the webview could adopt some of the color scheme as an injectable
prebuilt css derived from the current Terminal Profile.

https://iterm2.com/python-api/statusbar.html#iterm2.CheckboxKnob is just a
button? or is a thing that is associated with data too?

I guess defocusing, or ESC withdraws the webview?

Cheers,
Nick
Post by George Nachman
I'm glad this thread came up again today as this capability will exist in
iTerm2 version 3.3 as a status bar extension. Here's a script that
https://iterm2.com/python-api/examples/jsonpretty.html
This stuff is still in development and will probably break from time to
time, but I'd love to get feedback on it.
Post by Nick Richards
How about a pop-up window which can both unescape (\"key\" : \"value\" =>
"key" : "value") and format any block of text alt-clicked upon?
iTerm2 currently can recognize links you alt-click on. How about it tries
to find the biggest enclosed JSON or escaped-JSON, spanning one or multiple
lines, and pop-up a little helper scrollable window?
I'd REALLY like that.
is iterm2 able to 'prettify' JSON before it displays it?
https://stedolan.github.io/jq/
cool, haven't heard of this before. thanks for the recommendation!
Looks like jq is available via brew
aztec:~ rhornsby$ brew info jq
jq: stable 1.5 (bottled), HEAD
Lightweight and flexible command-line JSON processor
https://stedolan.github.io/jq/
--
You received this message because you are subscribed to the Google Groups
"iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the
Google Groups "iterm2-discuss" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/iterm2-discuss/FSUYi9uVfJY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
George Nachman
2018-10-26 22:40:25 UTC
Permalink
Post by Nick Richards
Possibly I'd customize the script and add controls (similar to the
iTerm2v3.3 status bar?) for the web view itself to be able to "re-pretty
and unescape" the body, "going deeper" so to speak. Enabling how one may
recursively Go To Definition on an unknown symbol, then when satisfied one
may unwind their stack back to whatever code they were developing.
The only unsolved problem is communicating from the web view back to your
script. My best idea is to use JavaScript websockets to run an api client
in the web view, and have a way for two api clients to pass each other
messages. Kinda complicated though.
Post by Nick Richards
OT: White on black works fine for a new webview. Might be nice in the
future if the webview could adopt some of the color scheme as an injectable
prebuilt css derived from the current Terminal Profile.
Yeah, looks jarring in dark mode. I’ll look into it.
Post by Nick Richards
https://iterm2.com/python-api/statusbar.html#iterm2.CheckboxKnob is just
a button? or is a thing that is associated with data too?
Knobs are for configuring status bar components through preferences.
Post by Nick Richards
I guess defocusing, or ESC withdraws the webview?
Yep
Post by Nick Richards
Cheers,
Nick
Post by George Nachman
I'm glad this thread came up again today as this capability will exist in
iTerm2 version 3.3 as a status bar extension. Here's a script that
https://iterm2.com/python-api/examples/jsonpretty.html
This stuff is still in development and will probably break from time to
time, but I'd love to get feedback on it.
Post by Nick Richards
How about a pop-up window which can both unescape (\"key\" : \"value\"
=> "key" : "value") and format any block of text alt-clicked upon?
iTerm2 currently can recognize links you alt-click on. How about it
tries to find the biggest enclosed JSON or escaped-JSON, spanning one or
multiple lines, and pop-up a little helper scrollable window?
I'd REALLY like that.
is iterm2 able to 'prettify' JSON before it displays it?
https://stedolan.github.io/jq/
cool, haven't heard of this before. thanks for the recommendation!
Looks like jq is available via brew
aztec:~ rhornsby$ brew info jq
jq: stable 1.5 (bottled), HEAD
Lightweight and flexible command-line JSON processor
https://stedolan.github.io/jq/
--
You received this message because you are subscribed to the Google
Groups "iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the
Post by George Nachman
Google Groups "iterm2-discuss" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/iterm2-discuss/FSUYi9uVfJY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Nick Richards
2018-10-27 01:32:34 UTC
Permalink
Groovy.

If you do need two way communication Web sockets does sound to me like a
good idea. Using other browser-technologies like POST'ing to special URLs
means dealing with caching and security (XSS / CORS ?). I've had to use
that technique for an Objective-C mobile app which hosted a JS webview, and
it was painful + slow due to character conversion / JavaScript runtime
overhead.

Perhaps it would be fun to create a JS WebSockets client & server, get that
working, then a Python WebSockets client & server, get that working, then
connect the ports together to get JS & Python talking. Not that I have any
experience with WebSockets libraries.

Looking forward to learning more about what you discover and decide upon.

And looking forward to Knobs :) Thanks for the consideration around the
CSS, is really just a thought.

Cheers,
Nick
Post by George Nachman
Post by Nick Richards
Possibly I'd customize the script and add controls (similar to the
iTerm2v3.3 status bar?) for the web view itself to be able to "re-pretty
and unescape" the body, "going deeper" so to speak. Enabling how one may
recursively Go To Definition on an unknown symbol, then when satisfied one
may unwind their stack back to whatever code they were developing.
The only unsolved problem is communicating from the web view back to your
script. My best idea is to use JavaScript websockets to run an api client
in the web view, and have a way for two api clients to pass each other
messages. Kinda complicated though.
Post by Nick Richards
OT: White on black works fine for a new webview. Might be nice in the
future if the webview could adopt some of the color scheme as an injectable
prebuilt css derived from the current Terminal Profile.
Yeah, looks jarring in dark mode. I’ll look into it.
Post by Nick Richards
https://iterm2.com/python-api/statusbar.html#iterm2.CheckboxKnob is just
a button? or is a thing that is associated with data too?
Knobs are for configuring status bar components through preferences.
Post by Nick Richards
I guess defocusing, or ESC withdraws the webview?
Yep
Post by Nick Richards
Cheers,
Nick
Post by George Nachman
I'm glad this thread came up again today as this capability will exist
in iTerm2 version 3.3 as a status bar extension. Here's a script that
https://iterm2.com/python-api/examples/jsonpretty.html
This stuff is still in development and will probably break from time to
time, but I'd love to get feedback on it.
Post by Nick Richards
How about a pop-up window which can both unescape (\"key\" : \"value\"
=> "key" : "value") and format any block of text alt-clicked upon?
iTerm2 currently can recognize links you alt-click on. How about it
tries to find the biggest enclosed JSON or escaped-JSON, spanning one or
multiple lines, and pop-up a little helper scrollable window?
I'd REALLY like that.
is iterm2 able to 'prettify' JSON before it displays it?
https://stedolan.github.io/jq/
cool, haven't heard of this before. thanks for the recommendation!
Looks like jq is available via brew
aztec:~ rhornsby$ brew info jq
jq: stable 1.5 (bottled), HEAD
Lightweight and flexible command-line JSON processor
https://stedolan.github.io/jq/
--
You received this message because you are subscribed to the Google
Groups "iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the
Post by George Nachman
Google Groups "iterm2-discuss" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/iterm2-discuss/FSUYi9uVfJY/unsubscribe
.
To unsubscribe from this group and all its topics, send an email to
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the
Google Groups "iterm2-discuss" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/iterm2-discuss/FSUYi9uVfJY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
George Nachman
2018-10-29 17:57:21 UTC
Permalink
iTerm2 runs a websocket server on port 1912, which is how scripts
communicate with it. Your javascript could act like a script and set a
user-defined variable, which are easy for scripts to listen for. You'll
need javascript protobufs (fun!), as I have only implemented a friendly API
for Python. The API is documented in the protobuf definition:
https://github.com/gnachman/iTerm2/blob/master/proto/api.proto

There's an old and perhaps working node.js example here:
https://github.com/gnachman/iTerm2/tree/master/tests/websocket
Post by Nick Richards
Groovy.
If you do need two way communication Web sockets does sound to me like a
good idea. Using other browser-technologies like POST'ing to special URLs
means dealing with caching and security (XSS / CORS ?). I've had to use
that technique for an Objective-C mobile app which hosted a JS webview, and
it was painful + slow due to character conversion / JavaScript runtime
overhead.
Perhaps it would be fun to create a JS WebSockets client & server, get
that working, then a Python WebSockets client & server, get that working,
then connect the ports together to get JS & Python talking. Not that I have
any experience with WebSockets libraries.
Looking forward to learning more about what you discover and decide upon.
And looking forward to Knobs :) Thanks for the consideration around the
CSS, is really just a thought.
Cheers,
Nick
Post by George Nachman
Post by Nick Richards
Possibly I'd customize the script and add controls (similar to the
iTerm2v3.3 status bar?) for the web view itself to be able to "re-pretty
and unescape" the body, "going deeper" so to speak. Enabling how one may
recursively Go To Definition on an unknown symbol, then when satisfied one
may unwind their stack back to whatever code they were developing.
The only unsolved problem is communicating from the web view back to your
script. My best idea is to use JavaScript websockets to run an api client
in the web view, and have a way for two api clients to pass each other
messages. Kinda complicated though.
Post by Nick Richards
OT: White on black works fine for a new webview. Might be nice in the
future if the webview could adopt some of the color scheme as an injectable
prebuilt css derived from the current Terminal Profile.
Yeah, looks jarring in dark mode. I’ll look into it.
Post by Nick Richards
https://iterm2.com/python-api/statusbar.html#iterm2.CheckboxKnob is
just a button? or is a thing that is associated with data too?
Knobs are for configuring status bar components through preferences.
Post by Nick Richards
I guess defocusing, or ESC withdraws the webview?
Yep
Post by Nick Richards
Cheers,
Nick
Post by George Nachman
I'm glad this thread came up again today as this capability will exist
in iTerm2 version 3.3 as a status bar extension. Here's a script that
https://iterm2.com/python-api/examples/jsonpretty.html
This stuff is still in development and will probably break from time to
time, but I'd love to get feedback on it.
Post by Nick Richards
How about a pop-up window which can both unescape (\"key\" : \"value\"
=> "key" : "value") and format any block of text alt-clicked upon?
iTerm2 currently can recognize links you alt-click on. How about it
tries to find the biggest enclosed JSON or escaped-JSON, spanning one or
multiple lines, and pop-up a little helper scrollable window?
I'd REALLY like that.
is iterm2 able to 'prettify' JSON before it displays it?
https://stedolan.github.io/jq/
cool, haven't heard of this before. thanks for the recommendation!
Looks like jq is available via brew
aztec:~ rhornsby$ brew info jq
jq: stable 1.5 (bottled), HEAD
Lightweight and flexible command-line JSON processor
https://stedolan.github.io/jq/
--
You received this message because you are subscribed to the Google
Groups "iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the
Post by George Nachman
Google Groups "iterm2-discuss" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/iterm2-discuss/FSUYi9uVfJY/unsubscribe
.
To unsubscribe from this group and all its topics, send an email to
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups "iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the
Google Groups "iterm2-discuss" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/iterm2-discuss/FSUYi9uVfJY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...