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 non-inline non-template implementation */
27 //#include "Editor.ih"
30 #include <senf/Utils/membind.hh>
31 #include <senf/Scheduler/Scheduler.hh>
33 //#include "Editor.mpp"
35 ///////////////////////////////cc.p////////////////////////////////////////
37 prefix_ senf::term::BaseEditor::BaseEditor(AbstractTerminal & terminal)
38 : terminal_ (&terminal),
39 keyTimeout_ (senf::ClockService::milliseconds(DEFAULT_KEY_TIMEOUT_MS)),
40 timer_ ("senf::term::BaseEditor::keySequenceTimeout",
41 senf::membind(&BaseEditor::keySequenceTimeout, this)),
44 terminal_->setCallbacks(*this);
47 prefix_ void senf::term::BaseEditor::newline()
50 write(tifo_.getString(Terminfo::properties::ClrEol));
54 prefix_ void senf::term::BaseEditor::toColumn(unsigned c)
59 if (tifo_.hasProperty(Terminfo::properties::ParmRightCursor)) {
60 write(tifo_.formatString(Terminfo::properties::ParmRightCursor, c - column_));
64 char const * cuf1 (tifo_.getString(Terminfo::properties::CursorRight));
71 else if (c < column_) {
72 if (tifo_.hasProperty(Terminfo::properties::ParmLeftCursor)) {
73 write(tifo_.formatString(Terminfo::properties::ParmLeftCursor, column_ - c));
77 char const * cub1 (tifo_.getString(Terminfo::properties::CursorRight));
86 prefix_ void senf::term::BaseEditor::insertChar(char ch)
88 if (column_+1 >= width())
90 if (tifo_.hasProperty(Terminfo::properties::InsertCharacter))
91 write(tifo_.getString(Terminfo::properties::InsertCharacter));
93 write(tifo_.formatString(Terminfo::properties::ParmIch, 1));
98 prefix_ void senf::term::BaseEditor::overwriteChar(char ch)
104 prefix_ void senf::term::BaseEditor::deleteChar()
106 if (tifo_.hasProperty(Terminfo::properties::DeleteCharacter))
107 write(tifo_.getString(Terminfo::properties::DeleteCharacter));
109 write(tifo_.formatString(Terminfo::properties::ParmDch, 1));
112 prefix_ unsigned senf::term::BaseEditor::currentColumn()
118 prefix_ void senf::term::BaseEditor::cb_init()
120 tifo_.load(terminal_->terminalType());
121 keyParser_.load(tifo_);
122 if (tifo_.hasProperty(Terminfo::properties::KeypadXmit))
123 write(tifo_.getString(Terminfo::properties::KeypadXmit));
126 prefix_ void senf::term::BaseEditor::cb_charReceived(char c)
129 timer_.timeout(senf::scheduler::eventTime() + keyTimeout_);
133 prefix_ void senf::term::BaseEditor::cb_windowSizeChanged()
135 if (column_ >= width())
139 prefix_ void senf::term::BaseEditor::keySequenceTimeout()
141 while (!inputBuffer_.empty()) {
143 v_keyReceived(keycode_t(inputBuffer_[0]));
144 inputBuffer_.erase(0, 1);
148 prefix_ void senf::term::BaseEditor::processKeys()
151 std::pair<senf::term::KeyParser::keycode_t, std::string::size_type> result
152 (keyParser_.lookup(inputBuffer_));
153 if (result.first == senf::term::KeyParser::Incomplete)
155 v_keyReceived(result.first);
156 inputBuffer_.erase(0, result.second);
157 } while (! inputBuffer_.empty());
161 prefix_ unsigned senf::term::BaseEditor::width()
163 return terminal_->width();
166 prefix_ void senf::term::BaseEditor::write(char ch)
168 terminal_->write(ch);
171 prefix_ void senf::term::BaseEditor::write(std::string const & s)
173 for (std::string::const_iterator i (s.begin()); i != s.end(); ++i)
177 ///////////////////////////////cc.e////////////////////////////////////////
179 //#include "Editor.mpp"
185 // comment-column: 40
186 // c-file-style: "senf"
187 // indent-tabs-mode: nil
188 // ispell-local-dictionary: "american"
189 // compile-command: "scons -u test"