// Custom includes
#include <map>
+#include <vector>
+#include <string>
#include <senf/Scheduler/ClockService.hh>
#include <senf/Scheduler/TimerEvent.hh>
#include "AbstractTerminal.hh"
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();
ClockService::clock_type keyTimeout_;
scheduler::TimerEvent timer_;
unsigned column_;
+ unsigned displayHeight_;
+ unsigned line_;
};
class LineEditor
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);
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();
virtual void v_keyReceived(keycode_t key);
typedef std::map<keycode_t, KeyBinding> KeyMap;
+ typedef std::vector<std::string> History;
bool enabled_;
bool redisplayNeeded_;
keycode_t lastKey_;
AcceptCallback callback_;
KeyMap bindings_;
+ History history_;
+ unsigned historyPoint_;
};
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);
}