用户I/O处理程序
nuio的Python项目详细描述
NUIO试图添加 以及易于使用的python用户输入/输出接口。
目标是提供一组具有print-like操作方法的类 以及其他一些用于markup&co处理用户输入/输出的方法。
功能
目前,nuio能够与posix终端进行eal。 对应的类在nuio.input.terminal和nio.output.terminal中。
哲学
Nuio试图让事情尽可能简单, 但它需要python3.5.1+语言特性。
任何阻塞的用户输入都是使用异步特性完成的,这是 将来会很方便的。
计划
应添加以下功能:
- 基于诅咒的I/O
- 基于ajax的i/o系统
- 非POSIX终端
- blockoutput的花式框架
示例
这是nuio的一个简单示例:
#!/usr/bin/python3 from nuio.input.terminal import POSIXTerminalInput from nuio.output.terminal import TerminalOutput, ESCAPES, TerminalBlockOutput import asyncio, shutil async def main(): width, height = shutil.get_terminal_size() # an output device out = TerminalBlockOutput(height - 10, width) out.print("This is a test") # input devices require an output device to handle prompts. inp = POSIXTerminalInput(out) data = await inp.input_int(prompt = "enter an integer > ") # You are able to use a bunch of ANSI escape sequences. # Usually you should use nuio.output.terminal.colors instead, # this will be compatible with other output devices. out.print_colored(ESCAPES["underline"], "you entered:", data) data = await inp.input_int(prompt = "enter an integer [4-100] > ", range = range(4, 100)) out.print_colored(ESCAPES["fg_red"], "you entered:", data) data = await inp.input_float(prompt = "enter an float [4-100] > ", range = range(4, 100)) out.print_colored(ESCAPES["bg_cyan"] + ESCAPES["fg_black"], "you entered:", data) # Usually you should make the input async, # but to simplify this the complete main function is async. loop = asyncio.get_event_loop() loop.run_until_complete(main()) loop.close()