summaryrefslogtreecommitdiffstats
path: root/presentty/text.py
diff options
context:
space:
mode:
authorJames E. Blair <corvus@gnu.org>2014-12-20 07:35:13 -0800
committerJames E. Blair <corvus@gnu.org>2015-01-09 10:39:14 -0800
commitef9fb76de9ef299fbdc8f87f1dd05bdd1eda649e (patch)
treedc85b1dfb180f427b3686e59d6b7a8254397c1e2 /presentty/text.py
downloadpresentty-ef9fb76de9ef299fbdc8f87f1dd05bdd1eda649e.tar.gz
presentty-ef9fb76de9ef299fbdc8f87f1dd05bdd1eda649e.tar.xz
presentty-ef9fb76de9ef299fbdc8f87f1dd05bdd1eda649e.zip
Initial commit
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 @@
+# Copyright (C) 2015 James E. Blair <corvus@gnu.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import subprocess
+
+import urwid
+
+class FigletText(urwid.WidgetWrap):
+ def __init__(self, text, attr=None):
+ self.text = text
+ self.attr = attr
+ output = self._run()
+ if attr:
+ widget = urwid.Text((attr, output), wrap='clip')
+ else:
+ widget = urwid.Text(output, wrap='clip')
+ super(FigletText, self).__init__(widget)
+
+ def _run(self):
+ p = subprocess.Popen(['figlet'],
+ stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ p.stdin.write(self.text)
+ p.stdin.close()
+ data = p.stdout.read()
+ p.stderr.read()
+ p.wait()
+ return data
+
+class CowsayText(urwid.WidgetWrap):
+ def __init__(self, text, attr=None):
+ self.text = text
+ self.attr = attr
+ output = self._run()
+ if attr:
+ widget = urwid.Text((attr, output), wrap='clip')
+ else:
+ widget = urwid.Text(output, wrap='clip')
+ super(CowsayText, self).__init__(widget)
+
+ def _run(self):
+ p = subprocess.Popen(['cowsay'],
+ stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ p.stdin.write(self.text)
+ p.stdin.close()
+ data = p.stdout.read()
+ p.stderr.read()
+ p.wait()
+ return data
+
+def main():
+ import slide
+ w = FigletText("Testing")
+ slpile = slide.SlidePile([])
+ slpile.contents.append((w, slpile.options()))
+ pad = slide.SlidePadding(slpile, align='center', width='pack')
+ fill = slide.SlideFiller(pad)
+ #w.render((80,25))
+ fill.render((80,25))
+ screen = urwid.raw_display.Screen()
+ if True:
+ with screen.start():
+ screen.draw_screen((80,25), fill.render((80,25)))
+ raw_input()
+if __name__=='__main__':
+ main()