Utils/Console: Replace Readline with LineEditor
[senf.git] / Utils / Console / LineEditor.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 LineEditor public header */
25
26 #ifndef HH_SENF_Utils_Console_LineEditor_
27 #define HH_SENF_Utils_Console_LineEditor_ 1
28
29 // Custom includes
30 #include <boost/scoped_ptr.hpp>
31 #include "../Termlib/TelnetTerminal.hh"
32 #include "../Termlib/Editor.hh"
33 #include "Server.hh"
34
35 //#include "LineEditor.mpp"
36 ///////////////////////////////hh.p////////////////////////////////////////
37
38 namespace senf {
39 namespace console {
40 namespace detail {
41
42     class LineEditorSwitcher
43         : public ClientReader
44     {
45     public:
46         explicit LineEditorSwitcher(Client & client);
47
48         void editorSetupFailed();
49
50     private:
51         virtual void v_disablePrompt();
52         virtual void v_enablePrompt();
53         virtual void v_write(std::string const & data);
54
55         boost::scoped_ptr<ClientReader> reader_;
56     };
57
58     class LineEditorClientReader
59         : public ClientReader, public term::TelnetTerminal
60     {
61     public:
62         explicit LineEditorClientReader(Client & client, LineEditorSwitcher & switcher);
63         
64     private:
65         // TelnetTerminal API implementation
66         virtual void v_setupFailed();
67         virtual void v_eof();
68
69         // ClientReader API implementation
70         virtual void v_disablePrompt();
71         virtual void v_enablePrompt();
72         virtual void v_write(std::string const & data);
73
74         // Editor callbacks
75         void executeLine(std::string const & text);
76         void deleteCharOrExit(term::LineEditor & editor);
77
78         term::LineEditor editor_;
79         LineEditorSwitcher * switcher_;
80     };
81
82 }}}
83
84 ///////////////////////////////hh.e////////////////////////////////////////
85 //#include "LineEditor.cci"
86 //#include "LineEditor.ct"
87 //#include "LineEditor.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: