box-o-sand/PracticingCurses/basics/init_func_example.py

34 lines
682 B
Python
Raw Normal View History

import sys
import curses
def main():
curses.wrapper(init_func_example)
return 0
def init_func_example(stdscr):
curses.raw()
stdscr.keypad(1)
curses.noecho()
stdscr.addstr(0, 0, "Type any character to see it in bold\n")
ch = stdscr.getch()
if ch == curses.KEY_F1:
stdscr.addstr(1, 0, "F1 Key pressed")
else:
key_pressed = "The pressed key is "
stdscr.addstr(1, 0, key_pressed)
stdscr.attron(curses.A_BOLD)
stdscr.addstr(1, len(key_pressed), chr(ch))
stdscr.attroff(curses.A_BOLD)
stdscr.refresh()
stdscr.getch()
if __name__ == '__main__':
sys.exit(main())
# vim:filetype=python