Code Monkey home page Code Monkey logo

coadlib's Introduction

coadlib - Console Application Development Library

Coadlib is a python library for develop console application.

Co nsole A pplication D evelopment Library

Application classes

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 class, added new methods to input message from user.

params

The Application class params:

  • name
  • desc
  • version
  • padding
  • margin

new 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

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()

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.

coadlib's People

Contributors

alice1017 avatar

Watchers

 avatar  avatar

coadlib's Issues

change pkg name

origin: Console-Application-Development-Library

choice:

  • new: c-a-dev-l -> cadevl
  • new: c-a-d-lib -> cadlib
  • new: c-a-de-lib -> cadelib
  • new: co-a-d-l -> coadl
  • new: co-a-d-lib -> coadlib

new pkg name: coadlib

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.