resloved / xtext

📝 — Display Text w/ X11
MIT License
8 stars 2 forks source link

xtext

Install

Arch/Manjaro

xtext is available in the AUR

Build

Dependencies

Compile

gcc -o xtext $(pkg-config --cflags --libs cairo pango x11 xfixes) xtext.c

or just make && make install

Usage

Pipe text into xtext and give it the coordinates of where to display:

input | xtext x y alignment

Alignment is an optional arguement with the following options (By default xtext uses left-alignment):

Input Alignment
0 Left
1 Right
2 Center

Standard xtext structure:

(echo "Hello World!"; cat) | xtext 0 0

xtext is able to handle streams of text, allowing you to update what it displays:

while true; do echo $(date +%M:%S); sleep 1; done | xtext 0 0

Formatting

xtext also takes advantage of Pango, a library for rendering and organizing text. Pango comes with its own markup language allowing us to add attributes to the displayed text.

(echo "<span color='red'>Hello World!</span>"; cat) | xtext 0 0

The Gnome Developer docs have a page dedicated to all the different Pango markup attributes. Changing the attributes becomes very powerful when paired with an updating stream of text. You can make some really interesting UI elements by changing how the text is displayed on the fly.

Take a look at the examples/ if want to find a place to start.

Animation

To animate text I use the following structure:

anim 'example' | effect | xtext 0 0

The helper anim prints a given string 60 times a second. While this isn't necessary for animation, it's useful for updating a static string at a consistent rate.

Each effect reads in from STDIN, updates the given line in some way (often using a span) and then prints the new line. This can be accomplished in python using:

for line in sys.stdin:
      # Update line somehow...
      print(line.strip(), flush=True)

All of the following effects can be found in examples/animation/

Fade

anim 'fade' | fade | xtext 0 0

Transition

anim 'transition' | transition -d -10 | xtext 0 0

Combine

anim 'fade &amp; transition' | fade | transition -d -10 | xtext 0 0

Wave

anim 'waving' | wave | xtext 0 0

Rainbow

anim 'rainbow' | rainbow | xtext 0 0

Resources

X documentation contain some very murky waters. Thankfully there were a couple hidden gems out there and I would have been completely lost without them.

C

Xlib/X11

Cairo

Pango