Joachim Breitner

Copying HTML from gnome-terminal

Published 2011-07-21 in sections English, Digital World.

One of the first things that I worked on here at DebConf11 is supporting the HTML target in gnome-terminal. This means that if you copy a part of the screen and paste it into some application that handles HTML (such as evolution or my blog’s edit field), attributes such as color and boldness are preserved. Here are some examples:

A man page

MAN(1)                           Manual pager utils                           MAN(1)

       man - an interface to the on-line reference manuals

       man [-C file] [-d] [-D] [--warnings[=warnings]] [-R encoding] [-L locale] [-m
       system[,...]] [-M path] [-S list] [-e extension] [-i|-I] [--regex|--wildcard]
       [--names-only]  [-a]  [-u]  [--no-subpages]  [-P  pager] [-r prompt] [-7] [-E
       encoding]   [--no-hyphenation]   [--no-justification]   [-p   string]    [-t]
       [-T[device]] [-H[browser]] [-X[dpi]] [-Z] [[section] page ...] ...
       man -k [apropos options] regexp ...
       man -K [-w|-W] [-S list] [-i|-I] [--regex] [section] term ...
       man -f [whatis options] page ...
       man  -l [-C file] [-d] [-D] [--warnings[=warnings]] [-R encoding] [-L locale]
       [-P pager] [-r prompt] [-7]  [-E  encoding]  [-p  string]  [-t]  [-T[device]]
       [-H[browser]] [-X[dpi]] [-Z] file ...
       man -w|-W [-C file] [-d] [-D] page ...
       man -c [-C file] [-d] [-D] page ...
       man [-hV]

       man is the system's manual pager. Each page argument given to man is normally
       the name of a program, utility or function.  The manual page associated  with
       each  of these arguments is then found and displayed. A section, if provided,
 Manual page man(1) line 1 (press h for help or q to quit)

A coloured diff from git

commit 55c514ae6a714abcfa818c33f00a2c051412c3d9
Author: Joachim Breitner <>
Date:   Thu Jul 21 12:08:56 2011 +0200

    Refactor vte_terminal_determine_colors_internal
    to work on VteCellAttr instead of VteCell, and use it in

diff --git a/src/vte.c b/src/vte.c
index 8bcc95d..7d4a6f1 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -6532,19 +6532,18 @@ swap (guint *a, guint *b)
 static void
 vte_terminal_determine_colors_internal(VteTerminal *terminal,
-                                      const VteCell *cell,
+                                      const VteCellAttr *attr,
                                       gboolean selected,
                                       gboolean cursor,
                                       guint *pfore, guint *pback)
        guint fore, back;

Midnight commander

  Links     Datei     Befehl     Optionen     Rechts
┌<─ ~/build/gnome-terminal/vte ───────────.[^]>┐┌<─ ~/build/gnome-terminal/vte ────────────.[^]>┐
│'n        Name           Größe Modifikations││'n         Name           Größe Modifikations│
│/..                     │ÜBERVZ.│20. Jul 18:23││/..                      │ÜBERVZ.│20. Jul 18:23│
│/.git                   │   4096│22. Jul 12:42││/.git                    │   4096│22. Jul 12:42│
│/autom4te.cache         │   4096│22. Jul 11:20││/autom4te.cache          │   4096│22. Jul 11:20│
│/doc                    │   4096│22. Jul 11:20││/doc                     │   4096│22. Jul 11:20│
│/glade                  │   4096│22. Jul 11:20││/glade                   │   4096│22. Jul 11:20│
│/gnome-pty-helper       │   4096│22. Jul 09:47││/gnome-pty-helper        │   4096│22. Jul 09:47│
│/perf                   │   4096│22. Jul 11:20││/perf                    │   4096│22. Jul 11:20│
│/po                     │   4096│22. Jul 11:20││/po                      │   4096│22. Jul 11:20│
│/src                    │  12288│22. Jul 12:41││/src                     │  12288│22. Jul 12:41│
│/termcaps               │   4096│22. Jul 11:20││/termcaps                │   4096│22. Jul 11:20│
│ .gitignore             │    935│22. Jul 11:20││ .gitignore              │    935│22. Jul 11:20│
│ AUTHORS                │     41│20. Jul 18:25││ AUTHORS                 │     41│20. Jul 18:25│
│ COPYING                │  35068│22. Jul 11:11││ COPYING                 │  35068│22. Jul 11:11│
│ ChangeLog.pre-git      │ 433051│20. Jul 18:25││ ChangeLog.pre-git       │ 433051│20. Jul 18:25│
│ HACKING                │    905│20. Jul 18:25││ HACKING                 │    905│20. Jul 18:25│
│ MAINTAINERS            │    118│20. Jul 18:25││ MAINTAINERS             │    118│20. Jul 18:25│
│ Makefile               │  30512│22. Jul 11:20││ Makefile                │  30512│22. Jul 11:20│
│            │   1247│22. Jul 11:11││             │   1247│22. Jul 11:11│
│            │  28812│22. Jul 11:20││             │  28812│22. Jul 11:20│
│ NEWS                   │  43910│20. Jul 18:25││ NEWS                    │  43910│20. Jul 18:25│
│ README                 │    496│20. Jul 18:25││ README                  │    496│20. Jul 18:25│
│ aclocal.m4             │ 377874│22. Jul 11:20││ aclocal.m4              │ 377874│22. Jul 11:20│
│*             │    610│20. Jul 18:25││*              │    610│20. Jul 18:25│
│ÜBERVZ.                                       ││ÜBERVZ.                                        │
└────────────────────────────── 10G/104G (9%) ─┘└─────────────────────────────── 10G/104G (9%) ─┘
Hint: To look at the output of a command in the viewer, use M-!
~/build/gnome-terminal/vte $
 1Hilfe   2Menü    3Ansicht  4Bear~ten 5Kopieren 6Ver~ben 7Mkdir    8Löschen  9Menüs   10Beenden

These changes are discussed in GNOME Bugzilla bug #365121 and can be downloaded in my git repository. Unfortunately, I later found out that I was not basing my work on the current development version, which has changed considerably, so we will see how and when my changes will actually make it into GNOME. Also note that my blog’s HTML editor actually modifies the HTML code, so looking at the source of this page does not give you the code that I generate.

Update: I ported my changes onto the vte-next branch, so they could be merged now. Please follow the bug report if you want to know more.



The menu bar of Midnight Commander looks truncated. Do you intend to fix that?
#1 Marius Gedminas (Homepage) am 2011-07-22
I am not sure what the proper fix would be. mc does not actually emit spaces here and just assumes (rightfully) that the terminal emulator will use the background color of the last character on the line for the remainder of the line.

I could add spaces to the copied data to fill up the line, but then the spaces are not there and this might be a problem in other applications...

Do you have a good idea here? And feel free to discuss this in the bug report, there it is more likely to be found than here.
#2 Joachim Breitner (Homepage) am 2011-07-22
Maybe use a <div> for each line with the background colour style set to the background colour of the last character?
#3 r am 2011-07-26
That’s waht I mean by adding spaces. But that changes the content of the selection; maybe someone wants to know what spaces were really printed by the program. But probably the better compromise; I might implement this once (and if...) my patch is merged.
#4 Joachim Breitner (Homepage) am 2011-07-26

Have something to say? You can post a comment by sending an e-Mail to me at <>, and I will include it here.