forked from glitchub/fbtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfbtext
executable file
·70 lines (52 loc) · 1.94 KB
/
fbtext
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/python3
"""
Usage:
fbtext [options] [--] ["arbitrary text"]
Write arbitrary text to frame buffer.
Options are:
-b width - screen border width, default is 0 (no border)
-c [fg:]bg - foreground and background colors
-d device - framebuffer device
-f path/to/font - specify font file (should be monospaced)
-m - text margin in pixels, default is 10
-s style - the font style, default is "@c".
If no text is provided then it will be read from stdin.
If specified background color is "transparent" (or specifies a transparent
alpha), then existing framebuffer content will be overlayed.
"""
import os, sys, getopt
try: import screen # works if this executable is in the fbtools directory
except: from fbtools import screen # works if fbtools is installed as a package
border = 0
fg = None
bg = None
device = None
font = None
margin = 10
style = None
try:
opts, args = getopt.getopt(sys.argv[1:],"b:c:d:f:g:m:s:wx")
for opt, arg in opts:
if opt == "-b": border = int(arg)
elif opt == "-c": fg, bg = (i or None for i in ([None]+arg.split(':'))[-2:])
elif opt == "-d": device = arg
elif opt == "-f": font = arg
elif opt == "-m": margin = int(arg)
elif opt == "-s": style = arg
else: raise Exception("Invalid option '%s'" % opt)
except Exception as e:
print (str(e), "\n", __doc__, file = sys.stderr)
quit(1)
if not args or (len(args)==1 and args[0] == "-"):
# no text or legacy "-", read from stdin
text = str(sys.stdin.buffer.read(),"utf8")
else:
# else use command line
text = " ".join(args)
margin += border
# Init the screen
screen = screen.Screen(fbdev=device, fg=fg, bg=bg, font=font, style=style, border=border)
# Add the text
screen.child(left=margin, top=margin, right=-margin, bottom=-margin).text(text).merge()
# Show it
screen.display()