https://github.com/alice1017/coadlib
Console Application Development Library
https://github.com/alice1017/coadlib
Last synced: about 2 months ago
JSON representation
Console Application Development Library
- Host: GitHub
- URL: https://github.com/alice1017/coadlib
- Owner: alice1017
- License: mit
- Created: 2017-04-07T02:34:03.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-05T07:50:43.000Z (almost 7 years ago)
- Last Synced: 2025-02-15T08:26:00.567Z (3 months ago)
- Language: Python
- Homepage:
- Size: 24.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# coadlib - Console Application Development Library
**Coadlib** is a python library for develop console application.
**Co** nsole **A** pplication **D** evelopment **Lib**rary
## Application classes
* [Application](#application)
* [params](#params)
* [main methods](#main-methods)
* [InteractiveApplication](#interactiveapplication)
* [params](#params-1)
* [main methods](#main-methods-1)
* [InteractiveLoopApplication](#interactiveloopapplication)
* [params](#params-2)
* [main methods](#main-methods-2)
* [example](#example)
* [variables](#variables)### Application
**The base application class.**
Supported encoding, IO, etc.
#### params
* `name` - application name
* `desc` - applicationi description
* `version` - application version
* `padding` - 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.#### main methods
* `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.### InteractiveApplication
Inherited the [application](#Application) class, added new methods to **input message from user**.
#### params
The `Application` class params:
* name
* desc
* version
* padding
* marginnew param:
* `suffix` - the **suffix letter** placed after an input string.
#### main methods
* `input_console(msg, valuetype, validate=True)` - display input console with suffix, supported validate.
### InteractiveLoopApplication
The InteractiveLoopApplication provides a **decorator** for **looping to function**.
#### params
Parameters are same of InteractiveApplication class.
#### main methods
* `loop` - The decorator
#### variables
* app. **STATUS__CONTINUE** - Continue the loop when returns this var
* app. **STATUS__EXIT** - Break the loop when returns this var#### example
```py
from coadlib.apps import InteractiveLoopApplicationapp = 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_EXITelse:
try:
app.total += int(response)
return app.STATUS_CONTINUEexcept:
app.write_error("Error: incorrect data.")
return app.STATUS_CONTINUEif __name__ == "__main__":
app.write_usage()
main()
```## CHANGELOG
### version 0.1.2
* Changed app parametor from 'prefix' to 'suffix' in InteractiveApplication, and InteractiveLoopApplication.
* Compliant with pep8### version 0.1.1
* Package renamed: 'ConsoleADL' -> 'coadlib'
* Use decorator in InteractiveLoopApplication.
* Wroute README.md
* To more easy import, the applications in app.py.