summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCalvin Morrison <mutantturkey@gmail.com>2013-07-22 19:29:38 -0400
committerCalvin Morrison <mutantturkey@gmail.com>2013-07-22 19:29:38 -0400
commite4ecc40711e80ddfa14ea1ffb2704a46bb8acdd4 (patch)
tree3afb2a921afe8c73554dc99c3245d2326b1ada45
parent6bb50e1ce5972fb71bbe5c3e6cf3bc897547cc37 (diff)
throw an exception for argv[1] and give it a shebang as well as generalize the sed call
-rwxr-xr-x[-rw-r--r--]pc.py (renamed from rtsed.py)18
1 files changed, 12 insertions, 6 deletions
diff --git a/rtsed.py b/pc.py
index af17b2b..35da4fb 100644..100755
--- a/rtsed.py
+++ b/pc.py
@@ -1,3 +1,4 @@
+#!/usr/bin/python
import curses
import os
import sys
@@ -23,7 +24,7 @@ input_buffer = ""
cols = int(subprocess.check_output(["tput", "cols"]))
rows = int(subprocess.check_output(["tput", "lines"]))
-def call_sed(string):
+def call_process(process, string):
process = Popen(["sed", "-e", string], stdout=PIPE, stdin=PIPE, stderr=PIPE)
ret = process.communicate(input_buffer)
if(process.returncode is not 0):
@@ -33,13 +34,18 @@ def call_sed(string):
return
-def main():
+def main(argv):
input_string = ""
global input_buffer
- for line in open(sys.argv[1], "r"):
- input_buffer = input_buffer + line
+ try:
+ input_fh = open(argv[1], "r")
+ for line in input_fh:
+ input_buffer = input_buffer + line
+ except:
+ curses.endwin()
+ sys.exit("please specify a file")
# init our screen
screen.addstr("".ljust(cols), curses.color_pair(1));
@@ -60,7 +66,7 @@ def main():
continue;
elif(key == 13 or key == 10):
screen.addstr(input_string.ljust(cols), curses.color_pair(1));
- call_sed(input_string)
+ call_process("sed", input_string)
screen.addstr("EOF")
continue;
else:
@@ -72,5 +78,5 @@ def main():
curses.endwin()
if __name__ == "__main__":
- sys.exit(main())
+ sys.exit(main(sys.argv))