diff options
-rw-r--r-- | presentty/text.py | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/presentty/text.py b/presentty/text.py index e0a88fc..92c0a26 100644 --- a/presentty/text.py +++ b/presentty/text.py | |||
@@ -29,15 +29,24 @@ class FigletText(urwid.WidgetWrap): | |||
29 | super(FigletText, self).__init__(widget) | 29 | super(FigletText, self).__init__(widget) |
30 | 30 | ||
31 | def _run(self): | 31 | def _run(self): |
32 | p = subprocess.Popen(['figlet'], | 32 | try: |
33 | stdin=subprocess.PIPE, | 33 | p = subprocess.Popen(['figlet'], |
34 | stdout=subprocess.PIPE, | 34 | stdin=subprocess.PIPE, |
35 | stderr=subprocess.PIPE) | 35 | stdout=subprocess.PIPE, |
36 | p.stdin.write(self.text) | 36 | stderr=subprocess.PIPE) |
37 | p.stdin.close() | 37 | except OSError, e: |
38 | data = p.stdout.read() | 38 | if e.errno == 2: |
39 | p.stderr.read() | 39 | print("ERROR: figlet is used but is not installed.") |
40 | p.wait() | 40 | else: |
41 | print("ERROR: unable to run figlet: %s" % e) | ||
42 | raw_input("Press ENTER to continue.") | ||
43 | data = "[Unable to run figlet]" | ||
44 | else: | ||
45 | p.stdin.write(self.text) | ||
46 | p.stdin.close() | ||
47 | data = p.stdout.read() | ||
48 | p.stderr.read() | ||
49 | p.wait() | ||
41 | return data | 50 | return data |
42 | 51 | ||
43 | class CowsayText(urwid.WidgetWrap): | 52 | class CowsayText(urwid.WidgetWrap): |
@@ -52,15 +61,24 @@ class CowsayText(urwid.WidgetWrap): | |||
52 | super(CowsayText, self).__init__(widget) | 61 | super(CowsayText, self).__init__(widget) |
53 | 62 | ||
54 | def _run(self): | 63 | def _run(self): |
55 | p = subprocess.Popen(['cowsay'], | 64 | try: |
56 | stdin=subprocess.PIPE, | 65 | p = subprocess.Popen(['cowsay'], |
57 | stdout=subprocess.PIPE, | 66 | stdin=subprocess.PIPE, |
58 | stderr=subprocess.PIPE) | 67 | stdout=subprocess.PIPE, |
59 | p.stdin.write(self.text) | 68 | stderr=subprocess.PIPE) |
60 | p.stdin.close() | 69 | except OSError, e: |
61 | data = p.stdout.read() | 70 | if e.errno == 2: |
62 | p.stderr.read() | 71 | print("ERROR: cowsay is used but is not installed.") |
63 | p.wait() | 72 | else: |
73 | print("ERROR: unable to run cowsay: %s" % e) | ||
74 | raw_input("Press ENTER to continue.") | ||
75 | data = "[Unable to run cowsay]" | ||
76 | else: | ||
77 | p.stdin.write(self.text) | ||
78 | p.stdin.close() | ||
79 | data = p.stdout.read() | ||
80 | p.stderr.read() | ||
81 | p.wait() | ||
64 | return data | 82 | return data |
65 | 83 | ||
66 | def main(): | 84 | def main(): |