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 LineEditor non-inline non-template implementation */
26 #include "LineEditor.hh"
27 //#include "LineEditor.ih"
30 #include "../Logger/SenfLog.hh"
32 //#include "LineEditor.mpp"
34 ///////////////////////////////cc.p////////////////////////////////////////
36 ///////////////////////////////////////////////////////////////////////////
37 // senf::console::detail::LineEditorSwitcher
39 prefix_ senf::console::detail::LineEditorSwitcher::LineEditorSwitcher(Client & client)
40 : ClientReader(client),
41 reader_ (new LineEditorClientReader(client, *this))
44 prefix_ void senf::console::detail::LineEditorSwitcher::editorSetupFailed()
46 // We need to delete the old reader *before* creating the new one such that all old scheduler
47 // events are removed before installing the new ones.
49 reader_.reset(new DumbClientReader(client()));
52 prefix_ void senf::console::detail::LineEditorSwitcher::v_disablePrompt()
54 reader_->disablePrompt();
57 prefix_ void senf::console::detail::LineEditorSwitcher::v_enablePrompt()
59 reader_->enablePrompt();
62 prefix_ void senf::console::detail::LineEditorSwitcher::v_write(std::string const & data)
67 ///////////////////////////////////////////////////////////////////////////
68 // senf::console::detail::LineEditorClientReader
70 prefix_ senf::console::detail::LineEditorClientReader::
71 LineEditorClientReader(Client & client, LineEditorSwitcher & switcher)
72 : term::BaseTelnetProtocol(client.handle()), ClientReader(client),
73 editor_ (*this, senf::membind(&LineEditorClientReader::executeLine, this)),
76 editor_.prompt(promptString());
77 editor_.defineKey(senf::term::KeyParser::Ctrl('D'),
78 senf::membind(&LineEditorClientReader::deleteCharOrExit, this));
81 prefix_ void senf::console::detail::LineEditorClientReader::v_setupFailed()
84 switcher_->editorSetupFailed();
87 prefix_ void senf::console::detail::LineEditorClientReader::v_eof()
92 prefix_ void senf::console::detail::LineEditorClientReader::v_disablePrompt()
97 prefix_ void senf::console::detail::LineEditorClientReader::v_enablePrompt()
102 prefix_ void senf::console::detail::LineEditorClientReader::v_write(std::string const & data)
104 BaseTelnetProtocol::write(data);
108 senf::console::detail::LineEditorClientReader::executeLine(std::string const & text)
111 stream() << std::flush;
112 editor_.prompt(promptString());
117 senf::console::detail::LineEditorClientReader::deleteCharOrExit(term::LineEditor & editor)
119 if (editor.text().empty())
120 ClientReader::handle().facet<TCPSocketProtocol>().shutdown(TCPSocketProtocol::ShutRD);
122 term::bindings::deleteChar(editor);
125 ///////////////////////////////cc.e////////////////////////////////////////
127 //#include "LineEditor.mpp"
133 // comment-column: 40
134 // c-file-style: "senf"
135 // indent-tabs-mode: nil
136 // ispell-local-dictionary: "american"
137 // compile-command: "scons -u test"