diff --git a/bin/COMPILE b/bin/COMPILE index 6f3dedc..eef64f2 100755 --- a/bin/COMPILE +++ b/bin/COMPILE @@ -264,7 +264,7 @@ start_time=`date +%s` MODULE_LIST="cpp ite cppite" # 检查编译器版本 -check_gcc_gpp_version +# check_gcc_gpp_version # 向上递归目录查找编译配置文件, 向上搜索优先于 向下探测 和 环境配置(如果已经在模块目录下则不用去探测和环境中找) OLD_DIR=`pwd` diff --git a/src/main.py b/src/main.py index 760d5f7..ea85ca1 100755 --- a/src/main.py +++ b/src/main.py @@ -2,7 +2,13 @@ # -*- coding:utf-8 -*- tab:4 import os import sys -import readline +try: + import readline +except ImportError,e: + print "No readline module installed. {e}".format( e = e ) +else: + import atexit + #import rlcompleter from py import settings as sst from py import utils from py.cppite import CppIte @@ -12,9 +18,17 @@ def main(argc, argv ): os.chdir( BASE_DIR ) print "\t{cs}Hello world! c++ Interactive Test Environment{ce}".format( cs=sst.color.FG_BLUE, ce=sst.color.END ) try: + histfile = os.path.join(os.path.expanduser("~"), ".his_cppite") + try: + readline.read_history_file( histfile ) + except IOError: + pass + atexit.register(readline.write_history_file, histfile) readline.parse_and_bind("tab: complete") readline.parse_and_bind("set editing-mode emacs") ite = CppIte() + readline.set_completer( ite.completer ) + readline.set_completer_delims(" ") cmd_idx = 0 code_idx = 0 ri = utils.get_raw_input(sst.root_tip, code_idx) @@ -25,8 +39,11 @@ def main(argc, argv ): else: code_idx += 1 ri = utils.get_raw_input( sst.root_tip, code_idx ) - #except Exception,e: - except IndexError,e: - print e + del histfile + except KeyboardInterrupt,e: + pass + except EOFError,e: + pass + if __name__ == "__main__": main( len(sys.argv), sys.argv ) diff --git a/src/py/CMakeLists_tmpl.py b/src/py/CMakeLists_tmpl.py index 4720523..b07a3ee 100644 --- a/src/py/CMakeLists_tmpl.py +++ b/src/py/CMakeLists_tmpl.py @@ -7,11 +7,8 @@ SET(EXECUTABLE_OUTPUT_PATH ${{CMAKE_SOURCE_DIR}}/../../bin/ ) SET(CMAKE_USE_RELATIVE_PATHS true ) -FIND_PACKAGE(glib REQUIRED) - INCLUDE_DIRECTORIES( "/usr/include/" - ${{GLIB_INCLUDE_DIR}} {add_include_dirs} ) @@ -23,7 +20,6 @@ ) SET(EXTRA_LIBS - glib-2.0 ${{EXTRA_LIBS}} {add_static_libs} ) diff --git a/src/py/cppite.py b/src/py/cppite.py index 0fb74ad..2e94aee 100644 --- a/src/py/cppite.py +++ b/src/py/cppite.py @@ -26,13 +26,16 @@ def __init__(self): # command full name and its shortkeys self.ite_cmd_keymap={ + 'HELP': ("H", "HEL", ), + 'QUIT': ("Q", ), + 'EXIT': ("E", ), + 'BYE': ("B", ), 'RUN': ("R", "RU"), 'COMPILE': ("C", "CO", "COM", "COMP"), 'VERBOSE': ("V", "VE", "VERB"), 'SIMPLE': ("S", "SI", "SIM"), 'CLEAR': ("CL", "CLE", ), 'SHOW': ("SH", "SHO", ), - 'HELP': ("H", "HEL", ), 'RELOAD_SETTING': ('RS', 'REST'), 'CMD_CLEAR': ("CCL", "CCLE", ), 'CMD_HISTORY': ("CH", "CHIS", ), @@ -46,8 +49,10 @@ def __init__(self): 'LIST_STATIC_FILE': ('LSF', ), 'RM_STATIC_FILE': ('RSF', "REMOVE_STATIC_FILE"), 'LOAD_FRAG_FILE': ('LFF', 'LDFF'), - } + self.commands = self.ite_cmd_keymap.keys() + self.short_cmds = [] + [ self.short_cmds.extend(list(c)) for c in self.ite_cmd_keymap.values() if isinstance(c, (list,tuple)) and len(c)>0 ] def is_ite_cmd(self, ri): @@ -117,6 +122,19 @@ def cmd_help(self, name=None): else: print "{c}Not surpported command:{n}{e}".format( n=name, c=st.color.FG_RED, e=st.color.END ) + + def cmd_quit(self): + """Exit cppite""" + exit(0) + + def cmd_exit(self): + """Alias of quit""" + self.cmd_quit() + + def cmd_bye(self): + """Alias of quit""" + self.cmd_quit() + def cmd_reload_setting(self): """Reload the settings.py""" @@ -358,3 +376,34 @@ def exec_bash_cmd(self, cmd): elif self.is_verbose: print "{c}{out}{e}".format( c=st.color.FG_GREEN, out=output, e=st.color.END ) return status, output + + def completer(self, text, state): + if text.strip().startswith("#//"): + tmp_text = text.strip().strip("#//") + commands = self.commands #+ self.short_cmds + commands.sort() + options = [ "#//{c}".format(c=c) for c in commands if c.startswith( tmp_text.upper() )] + if state < len(options): + return options[state] + else: + return None + elif text.strip().startswith("#") or text.strip().startswith("#/"): + options = ["#//" ] + if state < len(options): + return options[state] + else: + return None + elif len(text.strip()) == 0: + options = ["#"] + if state < len(options): + return options[state] + else: + return None + else: + tmp_text = text.strip().lower() + codes = self.cpp_fragment + options = [ c for c in codes if c.startswith ( tmp_text ) ] + if state < len(options): + return options[state] + else: + return None diff --git a/src/py/utils.py b/src/py/utils.py index fd55be5..91282ba 100644 --- a/src/py/utils.py +++ b/src/py/utils.py @@ -11,4 +11,11 @@ def quit_ite( input_str ): return False def get_raw_input(tip, idx): - return raw_input("{t} [{i}]> ".format( t=tip, i=idx) ) + return raw_input( "{t} [{i}]> ".format( t=tip, i=idx ) ) + +def completer(text, state): + options = [i for i in commands if i.startswith(text)] + if state < len(options): + return options[state] + else: + return None diff --git a/start.sh b/start.sh index 0000f7d..61590ba 100755 --- a/start.sh +++ b/start.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash -BIN_FILE=$(readlink -f $0) +#BIN_FILE=$(readlink -f $0) +BIN_FILE=$(readlink $0) # On mac os, readlink no -f parameter PROJ_BIN=$(dirname $BIN_FILE) PROJ_HOME=$(dirname $PROJ_BIN) SCRIPT_NAME=$(basename $BIN_FILE)