xtext is available in the AUR
Pango
Cairo
X
gcc -o xtext $(pkg-config --cflags --libs cairo pango x11 xfixes) xtext.c
or just make && make install
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
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.
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/
anim 'fade' | fade | xtext 0 0
anim 'transition' | transition -d -10 | xtext 0 0
anim 'fade & transition' | fade | transition -d -10 | xtext 0 0
anim 'waving' | wave | xtext 0 0
anim 'rainbow' | rainbow | xtext 0 0
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.