iterating over each char in the file in a more pythonic way, though still not happy with retaining all of the branches from the C version

cat-town
Dan Buch 15 years ago
parent 2cb096e27e
commit 996ade6414

@ -8,25 +8,27 @@ FILE = {'fp': None}
def simple_attr(stdscr): def simple_attr(stdscr):
row, col = stdscr.getmaxyx() row, col = stdscr.getmaxyx()
prev = '' prev = ''
for ch in FILE['fp'].read(): fp = FILE['fp']
y, x = stdscr.getyx() for line in fp:
if y == (row - 1): for ch in line:
stdscr.addstr(row - 1, 0, "<-Press Any Key->")
stdscr.getch()
stdscr.clear()
stdscr.move(0, 0)
if prev == '/' and ch == '*':
stdscr.attron(curses.A_BOLD)
y, x = stdscr.getyx() y, x = stdscr.getyx()
stdscr.addstr(y, x - 1, '/{0}'.format(ch)) if y == (row - 1):
else: stdscr.addstr(row - 1, 0, "<-Press Any Key->")
stdscr.addstr(y, x, ch) stdscr.getch()
stdscr.refresh() stdscr.clear()
stdscr.move(0, 0)
if prev == '*' and ch == '/': elif prev == '/' and ch == '*':
stdscr.attroff(curses.A_BOLD) stdscr.attron(curses.A_BOLD)
y, x = stdscr.getyx()
prev = ch stdscr.addstr(y, x - 1, '/{0}'.format(ch))
else:
stdscr.addstr(y, x, ch)
stdscr.refresh()
if prev == '*' and ch == '/':
stdscr.attroff(curses.A_BOLD)
prev = ch
def main(sysargs=sys.argv[:]): def main(sysargs=sys.argv[:]):

Loading…
Cancel
Save