Up: Basic use   [Contents][Index]


3.1.1 Hyperlinks

Text output may contain hyperlinks. These hyperlinks are encoded through an escape sequence, specified at Hyperlinks in terminal emulators. Currently (as of 2019), they are displayed only in gnome-terminal version 3.26 or above. More terminal emulators will support hyperlinks in the future. Terminal emulators which don’t support hyperlinks ignore it, except for a few terminal emulators, for which users may need to disable the hyperlinks (see The NO_TERM_HYPERLINKS variable) if the heuristic built into libtextstyle does not already disable them.

To emit a hyperlink, use code like this:

  styled_ostream_t stream = ...
  ...
  /* Start a hyperlink.  */
  styled_ostream_set_hyperlink (stream, url, NULL);
  ...
  /* Emit the anchor text.  This can be styled text.  */
  ostream_write_str (stream, "Click here!");
  ...
  /* End the current hyperlink.  */
  styled_ostream_set_hyperlink (stream, NULL, NULL);

The anchor text can be styled. But the hyperlinks themselves cannot be styled; they behave as implemented by the terminal emulator.