4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief Editor public header */
26 #ifndef HH_SENF_Utils_Termlib_Editor_
27 #define HH_SENF_Utils_Termlib_Editor_ 1
31 #include <senf/Scheduler/ClockService.hh>
32 #include <senf/Scheduler/TimerEvent.hh>
33 #include "AbstractTerminal.hh"
34 #include "Terminfo.hh"
36 //#include "Editor.mpp"
37 ///////////////////////////////hh.p////////////////////////////////////////
43 : public AbstractTerminal::Callbacks
46 typedef KeyParser::keycode_t keycode_t;
48 static unsigned const DEFAULT_KEY_TIMEOUT_MS = 500u;
50 explicit BaseEditor(AbstractTerminal & terminal);
52 void newline(); ///< Move to beginning of a new, empty line
53 void toColumn(unsigned c); ///< Move cursor to column \p c
54 void put(char ch); ///< Write \p ch at current column
55 void put(std::string const & text);
56 void clearLine(); ///< Clear current line and move cursor to first column
57 void setBold(); ///< Set bold char display
58 void setNormal(); ///< Set normal char display
60 unsigned currentColumn() const; ///< Return number of current column
64 virtual bool cb_init();
65 virtual void cb_windowSizeChanged();
68 virtual void v_keyReceived(keycode_t key) = 0;
70 virtual void cb_charReceived(char c);
72 void keySequenceTimeout();
76 void write(std::string const & s);
78 AbstractTerminal * terminal_;
81 std::string inputBuffer_;
82 ClockService::clock_type keyTimeout_;
83 scheduler::TimerEvent timer_;
91 ///////////////////////////////////////////////////////////////////////////
94 typedef boost::function<void (LineEditor&)> KeyBinding;
95 typedef boost::function<void (std::string const &)> AcceptCallback;
97 ///////////////////////////////////////////////////////////////////////////
99 LineEditor(AbstractTerminal & terminal, AcceptCallback cb);
101 ///////////////////////////////////////////////////////////////////////////
103 void prompt(std::string const & text);
104 void set(std::string const & text, unsigned pos = 0u);
106 // Overall edit control
112 void forceRedisplay();
114 // Cursor and display movement
115 void gotoChar(unsigned n);
116 void scrollTo(unsigned n);
119 void deleteChar(unsigned n=1);
120 void insert(char ch);
121 void insert(std::string const & text);
124 std::string const & text();
126 unsigned displayPos();
130 void defineKey(keycode_t key, KeyBinding binding);
131 void unsetKey(keycode_t key);
134 virtual bool cb_init();
135 virtual void cb_windowSizeChanged();
136 virtual void v_keyReceived(keycode_t key);
138 typedef std::map<keycode_t, KeyBinding> KeyMap;
141 bool redisplayNeeded_;
143 unsigned promptWidth_;
147 unsigned displayPos_;
149 AcceptCallback callback_;
155 void selfInsertCommand (LineEditor & editor);
156 void forwardChar (LineEditor & editor);
157 void backwardChar (LineEditor & editor);
158 void accept (LineEditor & editor);
159 void backwardDeleteChar (LineEditor & editor);
160 void deleteChar (LineEditor & editor);
161 void beginningOfLine (LineEditor & editor);
162 void endOfLine (LineEditor & editor);
163 void deleteToEndOfLine (LineEditor & editor);
164 void restartEdit (LineEditor & editor);
170 ///////////////////////////////hh.e////////////////////////////////////////
171 //#include "Editor.cci"
172 //#include "Editor.ct"
173 //#include "Editor.cti"
180 // comment-column: 40
181 // c-file-style: "senf"
182 // indent-tabs-mode: nil
183 // ispell-local-dictionary: "american"
184 // compile-command: "scons -u test"