#!/usr/bin/python import conz cn = conz.Console() choices = ( ('FO', 'Foo'), ('BA', 'Bar'), ('BZ', 'Baz'), ('FA', 'Fam'), ) show = lambda v: cn.pstd('Got value {}'.format(val)) # Simple default usage val = cn.menu(choices) show(val) # Custom prompt and intro val = cn.menu(choices, prompt='Tells us what you want [1-4]: ', intro='Once upon a time, there was a menu.') show(val) # Custom numbering numerator = lambda n: ['abcd'[i] for i in range(n)] clean = lambda x: x.strip() val = cn.menu(choices, numerator=numerator, clean=clean) show(val) # Custom formatter
#!/usr/bin/python import conz someval = True cn = conz.Console(verbose=True) cn.pstd('This goes to STDOUT') cn.perr('This goes to STDERR') cn.pverr(someval, 'This message is related to somevar') cn.pstd(cn.color.green('This message is green')) with cn.progress('Some long operation'): import time time.sleep(2) data = cn.read('Type something in:') cn.pstd('You typed in {}'.format(cn.color.yellow(data, style='italic')))