Utils/Termlib: Implement LineEditor auxiliary display support
[senf.git] / Utils / Termlib / Editor.hh
index e5cb475..d2d091c 100644 (file)
@@ -28,6 +28,8 @@
 
 // Custom includes
 #include <map>
+#include <vector>
+#include <string>
 #include <senf/Scheduler/ClockService.hh>
 #include <senf/Scheduler/TimerEvent.hh>
 #include "AbstractTerminal.hh"
@@ -52,13 +54,19 @@ namespace term {
         void newline();                 ///< Move to beginning of a new, empty line
         void toColumn(unsigned c);      ///< Move cursor to column \p c
         void put(char ch);              ///< Write \p ch at current column
-        void put(std::string const & text);
+        void put(std::string const & text); ///< Write \a text starting at current column
         void clearLine();               ///< Clear current line and move cursor to first column
         void setBold();                 ///< Set bold char display
         void setNormal();               ///< Set normal char display
+        void maybeClrScr();             ///< Clear screen if possible
+
+        void toLine(unsigned l);        ///< Move to relative display line \a l
+        void reset();                   ///< Reset display area to single line
 
         unsigned currentColumn() const; ///< Return number of current column
-        unsigned width();
+        unsigned currentLine() const;   ///< Return number of current relative line
+        unsigned width();               ///< Return current screen width
+        unsigned height();              ///< Return current screen height
 
     protected:
         virtual bool cb_init();
@@ -82,6 +90,8 @@ namespace term {
         ClockService::clock_type keyTimeout_;
         scheduler::TimerEvent timer_;
         unsigned column_;
+        unsigned displayHeight_;
+        unsigned line_;
     };
 
     class LineEditor
@@ -94,6 +104,8 @@ namespace term {
         typedef boost::function<void (LineEditor&)> KeyBinding;
         typedef boost::function<void (std::string const &)> AcceptCallback;
 
+        static unsigned const MAX_HISTORY_SIZE = 1024u;
+
         ///////////////////////////////////////////////////////////////////////////
 
         LineEditor(AbstractTerminal & terminal, AcceptCallback cb);
@@ -120,6 +132,16 @@ namespace term {
         void insert(char ch);
         void insert(std::string const & text);
 
+        // History
+        void pushHistory(std::string const & text);
+        void prevHistory();
+        void nextHistory();
+
+        // Aux Display
+        void auxDisplay(int line, std::string const & text);
+        unsigned maxAuxDisplayHeight();
+        void clearAuxDisplay();
+
         // Get information
         std::string const & text();
         unsigned point();
@@ -136,6 +158,7 @@ namespace term {
         virtual void v_keyReceived(keycode_t key);
 
         typedef std::map<keycode_t, KeyBinding> KeyMap;
+        typedef std::vector<std::string> History;
 
         bool enabled_;
         bool redisplayNeeded_;
@@ -148,6 +171,8 @@ namespace term {
         keycode_t lastKey_;
         AcceptCallback callback_;
         KeyMap bindings_;
+        History history_;
+        unsigned historyPoint_;
     };
 
 namespace bindings {
@@ -162,6 +187,12 @@ namespace bindings {
     void endOfLine           (LineEditor & editor);
     void deleteToEndOfLine   (LineEditor & editor);
     void restartEdit         (LineEditor & editor);
+    void prevHistory         (LineEditor & editor);
+    void nextHistory         (LineEditor & editor);
+    void clearScreen         (LineEditor & editor);
+
+    typedef boost::function<void (LineEditor &, unsigned b, unsigned e, std::vector<std::string> &)> Completer;
+    void complete            (LineEditor & editor, Completer completer);
 
 }