From 6eb92f9817a3a9a7a4ad856bd0157fd5d08022eb Mon Sep 17 00:00:00 2001 From: Po-Han Sung Date: Wed, 9 Apr 2014 18:39:09 +0800 Subject: [PATCH] Use library readline to handle input Library readline provides several functions that make typing words easier. Besides basic shortcut keys for editing words, this commit also utilizes the history feature. --- ydict | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ydict b/ydict index 18495f4..3e2fca8 100755 --- a/ydict +++ b/ydict @@ -16,6 +16,8 @@ import random import ConfigParser from multiprocessing import Process, Queue, Pool import xml.etree.ElementTree as ET +import readline +import atexit version="ydict 1.3.4" @@ -382,7 +384,13 @@ if __name__ == '__main__': elif options.listall: wordlist() cleanup() - + + histfile = os.path.join(os.path.expanduser("~"), ".ydict_hist") + try: + readline.read_history_file(histfile) + except IOError: + pass + atexit.register(readline.write_history_file, histfile) while(1): try: word=raw_input(" ")