K
So langsam komme ich voran
Hier die verbesserte Version:
int main( )
{
string HistoryFile = "history.txt";
bool do_exit = false;
const char prompt[ ] = ":\\>";
//Liste für History Befehle
list< string > history;
//Liste für Dateien/Verzeichniss
list< string > listDir;
if(checkFile(HistoryFile.c_str()))
{
history = readHistory(HistoryFile);
}
//Hole Dateien/Verzeichnisse
listDir = getDirectory();
HANDLE std_output = GetStdHandle( STD_OUTPUT_HANDLE );
CONSOLE_SCREEN_BUFFER_INFO console_screen_buffer_info;
do
{
cout << prompt;
string input;
string getTabOutput;
bool history_mode = false;
bool TAB_MODE = false;
list< string >::iterator current_file = listDir.begin();
list< string >::iterator current_history_item = history.begin( );
int key;
do
{
key = _getch( );
//Backspace
if( ( key == 0x08 ) && input.length( ) )
{
clear_line( input.length( ), prompt );
input.erase( input.length( ) - 1, 1 );
cout << input << flush;
}
//TAB-Vervollständigung
else if( key == 0x09)
{
//Speichert Ausgabe in History
TAB_MODE = true;
if( current_file != listDir.end() )
{
++current_file;
if( current_file != listDir.end( ) )
{
string FileObject = *current_file;
getTabOutput = clear_TabInput(input, prompt, FileObject);
cout << getTabOutput << flush;
}
else
current_file = listDir.begin();
}
}
else if( key == 0x0E && key == 0x09)
{
cout << "SHIFT" << endl;
}
//Escape
else if( key == 0x1b )
{
clear_line( input.length( ), prompt );
history_mode = false;
input = "";
}
//Steuerzeichen
else if( key == 0xe0 )
{
switch( _getch( ) )
{
int x, y;
case 0x48: // Pfeiltaste nach Oben
if( current_history_item != history.end( ) )
{
if( !history_mode )
{
history_mode = true;
}
else
{
++current_history_item;
}
if( current_history_item != history.end( ) )
{
clear_line( input.length( ), prompt );
input = *current_history_item;
cout << input << flush;
}
}
break;
case 0x50: // Pfeiltaste nach Unten
if( history_mode && ( current_history_item != history.begin( ) ) )
{
--current_history_item;
clear_line( input.length( ), prompt );
input = *current_history_item;
cout << input << flush;
}
break;
case 0x4B: // Pfeiltaste nach Links
GetConsoleScreenBufferInfo( std_output, &console_screen_buffer_info );
x = console_screen_buffer_info.dwCursorPosition.X;
y = console_screen_buffer_info.dwCursorPosition.Y;
gotoxy(x-1, y);
break;
case 0x4D: // Pfeiltaste nach Rechts
GetConsoleScreenBufferInfo( std_output, &console_screen_buffer_info );
x = console_screen_buffer_info.dwCursorPosition.X;
y = console_screen_buffer_info.dwCursorPosition.Y;
gotoxy(x+1, y);
break;
}
}
else if( key != '\r' )
{
input += key;
cout.put( key );
}
else if( key == '\r')
{
if(TAB_MODE)
saveToHistory(getTabOutput);
else
saveToHistory(input);
}
}while( key != '\r' ); // enter
cout.put( '\n' );
if( input.length( ) )
{
if(TAB_MODE)
history.push_front( getTabOutput);
else
history.push_front( input );
}
if( input == "exit" )
{
do_exit = true;
}
} while( !do_exit );
}
Jetzt habe ich noch die LINKE & RECHTE PFEILTASTE eingebaut um in dem eingegebenem string zu navigieren, mithilfe von gotoxy() kann ich nun an die gewünschte Position gelangen. Wenn ich nun die Leertaste drücke wird der Input gelöscht also das jeweilige Zeichen, z.B. ich als Input = "hallo test**"
Jetzt möchte ich mit dem Cursor vorm "test" = "**test" wenn ich hier Leertaste drücke steht folgendes: " _est" es wird alles verschlungen, wie kann man das verhindern?