diff options
Diffstat (limited to 'pc.py')
-rwxr-xr-x | pc.py | 35 |
1 files changed, 24 insertions, 11 deletions
@@ -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: |