Last active
November 24, 2017 06:13
-
-
Save amjith/9c50bf5d28f998bc5049ae573dbab375 to your computer and use it in GitHub Desktop.
Template for creating awesome REPLs with prompt-toolkit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from prompt_toolkit import prompt | |
from prompt_toolkit.history import FileHistory | |
from prompt_toolkit.contrib.completers import WordCompleter | |
from pygments.lexers.sql import SqlLexer | |
import sqlite3 | |
history = FileHistory('history.txt') | |
completer = WordCompleter(['select', 'insert', 'delete', 'drop', 'from']) | |
connection = sqlite3.connect(':memory:') | |
while 1: | |
try: | |
inp = prompt('prompt> ', history=history, lexer=SqlLexer, completer=completer) | |
with connection: | |
print (connection.execute(inp).fetchall()) | |
except EOFError: | |
print ('Good bye!') | |
exit(0) | |
except Exception as e: | |
print (str(e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment