from __future__ import print_function
import sys
import curses

FILE = {'fp': None}


def simple_attr(stdscr):
    row, col = stdscr.getmaxyx()
    prev = ''
    fp = FILE['fp']
    for line in fp:
        for ch in line:
            y, x = stdscr.getyx()
            if y == (row - 1):
                stdscr.addstr(row - 1, 0, "<-Press Any Key->")
                stdscr.getch()
                stdscr.clear()
                stdscr.move(0, 0)
            elif prev == '/' and ch == '*':
                stdscr.attron(curses.A_BOLD)
                y, x = stdscr.getyx()
                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[:]):
    if not sysargs[1:]:
        print('Usage: {0} <a c file name>'.format(sysargs[0]))
        return 1
    try:
        FILE['fp'] = open(sysargs[1], 'r')
    except (OSError, IOError):
        print('Cannot open input file', file=sys.stderr)
        return 1
    curses.wrapper(simple_attr)
    return 0


if __name__ == '__main__':
    sys.exit(main())

# vim:filetype=python
