module for add function in terminal


License
Other
Install
pip install myterm==0.3.0

Documentation

Module myterm

Installation

pip install myterm

Or

git clone https://github.com/fraoustin/myterm.git
cd myterm
python setup.py install

Usage

If you want add color in python command, add you pythonstartup env

import myterm.startup

Or

export PYTHONSTARTUP=/usr/local/lib/python2.7/dist-packages/myterm/startup.py

If you want color in console program

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import logging
import logging.handlers
import myterm

VERSION="0.1"
PROG="test1"
DESCRIPTION="""test of myterm.StreamHandler"""
AUTHOR="Author"

if __name__ == '__main__':
    usage = "usage: %prog [options]"
    parser = myterm.OptionParser(version="%s %s" % (PROG,VERSION), usage=usage)
    parser.description= DESCRIPTION
    parser.epilog = AUTHOR
    try:
        (options, args) = parser.parse_args()
        # create logger
        logger = logging.getLogger("simple_example")
        logger.setLevel(logging.DEBUG)
        # create console handler and set level to debug
        ch = myterm.StreamHandler()
        ch.setLevel(logging.DEBUG)
        # create formatter
        formatter = logging.Formatter("%(icon)s %(asctime)s - %(name)s - %(levelname)s - %(message)s")
        # add formatter to ch
        ch.setFormatter(formatter)
        # add ch to logger
        logger.addHandler(ch)

        # "application" code
        logger.debug("debug message")
        logger.info("info message")
        logger.warn("warn message")
        logger.error("error message")
        logger.critical("critical message")

    except Exception as e:
        parser.error(e)
        sys.exit(1)