Utils/Termlib: Implement terminfo format string interpretation
[senf.git] / Utils / Termlib / Editor.hh
1 // $Id$
2 //
3 // Copyright (C) 2009 
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief Editor public header */
25
26 #ifndef HH_SENF_Utils_Termlib_Editor_
27 #define HH_SENF_Utils_Termlib_Editor_ 1
28
29 // Custom includes
30 #include <senf/Scheduler/ClockService.hh>
31 #include <senf/Scheduler/TimerEvent.hh>
32 #include "AbstractTerminal.hh"
33 #include "Terminfo.hh"
34
35 //#include "Editor.mpp"
36 ///////////////////////////////hh.p////////////////////////////////////////
37
38 namespace senf {
39 namespace term {
40
41     class BaseEditor
42         : public AbstractTerminal::Callbacks
43     {
44     public:
45         typedef KeyParser::keycode_t keycode_t;
46
47         static unsigned const DEFAULT_KEY_TIMEOUT_MS = 500u;
48
49         explicit BaseEditor(AbstractTerminal & terminal);
50
51         void newline();                 ///< Move to beginning of a new, empty line
52         void toColumn(unsigned c);      ///< Move cursor to column \p c
53         void insertChar(char ch);       ///< Insert \p ch at current column, shifting text right
54         void overwriteChar(char ch);    ///< Write \p ch at current column
55         void deleteChar();              ///< Delete a character a current column
56
57         unsigned currentColumn() const; ///< Return number of current column
58
59     private:
60         virtual void v_keyReceived(keycode_t key) = 0;
61
62         virtual void cb_init();
63         virtual void cb_charReceived(char c);
64         virtual void cb_windowSizeChanged();
65
66         void keySequenceTimeout();
67         void processKeys();
68
69         unsigned width();
70         void write(char ch);
71         void write(std::string const & s);
72         
73         AbstractTerminal * terminal_;
74         Terminfo tifo_;
75         KeyParser keyParser_;
76         std::string inputBuffer_;
77         ClockService::clock_type keyTimeout_;
78         scheduler::TimerEvent timer_;
79         unsigned column_;
80     };
81
82 }}
83
84 ///////////////////////////////hh.e////////////////////////////////////////
85 //#include "Editor.cci"
86 //#include "Editor.ct"
87 //#include "Editor.cti"
88 #endif
89
90 \f
91 // Local Variables:
92 // mode: c++
93 // fill-column: 100
94 // comment-column: 40
95 // c-file-style: "senf"
96 // indent-tabs-mode: nil
97 // ispell-local-dictionary: "american"
98 // compile-command: "scons -u test"
99 // End: