Coadlib is a python library for develop console application.
Co nsole A pplication D evelopment Library
The base application class.
Supported encoding, IO, etc.
name
- application namedesc
- applicationi descriptionversion
- application versionpadding
- the width size from left side of terminal window to string area.margin
- the height size from top side of terminal window to string area.encoding
- application encoding. by default, the program decides encoding by your platform.
write(msg)
- print message too stream with new line.write_error(msg)
- print error message to stream with new line.write_usage()
- generate usage message from application name, version, description, and print it.exit(status)
- exit application with status code.
Inherited the application class, added new methods to input message from user.
The Application
class params:
- name
- desc
- version
- padding
- margin
new param:
suffix
- the suffix letter placed after an input string.
input_console(msg, valuetype, validate=True)
- display input console with suffix, supported validate.
The InteractiveLoopApplication provides a decorator for looping to function.
Parameters are same of InteractiveApplication class.
loop
- The decorator
- app. STATUS__CONTINUE - Continue the loop when returns this var
- app. STATUS__EXIT - Break the loop when returns this var
from coadlib.apps import InteractiveLoopApplication
app = InteractiveLoopApplication(
name="calcuation program",
desc="please input number, and return total.",
version="1.0", padding=4, margin=3, suffix=" > "
)
app.total = 0
@app.loop
def main():
response = app.input_console("number", int, validate=False)
if response == "":
app.write("total: {:,}".format(app.total))
return app.STATUS_EXIT
else:
try:
app.total += int(response)
return app.STATUS_CONTINUE
except:
app.write_error("Error: incorrect data.")
return app.STATUS_CONTINUE
if __name__ == "__main__":
app.write_usage()
main()
- Changed app parametor from 'prefix' to 'suffix' in InteractiveApplication, and InteractiveLoopApplication.
- Compliant with pep8
- Package renamed: 'ConsoleADL' -> 'coadlib'
- Use decorator in InteractiveLoopApplication.
- Wroute README.md
- To more easy import, the applications in app.py.