C/C++ History für Command Prompt
-
Hoi,
ich habe mir eine Art Shell geschrieben, die verschiedene Kommandos abarbeitet.
Jetzt hätte ich gerne eine Art History, durch die ich mit den Pfeiltasten hoch/runter hüpfen kann, wie bei der bash zb.Gibt es dafür etwas fertiges?
Mfg,
Ethon
-
Nein, das sind vielleicht 10 Zeilen Code, willste das als Library?
-
Ah, libreadline. Problem solved. Warum, finde ich den Kram immer sofort nachdem ich hier nachfrage?
cooky451 schrieb:
Nein, das sind vielleicht 10 Zeilen Code, willste das als Library?
10 Zeilen? Mindestens 50x so viele. Zeig doch mal nen 10-Zeiler der das kann.
-
Du machst nen Container in den du alle Eingaben kopierst und springst dann bei down einen Index runter und bei up einen Index hoch?
-
cooky451 schrieb:
Du machst nen Container in den du alle Eingaben kopierst und springst dann bei down einen Index runter und bei up einen Index hoch?
Woher weißt du ob die Pfeiltaste gedrückt wurde?
-
Was hat die History damit zu tun? Ich dachte du hast schon eine Shell?
-
Bis jetzt lese ich ein Kommando mit std::getline und führe das aus.
readline ist ein perfekter Ersatz, die Bibliothek unterstützt eben nicht nur Keybindings sondern auch History, auto compltion etc.Sorry wenn ich mich missverständlich ausgedrückt habe, eine History allein wäre natürlich trivial umzusetzen.
-
Dann suchst du also keine History, sondern... ja, was eigentlich? Eine Bibliothek für Tastatureingaben? Wenn es nur für ein System sein soll, wird es ja wieder trivial. Aber readline scheint es ja gelöst zu haben.
-
Wenn es mal um ein Programm geht, das du nicht unbedingt erst selbst auf Readline umstellen willst, kannst du es auch einfach mit rlwrap wrappen.
rlwrap dein-programm
Schon dürftest du die netten Commandline-Editing-Funktionen Readlines sowie eine History zur Verfügung haben.
-
Nutzt du Windows? Ich glaube, wenn du getline nutzt, dann hast du diese Funktionalität automatisch.