Glk Text Formatting by Dannii Willis


Glk Text Formatting allows you to control text colours and reverse mode at character granularity. Instead of only having one colour per style, you can now manually specify colours for each paragraph, sentence, word, or even single character.

Glk Text Formatting uses non-standard Glk functions specified at <https://curiousdannii.github.io/if/gargoyle.html>. At present, they are supported only in Windows Glulxe/Git. Gargoyle will support these functions in its next release.

It is strongly recommended that you test whether these functions are supported before using them. If you do not your interpreter may raise a fatal error.

if glk text formatting is supported:
     say "[reverse mode on]Reversed![reverse mode off]";

Phrases are provided to set the foreground and background colours, as well as turning on and off reverse mode. Colours are specified as CSS colours (just as you would with Glulxe Text Effects).

set color/colour "#FF0000";
set background/bg color/colour: "#0000FF";
reset the foreground/fg color/colour;
reset the background/bg color/colour;
set reverse mode on;
set reverse mode off;
say reverse mode on;
say reverse mode off;

The latest version of this extension can be found at <https://github.com/i7/extensions>. This extension is released under the Creative Commons Attribution licence. Bug reports, feature requests or questions can be made at <https://github.com/i7/extensions/issues>.

Example: * Rainbow and space invader

"Rainbow and space invader"

Include Version 1 of Glk Text Formatting by Dannii Willis.

The Show Case is a room. "This is the show case for Glk Text Formatting.

[if glk text formatting is supported]Here is a pretty rainbow:

[rainbow]

And here is a space invader:

[space invader][otherwise]Your interpreter does not support Glk text formatting.[end if]".

To say rainbow:
     let the rainbow colours be { "#ff0000", "#ff3000", "#ff6000", "#ff9000", "#ffc000", "#fff000", "#deff00", "#aeff00", "#7eff00", "#4eff00", "#1eff00", "#00ff12", "#00ff42", "#00ff72", "#00ffa2", "#00ffd2", "#00fcff", "#00ccff", "#009cff", "#006cff", "#003cff", "#000cff", "#2400ff", "#5400ff", "#8400ff", "#b400ff", "#e400ff", "#ff00ea", "#ff00ba", "#ff008a", "#ff005a", "#ff002a" };
     say "[fixed letter spacing][reverse mode on]";
     repeat with C running through the rainbow colours:
         set color C;
         say " ";
     reset fg color;
     say "[reverse mode off][variable letter spacing]";

To say space invader:
     say "[fixed letter spacing] [reverse on] [reverse off] [reverse on] [reverse off] [line break] [reverse on] [reverse off] [reverse on] [reverse off] [line break] [reverse on] [reverse off] [line break] [reverse on] [reverse off] [reverse on] [reverse off] [reverse on] [reverse off] [line break][reverse on] [reverse off] [line break][reverse on] [reverse off] [reverse on] [reverse off] [reverse on] [reverse off] [line break][reverse on] [reverse off] [reverse on] [reverse off] [reverse on] [reverse off] [reverse on] [reverse off] [line break] [reverse on] [reverse off] [reverse on] [reverse off] [line break][variable letter spacing]".