How to use the blocks feature?

290 views
Skip to first unread message

Enrico B. da Luz

unread,
Oct 4, 2023, 12:05:22 AM10/4/23
to iterm2-discuss
Hi, I noticed this in a recent update:

It also adds a new "blocks" feature for quoting
blocks of code, including an in-the-terminal
button to copy code to the pasteboard.


How do I use it? Can someone share more details?

Thanks!

George Nachman

unread,
Oct 5, 2023, 1:32:04 PM10/5/23
to iterm2-...@googlegroups.com
Here’s some sample code:


Here’s what it looks like:


The block is defined by the bar on the left side. The “copy to clipboard” link and button refer to its identifier. The main use of blocks is to simplify copying chunks of code to the clipboard. If you have ideas on what else it could do, let  me know!

--
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-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/iterm2-discuss/37674355-1a87-45dd-8241-db89c4c6cf64n%40googlegroups.com.

Enrico B. da Luz

unread,
Oct 9, 2023, 1:26:01 AM10/9/23
to iterm2-discuss
Nice, thanks for that George!

For reference, I've managed to replicate this using bash, either I'm doing something wrong or it's copying the next line beyond the output:

#!/usr/bin/env bash

start_block() {
  block_id="$1"
  type="$2"
  echo -ne "\033]1337;Block=attr=start;id=$block_id;type=$type\a"
}

end_block() {
  block_id="$1"
  echo -ne "\033]1337;Block=attr=end;id=$block_id;render=0\a"
}

copyButton() {
  block_id="$1"
  echo -ne "\033]1337;Button=type=copy;block=$block_id\a"
}

block_id=$(uuidgen)
block_type='python'

content="print('$block_id')"

echo $(copyButton $block_id)
echo -n $(start_block $block_id $block_type)
echo $content
# With `-n` it will copy the next line (typically a PS1 / prompt)
# Without `-n` it won't copy the prompt but it will print an extra line
echo -n $(end_block $block_id)


In terms of ideas, it would be nice to be able to collapse blocks. Actually, that would be handy for the whole command output and maybe blocks could be collapsed as a sub-level.

George Nachman

unread,
Oct 15, 2023, 3:05:45 PM10/15/23
to iterm2-...@googlegroups.com
The bug with selecting an extra line is fixed now.

I agree collapsing would be nice. That’s been in the todo list for a long time but it’s pretty difficult to get right.

Reply all
Reply to author
Forward
0 new messages