Simple Python CLI


# see https://pythonconquerstheuniverse.wordpress.com/2011/11/06/posting-sourcecode-on-wordpress/

# -*- coding: utf-8 -*-
from jsnippets import snippets

CUR_SNIP_IX = 0; CUR_SNIP_KEY = list(snippets.keys())[CUR_SNIP_IX]
def main():
    while True:
        cmd = (input ('?> ')).lower()
        if cmd == 'exit': break
        elif cmd == 'print': printCurrentSnippet()
        elif cmd == 'printa': printAllSnippets()
        elif cmd == 'next': bumpCUR_SNIP_IX()
        elif cmd == 'zero': zeroOutCUR_SNIP_IX()
def zeroOutCUR_SNIP_IX():
    global CUR_SNIP_IX, CUR_SNIP_KEY
    CUR_SNIP_IX = 0; CUR_SNIP_KEY = list(snippets.keys())[CUR_SNIP_IX]
def bumpCUR_SNIP_IX():
    global CUR_SNIP_IX, CUR_SNIP_KEY
    CUR_SNIP_IX = ( (CUR_SNIP_IX + 1)%(len(snippets.keys())) );
    CUR_SNIP_KEY = list(snippets.keys())[CUR_SNIP_IX]
def printCurrentSnippet():
    print(snippets[CUR_SNIP_KEY])
    def printAllSnippets():
    print(snippets)

if __name__ == '__main__':
    main()