summaryrefslogtreecommitdiff
path: root/pc.py
diff options
context:
space:
mode:
authorCalvin Morrison <calvin@fastmailteam.com>2021-05-18 11:30:22 -0400
committerCalvin Morrison <calvin@fastmailteam.com>2021-05-18 11:30:22 -0400
commit0415232d9fd9f434f0a7bd732ee0cac6063de772 (patch)
tree3b4f3edc6681016deda0adf2667cf91928d1a3dd /pc.py
parentec696b68adca7ec6fe098cf709e2e5e51427d1ac (diff)
curses sucks so catch all the errors it throws. program still worksHEADmaster
Diffstat (limited to 'pc.py')
-rwxr-xr-xpc.py35
1 files changed, 24 insertions, 11 deletions
diff --git a/pc.py b/pc.py
index e9c975e..d988e7e 100755
--- a/pc.py
+++ b/pc.py
@@ -34,6 +34,13 @@ input_buffer = ""
cols = int(subprocess.check_output(["tput", "cols"]))
rows = int(subprocess.check_output(["tput", "lines"]))
+# curses sucks
+def add(screen,*args):
+ try:
+ screen.addstr(args)
+ except:
+ pass
+
def call_process(process, pipe, stdin):
process = Popen(["sed", pipe], stdout=PIPE, stdin=PIPE, stderr=PIPE)
ret = process.communicate(stdin)
@@ -50,10 +57,10 @@ def call_pipes(a, pipe_array):
if(len(pipe_array) == 1):
if(ret[1] != 0):
- error = "Error on line 0:" + ret[0][:-1]
- screen.addstr(error.ljust(cols), curses.color_pair(4));
+ error = "Error on line 0:" + ret[0][:-1];
+ add(screen,error.ljust(cols), curses.color_pair(4));
else:
- screen.addstr(ret[0])
+ add(screen,ret[0])
return
p = ret[0];
@@ -61,16 +68,19 @@ def call_pipes(a, pipe_array):
ret = call_process("sed", pipe_array[i], p);
if(ret[1] != 0):
error = "Error on line " + str(i) + ":" + ret[0][:-1]
- screen.addstr(error.ljust(cols), curses.color_pair(4));
+ add(screen, error.ljust(cols), curses.color_pair(4));
else:
p = ret[0];
- screen.addstr(p)
+ try:
+ add(screen,p)
+ except:
+ pass
def update(pipe_array, current_pipe):
draw_pipes(pipe_array, current_pipe)
call_pipes("sed", pipe_array)
- screen.addstr("EOF")
+ add(screen,"EOF")
def draw_pipes(pipe_array, current_pipe):
@@ -79,8 +89,8 @@ def draw_pipes(pipe_array, current_pipe):
if(num == current_pipe):
color = 3
- screen.addstr(num, 0, str(num), curses.color_pair(2))
- screen.addstr(num, len(str(num)), " " + pipe.ljust(cols - len(str(num)) - 1), curses.color_pair(color))
+ add(screen, num, 0, str(num), curses.color_pair(2))
+ add(screen, num, len(str(num)), " " + pipe.ljust(cols - len(str(num)) - 1), curses.color_pair(color))
def main(argv):
@@ -105,9 +115,12 @@ def main(argv):
sys.exit("please specify a file")
# init our screen
- screen.addstr("".ljust(cols), curses.color_pair(1));
- screen.addstr(input_buffer)
- screen.addstr("EOF")
+ try:
+ screen.addstr("".ljust(cols), curses.color_pair(1));
+ screen.addstr(input_buffer)
+ screen.addstr("EOF")
+ except:
+ pass
screen.addstr(rows - 1, 0, argv[1] + " " + str(key) + " " + str(current_pipe))
try: