00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <iostream>
00019 #include <vector>
00020 #include <string>
00021 #include <map>
00022 #include <list>
00023 using namespace std;
00024
00025
00026 #include "SReadline.h"
00027 using namespace swift;
00028
00029
00030
00031
00032 int main( int argc, char ** argv )
00033 {
00034
00035
00036
00037
00038 SReadline Reader( "/tmp/.testhist", 32 );
00039
00040
00041
00042 vector< string > Completers;
00043
00044
00045
00046
00047 Completers.push_back( "command1 opt1" );
00048 Completers.push_back( "command1 opt2" );
00049 Completers.push_back( "command1 opt3 %file" );
00050 Completers.push_back( "command2 opt4" );
00051 Completers.push_back( "command2 opt5 %file %file" );
00052
00053
00054
00055
00056 Reader.RegisterCompletions( Completers );
00057
00058
00059 string UserInput;
00060 bool EndOfInput( false );
00061
00062 for ( ; ; )
00063 {
00064
00065 UserInput = Reader.GetLine( "Please input your command> ", EndOfInput );
00066 if ( EndOfInput )
00067 {
00068 cout << "End of the session. Exiting." << endl;
00069 break;
00070 }
00071 cout << "User input: '" << UserInput << "'." << endl;
00072 cout << "Press Ctrl+D for gracefull exit" << endl;
00073 }
00074
00075
00076 Reader.SaveHistory( "/tmp/BackupFileJustInCase" );
00077
00078
00079 Reader.ClearHistory();
00080
00081
00082 Reader.LoadHistory( "/tmp/BackupFileJustInCase" );
00083
00084 return 0;
00085 }
00086