directvt / vtm

Text-based desktop environment
MIT License
1.61k stars 43 forks source link

Copy selected text in HTML and RTF format #246

Closed o-sdn-o closed 2 years ago

o-sdn-o commented 2 years ago

xlink: https://github.com/microsoft/terminal/issues/1860#issuecomment-1272066364

o-sdn-o commented 2 years ago

If vtm is running locally, it is possible to simply populate the clipboard using the native Windows APIs, as the Windows Terminal does.

Note that OSC52 only serves to transmit plain text.

Worth reading https://specifications.freedesktop.org/clipboards-spec/clipboards-latest.txt

RTF

Test sample

{\rtf1\ansi\deff0\fcharset1
{\fonttbl{\f0\fmodern Courier;}}
Hello!
\line Control symbols: \\\{\}
\line{\i This is Italic text }
\line UTF-8 ๐Ÿ™‚๐Ÿ™‚๐Ÿ™‚๐Ÿ‘๐Ÿ‘๐Ÿ‘
\line{\b Bold text}
\line{\strike Turns on strikethrough}
\line{\ul Turns on continuous underline}
\line{\ul0 Turns off all underlining}
\line{\uldb Turns on double underline}
{\colortbl;\red0\green0\blue00;\red0\green0\blue000000255;\red255\green0\blue255;}
\line\highlight1\cf2Blue text
\line\highlight2\cf3This is colored text
\cf0\highlight0
\line\chshdng10000\cb1\cf2\chcbpat1\chcfpat2Blue text
\line\chshdng10000\cb2\cf3\chcbpat2\chcfpat3This is colored text
\chshdng0\cb0\cf0\chcbpat0\chcfpat0
\line Multipurpose Internet Mail Extension
\line ๏ผˆๅคš็›ฎ็š„ใ‚คใƒณใ‚ฟใƒผใƒใƒƒใƒˆใƒกใƒผใƒซๆ‹กๅผต๏ผ‰
\line
}

Windows

MS Windows rich edit controls register following clipboard formats

https://learn.microsoft.com/en-us/windows/win32/controls/use-rich-edit-clipboard-operations?redirectedfrom=MSDN

https://en.wikipedia.org/wiki/Rich_Text_Format

Proprietary Rich Text Format Version 1.5 (Unicode RTF) Specification https://www.biblioscape.com/rtf15_spec.htm

RTF supports generic font family names used for font substitution: roman (serif), Swiss (sans-serif), modern (monospace), script, decorative and technical. https://latex2rtf.sourceforge.net/RTF-Spec-1.0.txt

Note: Word 2013 does not resolve \highlightN colors from the \colortbl. Instead, \highlightN maps to a predefined list of colors. Windows versions of Word have never supported \cbN, but it can be emulated by the control word sequence \chshdng0\chcbpatN. https://stackoverflow.com/questions/3513758/how-can-i-change-the-background-color-of-specific-characters-in-a-rtf-document

Regarding leading spaces

MacOS

The default text editor for macOS, TextEdit, can also view, edit and save RTF files as well as RTFD files, and uses the format as its default. As of July 2009, TextEdit has limited ability to edit RTF document margins. Much older Mac word processing application programs such as MacWrite and WriteNow had the same RTF abilities as TextEdit has.

HTML

Windows

https://learn.microsoft.com/en-us/windows/win32/dataxchg/html-clipboard-format

X11

2.6.1.3. The CLIPBOARD Selection https://www.x.org/docs/ICCCM/icccm.pdf

Copy html target in VTE

Android

...

MacOS

...

o-sdn-o commented 2 years ago

Turned out nice enough (Ctrl+RightDrag to screen copy from vtm)

image

image