summaryrefslogtreecommitdiff
path: root/presentty/text.py
diff options
context:
space:
mode:
Diffstat (limited to 'presentty/text.py')
-rw-r--r--presentty/text.py81
1 files changed, 81 insertions, 0 deletions
diff --git a/presentty/text.py b/presentty/text.py
new file mode 100644
index 0000000..e0a88fc
--- /dev/null
+++ b/presentty/text.py
@@ -0,0 +1,81 @@
1# Copyright (C) 2015 James E. Blair <corvus@gnu.org>
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16import subprocess
17
18import urwid
19
20class FigletText(urwid.WidgetWrap):
21 def __init__(self, text, attr=None):
22 self.text = text
23 self.attr = attr
24 output = self._run()
25 if attr:
26 widget = urwid.Text((attr, output), wrap='clip')
27 else:
28 widget = urwid.Text(output, wrap='clip')
29 super(FigletText, self).__init__(widget)
30
31 def _run(self):
32 p = subprocess.Popen(['figlet'],
33 stdin=subprocess.PIPE,
34 stdout=subprocess.PIPE,
35 stderr=subprocess.PIPE)
36 p.stdin.write(self.text)
37 p.stdin.close()
38 data = p.stdout.read()
39 p.stderr.read()
40 p.wait()
41 return data
42
43class CowsayText(urwid.WidgetWrap):
44 def __init__(self, text, attr=None):
45 self.text = text
46 self.attr = attr
47 output = self._run()
48 if attr:
49 widget = urwid.Text((attr, output), wrap='clip')
50 else:
51 widget = urwid.Text(output, wrap='clip')
52 super(CowsayText, self).__init__(widget)
53
54 def _run(self):
55 p = subprocess.Popen(['cowsay'],
56 stdin=subprocess.PIPE,
57 stdout=subprocess.PIPE,
58 stderr=subprocess.PIPE)
59 p.stdin.write(self.text)
60 p.stdin.close()
61 data = p.stdout.read()
62 p.stderr.read()
63 p.wait()
64 return data
65
66def main():
67 import slide
68 w = FigletText("Testing")
69 slpile = slide.SlidePile([])
70 slpile.contents.append((w, slpile.options()))
71 pad = slide.SlidePadding(slpile, align='center', width='pack')
72 fill = slide.SlideFiller(pad)
73 #w.render((80,25))
74 fill.render((80,25))
75 screen = urwid.raw_display.Screen()
76 if True:
77 with screen.start():
78 screen.draw_screen((80,25), fill.render((80,25)))
79 raw_input()
80if __name__=='__main__':
81 main()