jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: GNU libtextstyle: 1. Introduction jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68:
[ << ][ >> ]           [Top][Contents][Index][ ? ]
jpayne@68: jpayne@68:
jpayne@68: jpayne@68: jpayne@68:

1. Introduction

jpayne@68: jpayne@68:

Text is easier to read when it is accompanied with styling information, jpayne@68: such as color, font attributes (weight, posture), or underlining, and jpayne@68: this styling is customized appropriately for the output device. jpayne@68:

jpayne@68:

GNU libtextstyle provides an easy way to add styling to programs that jpayne@68: produce output to a console or terminal emulator window. It does this jpayne@68: in a way that allows the end user to customize the styling using the jpayne@68: industry standard, namely Cascading Style Sheets (CSS). jpayne@68:

jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68:

1.1 Style definitions

jpayne@68: jpayne@68:

Let's look at the traditional way styling is done for specific programs. jpayne@68:

jpayne@68:

Browsers, when they render HTML, use CSS styling. jpayne@68:

jpayne@68:

The older approach to user-customizable text styling is that the user jpayne@68: associates patterns with escape sequences in an environment variable or a jpayne@68: command-line argument. This is the approach used, for example, by the jpayne@68: GNU ‘ls’ program in combination with the ‘dircolors’ program. jpayne@68: The processing is distributed across several steps: jpayne@68:

    jpayne@68:
  1. jpayne@68: There is default style definition that is hard-coded in the jpayne@68: ‘dircolors’ program. The user can also define their own definitions jpayne@68: in a file such as ‘~/.dir_colors’. This style definition contains jpayne@68: explicit terminal escape sequences; thus, it can only be used with jpayne@68: consoles and terminal emulators, and each style definition applies only jpayne@68: to a certain class of mostly-compatible terminal emulators. jpayne@68:
  2. jpayne@68: The dircolors program, when invoked, translates such a style jpayne@68: definition to a sequence of shell statements that sets an environment jpayne@68: variable LS_COLORS. jpayne@68:
  3. jpayne@68: The shell executes these statements, and thus sets the environment jpayne@68: variable LS_COLORS. jpayne@68:
  4. jpayne@68: The program looks at the environment variable and emits the listed escape jpayne@68: sequences. jpayne@68:
jpayne@68: jpayne@68:

In contrast, this library implements styling as follows: jpayne@68:

    jpayne@68:
  1. jpayne@68: There is a default style definition in a CSS file that is part of the jpayne@68: same package as the stylable program. The user can also define their own jpayne@68: definitions in a CSS file, and set an environment environment variable to jpayne@68: point to it. jpayne@68:
  2. jpayne@68: The program looks at the environment variable, parses the CSS file, jpayne@68: translates the styling specifications to the form that is appropriate for jpayne@68: the output device (escape sequences for terminal emulators, inline CSS jpayne@68: and <span> elements for HTML output), and emits it. jpayne@68:
jpayne@68: jpayne@68:

Thus, with GNU libtextstyle, the styling has the following properties: jpayne@68:

jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68:

1.2 Built-in versus separate styling

jpayne@68: jpayne@68:

There are generally two approaches for adding styling to text: jpayne@68:

jpayne@68: jpayne@68:

The first approach produces a styling that is 100% correct, regardless of jpayne@68: the complexity of the text that is being output. This is the preferred jpayne@68: approach for example for JSON, XML, or programming language text. jpayne@68:

jpayne@68:

The second approach works well if the output has a simple, easy-to-parse jpayne@68: format. It may produce wrong styling in some cases when the text format jpayne@68: is more complex. This approach is often used for viewing log files. jpayne@68:

jpayne@68:

GNU libtextstyle supports both approaches; it includes an example program jpayne@68: for each of the two approaches. jpayne@68:

jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68: jpayne@68:
[ << ][ >> ]           [Top][Contents][Index][ ? ]
jpayne@68:

jpayne@68: jpayne@68: This document was generated by Bruno Haible on February, 21 2024 using texi2html 1.78a. jpayne@68: jpayne@68:
jpayne@68: jpayne@68:

jpayne@68: jpayne@68: