dnkl/foot
41
2.0k
Fork
You've already forked foot
242

Allow copying text with (recreated) ANSI escape codes #2004

Open
opened 2025年03月20日 15:06:18 +01:00 by 5225225 · 7 comments

Describe your feature request

I understand that foot doesn't actually know what ANSI codes were used to make the given text on screen, but emitting ANSI escapes that produce the same result would be good enough.

The use case is being able to copy and paste text output from programs while keeping the color formatting from it.

One open question I can think of is "should URLs be preserved?". I would say yes but that might be surprising (users not knowing some text is even hyperlinked).

There's 2 ways I think this could be reasonably implemented, one being a new shortcut that puts the ansi text in the text/plain clipboard type, and the other being just always offering up a text/ansi (or whatever the most commonly used MIME type for ANSI encoded text is... https://stackoverflow.com/questions/73415087/what-mime-type-for-text-with-ansi-escape-sequences-color-codes seems to say there's no real standard for this.)

Alternatively, both can be done, unconditionally offering up a text/ansi and also having a shortcut to copy text as ANSI into the text/plain clipboard.

### Describe your feature request I understand that foot doesn't actually know what ANSI codes were used to *make* the given text on screen, but emitting ANSI escapes that produce the same result would be good enough. The use case is being able to copy and paste text output from programs while keeping the color formatting from it. One open question I can think of is "should URLs be preserved?". I would say *yes* but that might be surprising (users not knowing some text is even hyperlinked). There's 2 ways I think this could be reasonably implemented, one being a new shortcut that puts the ansi text in the `text/plain` clipboard type, and the other being just always offering up a `text/ansi` (or whatever the most commonly used MIME type for ANSI encoded text is... https://stackoverflow.com/questions/73415087/what-mime-type-for-text-with-ansi-escape-sequences-color-codes seems to say there's no real standard for this.) Alternatively, both can be done, unconditionally offering up a `text/ansi` and *also* having a shortcut to copy text as ANSI into the `text/plain` clipboard.
Collaborator
Copy link

The use case is being able to copy and paste text output from programs while keeping the color formatting from it.

I wouldn't really call that a "use case". That's just a description of what output you'd expect and how you'd capture it. Where would you paste it and for what purpose?

One open question I can think of is "should URLs be preserved?"

That's the kind of question that'd be easier to answer in the context of a use case.

> The use case is being able to copy and paste text output from programs while keeping the color formatting from it. I wouldn't really call that a "use case". That's just a description of what output you'd expect and how you'd capture it. Where would you paste it and for what purpose? > One open question I can think of is "should URLs be preserved?" That's the kind of question that'd be easier to answer in the context of a use case.
Owner
Copy link

Where would you paste it and for what purpose?

This is key. Otherwise we could just as well offer richtext, or any other formatting capable format.

> Where would you paste it and for what purpose? This is key. Otherwise we could just as well offer richtext, or any other formatting capable format.
Owner
Copy link

(not saying I'm willing to add support for richtext)

(not saying I'm willing to add support for richtext)
Contributor
Copy link

(not saying I'm willing to add support for richtext)
hahahahaha, I found that very funny.

> (not saying I'm willing to add support for richtext) *hahahahaha*, I found that very funny.
Contributor
Copy link

I also would be interested in the actual use case. Sometimes I wish I could preserve my colored shell output when I have to copy that into our support tickets, but to copy that in a usefull way for a web form, you probably most likely need to have the ansi sequences transformed to whatever is expected.

I am not sure ansi sequences by themselves are actually usefull outside of a terminal? I could be wrong though.

I also would be interested in the actual use case. Sometimes I wish I could preserve my colored shell output when I have to copy that into our support tickets, but to copy that in a usefull way for a web form, you probably most likely need to have the ansi sequences transformed to whatever is expected. I am not sure `ansi` sequences by themselves are actually usefull outside of a terminal? I could be wrong though.
Author
Copy link

The main 2 places I'd use it are discord(which admittedly has a pretty poor implementation of ANSI escapes by only supporting 8 foreground/background colors each, but its still useful for copy pasting compiler error messages, for example)

and pasting into a ANSI to HTML converter to put "screenshots" of terminal output on my site (I currently just do this by hand if i want a terminal output)

both of these use cases can be done without this feature (by redirecting to a file or wl-copy), but thats less convenient since then you need to go figure out how to make the application think it's still outputting to a terminal.

The main 2 places I'd use it are discord(which admittedly has a pretty poor implementation of ANSI escapes by only supporting 8 foreground/background colors each, but its still useful for copy pasting compiler error messages, for example) and pasting into a ANSI to HTML converter to put "screenshots" of terminal output on my site (I currently just do this by hand if i want a terminal output) both of these use cases *can* be done without this feature (by redirecting to a file or wl-copy), but thats less convenient since then you need to go figure out how to make the application think it's still outputting to a terminal.

I ended up implementing ANSI for piping commands (like piping the last command output). Speaking for myself, I don't much care for styles. but hyperlinks are rather important part. A fancy pager (ov) can use them. usual workflow can be something like having grep output in another terminal with links and colour. (without rerunning grep again.)

The code looks horrendous, so I'm not sure to make a PR.

I ended up implementing [ANSI](https://codeberg.org/saeedark/foot/commit/4d86271536b3c394f95409c29d758df72fa5efbd) for piping commands (like piping the last command output). Speaking for myself, I don't much care for styles. but hyperlinks are rather important part. A fancy pager ([ov](github.com/noborus/ov)) can use them. usual workflow can be something like having grep output in another terminal with links and colour. (without rerunning grep again.) The code looks horrendous, so I'm not sure to make a PR.
Sign in to join this conversation.
No Branch/Tag specified
master
osc-5522
sixel-heap-buffer-overflow
releases/1.27
releases/1.26
releases/1.25
releases/1.24
multi-cursor
releases/1.23
pixman-16f-2
releases/1.22
releases/1.21
releases/1.20
releases/1.19
releases/1.18
releases/1.17
releases/1.16
releases/1.15
releases/1.14
releases/1.13
releases/1.12
releases/1.11
releases/1.10
releases/1.9
releases/1.8
releases/1.7
releases/1.6
releases/1.5
releases/1.4
releases/1.3
releases/1.2
releases/1.1
releases/1.0
1.27.0
1.26.1
1.26.0
1.25.0
1.24.0
1.23.1
1.23.0
1.22.3
1.22.2
1.22.1
1.22.0
1.21.0
1.20.2
1.20.1
1.20.0
1.19.0
1.18.1
1.18.0
1.17.2
1.17.1
1.17.0
1.16.2
1.16.1
1.16.0
1.15.3
1.15.2
1.15.1
1.15.0
1.14.0
1.13.1
1.13.0
1.12.1
1.12.0
1.11.0
1.10.3
1.10.2
1.10.1
1.10.0
1.9.2
1.9.1
1.9.0
1.8.2
1.8.1
1.8.0
1.7.2
1.7.1
1.7.0
1.6.4
1.6.3
1.6.2
1.6.1
1.6.0
1.5.4
1.5.3
1.5.2
1.5.1
1.5.0
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.3.0
1.2.3
1.2.2
1.2.1
1.2.0
1.1.0
1.0.0
0.9.0
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
5 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dnkl/foot#2004
Reference in a new issue
dnkl/foot
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?