00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <iostream>
00020 #include <vector>
00021 #include <string>
00022 #include <map>
00023 #include <list>
00024 using namespace std;
00025
00026
00027 #include "SReadline.h"
00028 using namespace swift;
00029
00030
00031
00032 const string Prompt( "Please input your command> " );
00033
00034
00035
00036
00037
00038
00039
00040
00041 SReadline Reader( "/tmp/.testhist", 32 );
00042
00043
00044 SKeymap Keymap1( emacs_standard_keymap );
00045 SKeymap Keymap2( false );
00046
00047
00048
00049
00050 int PrintInfo( int Count, int Key )
00051 {
00052 cout << "Keymaps usage example v.1.0" << endl
00053 << "Press Ctrl-K to get back to the interactive mode." << endl;
00054 return 0;
00055 }
00056
00057 int SwitchToKeymap2( int Count, int Key )
00058 {
00059 Reader.SetKeymap( Keymap2 );
00060 cout << endl
00061 << "Entered to non-interactive mode. Use Ctrl-I for information." << endl;
00062 return 0;
00063 }
00064
00065 int SwitchToKeymap1( int Count, int Key )
00066 {
00067 Reader.SetKeymap( Keymap1 );
00068 cout << "Entering to interactive mode." << endl
00069 << "Press Ctrl-K to switch to the non-interactive mode." << endl;
00070
00071
00072 cout << Prompt << rl_line_buffer;
00073 return 0;
00074 }
00075
00076
00077
00078 int main( int argc, char ** argv )
00079 {
00080
00081 Keymap2.Bind( 'a', PrintInfo );
00082 Keymap2.Bind( CTRL( 'I' ), PrintInfo );
00083 Keymap2.Bind( CTRL( 'K' ), SwitchToKeymap1 );
00084
00085
00086 Keymap1.Bind( CTRL( 'K' ), SwitchToKeymap2 );
00087
00088
00089
00090 Reader.SetKeymap( Keymap1 );
00091
00092
00093 cout << "Use CTRL+K for switching keymaps" << endl;
00094
00095
00096 string UserInput;
00097 bool EndOfInput( false );
00098
00099 for ( ; ; )
00100 {
00101
00102 UserInput = Reader.GetLine( Prompt, EndOfInput );
00103 if ( EndOfInput )
00104 {
00105 cout << "End of the session. Exiting." << endl;
00106 break;
00107 }
00108 cout << "User input: '" << UserInput << "'." << endl;
00109 cout << "Press Ctrl+D for gracefull exit" << endl;
00110 }
00111
00112 return 0;
00113 }
00114