switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Utils / Console / LineEditor.hh
1 // $Id$
2 //
3 // Copyright (C) 2009
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief LineEditor public header */
30
31 #ifndef HH_SENF_Utils_Console_LineEditor_
32 #define HH_SENF_Utils_Console_LineEditor_ 1
33
34 // Custom includes
35 #include <boost/scoped_ptr.hpp>
36 #include <senf/Utils/Termlib/TelnetTerminal.hh>
37 #include <senf/Utils/Termlib/Editor.hh>
38 #include "Server.hh"
39
40 //#include "LineEditor.mpp"
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
42
43 namespace senf {
44 namespace console {
45 namespace detail {
46
47     /** \brief Internal: Client reader switching between LineEditorClientReader or DumbClientReader
48
49         This ClientReader implementation will try to initialize a LineEditorClientReader. If the
50         setup fails, a DumbClientReader is initialized instead. LineEditor support may fail to be
51         initialized if
52
53         \li The telnet client does not support necessary functionality
54         \li or the terminal type of the client is missing some functionality.
55      */
56     class LineEditorSwitcher
57         : public ClientReader
58     {
59     public:
60         explicit LineEditorSwitcher(Client & client);
61
62         void editorSetupFailed();
63
64     private:
65         virtual void v_disablePrompt();
66         virtual void v_enablePrompt();
67         virtual void v_write(std::string const & data);
68         virtual unsigned v_width() const;
69
70         boost::scoped_ptr<ClientReader> reader_;
71     };
72
73     /** \brief Internal: ClientReader using senf::term::LineEditor for interactive input
74
75         This ClientReader implementation uses a senf::term::LineEditor for interactive input.
76      */
77     class LineEditorClientReader
78         : public ClientReader, public term::TelnetTerminal
79     {
80     public:
81         explicit LineEditorClientReader(Client & client, LineEditorSwitcher & switcher);
82
83     private:
84         // TelnetTerminal API implementation
85         virtual void v_setupFailed();
86         virtual void v_eof();
87
88         // ClientReader API implementation
89         virtual void v_disablePrompt();
90         virtual void v_enablePrompt();
91         virtual void v_write(std::string const & data);
92         virtual unsigned v_width() const;
93
94         // Editor callbacks
95         void executeLine(std::string const & text);
96         void deleteCharOrExit(term::LineEditor & editor);
97         void completePath(term::LineEditor & editor, unsigned & b, unsigned & e,
98                           std::string & prefix, std::vector<std::string> & completions);
99
100         term::LineEditor editor_;
101         LineEditorSwitcher * switcher_;
102         std::string default_;
103     };
104
105 }}}
106
107 //-/////////////////////////////////////////////////////////////////////////////////////////////////
108 //#include "LineEditor.cci"
109 //#include "LineEditor.ct"
110 //#include "LineEditor.cti"
111 #endif
112
113 \f
114 // Local Variables:
115 // mode: c++
116 // fill-column: 100
117 // comment-column: 40
118 // c-file-style: "senf"
119 // indent-tabs-mode: nil
120 // ispell-local-dictionary: "american"
121 // compile-command: "scons -u test"
122 // End: