// Custom includes
#include <boost/bind.hpp>
-#include "TelnetTerminal.hh"
+#include "../../Utils/membind.hh"
#include "../../Scheduler/Scheduler.hh"
#include "../Logger.hh"
#include "../../Socket/Protocols/INet.hh"
+#include "TelnetTerminal.hh"
+#include "Editor.hh"
//#include "telnetServer.mpp"
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
namespace {
-
- class MyTelnet : public senf::term::TelnetTerminal
+
+ class MyTelnet
+ : public senf::term::TelnetTerminal
{
public:
- explicit MyTelnet(Handle handle) : senf::term::BaseTelnetProtocol(handle) {}
-
- private:
- virtual void v_keyReceived(keycode_t key)
+ explicit MyTelnet(Handle handle)
+ : senf::term::BaseTelnetProtocol (handle),
+ editor_ (*this, senf::membind(&MyTelnet::executeLine, this))
+ {
+ editor_.prompt("myTelnet-with-an-endlesssly-long-prompt$");
+ editor_.defineKey(senf::term::KeyParser::Ctrl('D'),
+ senf::membind(&MyTelnet::deleteCharOrExit, this));
+ }
+
+ void deleteCharOrExit(senf::term::LineEditor & editor)
+ {
+ if (editor.text().empty()) {
+ exit();
+ }
+ else
+ senf::term::bindings::deleteChar(editor);
+ }
+
+ void exit()
{
- SENF_LOG(("Key " << senf::term::KeyParser::describe(key)));
+ handle().facet<senf::TCPSocketProtocol>().shutdown(senf::TCPSocketProtocol::ShutRD);
+ }
+
+ virtual void v_setupFailed()
+ {
+ SENF_LOG(("Terminal setup failed"));
+ exit();
}
virtual void v_eof()
delete this;
}
- virtual void v_setupComplete()
+ void executeLine(std::string const & text)
{
- TelnetTerminal::v_setupComplete();
- SENF_LOG(("Terminal type is '" << terminalType() << "', window size is "
- << width() << "x" << height()));
+ SENF_LOG(("Execute line: " << text));
+ editor_.show();
}
- virtual void v_windowSizeChanged()
- {
- SENF_LOG(("New window size: " << width() << "x" << height()));
- }
+ private:
+ senf::term::LineEditor editor_;
};
typedef senf::TCPv4ServerSocketHandle ServerHandle;
}
ClientHandle client (handle.accept());
SENF_LOG(("new client ..."));
- new MyTelnet (client);
+ try {
+ new MyTelnet (client);
+ }
+ catch (std::exception & ex) {
+ SENF_LOG(("Client open failed: " << ex.what()));
+ }
+ catch (...) {
+ SENF_LOG(("Client open failed: unknown exception"));
+ }
}
}