# HG changeset patch # User Teemu Piippo # Date 1431704182 -10800 # Node ID 4f7c2c9446374f2f16bad1da96f3e0ebbf12c1bd # Parent 0e947b487b18ab3c4af8212f4aa9d87d5c692503# Parent 9ab869656b9e6cc324b898810253f76db4d9b30c Merge tab-complete diff -r 0e947b487b18 -r 4f7c2c944637 sources/interface.cpp --- a/sources/interface.cpp Mon May 04 18:16:05 2015 +0300 +++ b/sources/interface.cpp Fri May 15 18:36:22 2015 +0300 @@ -803,6 +803,20 @@ } break; + case '\t': + { + int space = current_input().find (" "); + + if (CurrentInputState == INPUTSTATE_NORMAL + and InputCursor > 0 + and (space == -1 or space >= InputCursor)) + { + String start = current_input().mid (0, InputCursor); + RCONSession::get_session()->request_tab_complete (start); + } + } + break; + case '\n': case KEY_ENTER: switch (CurrentInputState) @@ -892,6 +906,8 @@ } break; } + + render(); } // ------------------------------------------------------------------------------------------------- @@ -978,3 +994,21 @@ PlayerNames = names; NeedNicklistRender = true; } + +// ------------------------------------------------------------------------------------------------- +// +FUNCTION +Interface::tab_complete (const String& part, String complete) -> void +{ + String& input = mutable_current_input(); + + if (input.starts_with (part)) + { + if (input[part.length()] != ' ') + complete += ' '; + + input.replace (0, part.length(), complete); + InputCursor = complete.length(); + NeedInputRender = true; + } +} diff -r 0e947b487b18 -r 4f7c2c944637 sources/interface.h --- a/sources/interface.h Mon May 04 18:16:05 2015 +0300 +++ b/sources/interface.h Fri May 15 18:36:22 2015 +0300 @@ -41,4 +41,6 @@ FUNCTION update_statusbar() -> void; FUNCTION connect (String address, String password) -> void; FUNCTION set_player_names (const StringList& names) -> void; + FUNCTION need_refresh() -> void; + FUNCTION tab_complete (const String& part, String complete) -> void; }; diff -r 0e947b487b18 -r 4f7c2c944637 sources/list.h --- a/sources/list.h Mon May 04 18:16:05 2015 +0300 +++ b/sources/list.h Fri May 15 18:36:22 2015 +0300 @@ -339,7 +339,7 @@ { public: using Super = Container>; - using Super::Container; + using typename Super::Container; Vector(){} @@ -360,4 +360,4 @@ { return data(); } -}; \ No newline at end of file +}; diff -r 0e947b487b18 -r 4f7c2c944637 sources/network/rconsession.cpp --- a/sources/network/rconsession.cpp Mon May 04 18:16:05 2015 +0300 +++ b/sources/network/rconsession.cpp Fri May 15 18:36:22 2015 +0300 @@ -161,6 +161,37 @@ case SVRC_UPDATE: process_server_updates (packet); break; + + case SVRC_TOOMANYTABCOMPLETES: + { + unsigned int numCompletions = packet.read_short(); + print ("%1 completions for '%2'.\n", + int (numCompletions), m_lastTabComplete); + } + break; + + case SVRC_TABCOMPLETE: + { + StringList completes; + + for (signed int i = packet.read_byte(); i > 0; --i) + completes << packet.read_string(); + + if (completes.size() == 1) + Interface::tab_complete (m_lastTabComplete, completes[0]); + else if (not completes.is_empty()) + { + print ("Completions for '%1':\n", m_lastTabComplete); + + for (int i = 0; i < completes.size(); i += 8) + { + Range spliceRange (i, min (i + 8, completes.size() - 1)); + StringList splice (completes.splice (spliceRange)); + print ("- %1\n", splice.join (", ")); + } + } + } + break; } } } @@ -321,3 +352,21 @@ { return m_level; } + +// ------------------------------------------------------------------------------------------------- +// +METHOD +RCONSession::request_tab_complete (const String& part) -> void +{ + if (m_serverProtocol >= 4) + { + Bytestream packet; + packet.write_byte (CLRC_TABCOMPLETE); + packet.write_string (part); + send (packet); + bump_last_ping(); + m_lastTabComplete = part; + } + else + print ("Server protocol is %1, cannot tab-complete\n", m_serverProtocol); +} diff -r 0e947b487b18 -r 4f7c2c944637 sources/network/rconsession.h --- a/sources/network/rconsession.h Mon May 04 18:16:05 2015 +0300 +++ b/sources/network/rconsession.h Fri May 15 18:36:22 2015 +0300 @@ -37,7 +37,7 @@ // enum { - RCON_PROTOCOL_VERSION = 3 + RCON_PROTOCOL_VERSION = 4 }; // ------------------------------------------------------------------------------------------------- @@ -51,6 +51,8 @@ SVRC_INVALIDPASSWORD, SVRC_MESSAGE, SVRC_UPDATE, + SVRC_TABCOMPLETE, + SVRC_TOOMANYTABCOMPLETES, }; // ------------------------------------------------------------------------------------------------- @@ -62,6 +64,7 @@ CLRC_COMMAND, CLRC_PONG, CLRC_DISCONNECT, + CLRC_TABCOMPLETE, }; // ------------------------------------------------------------------------------------------------- @@ -107,6 +110,7 @@ METHOD state() const -> RCONSessionState; METHOD level() const -> const String&; METHOD is_active() const -> bool; + METHOD request_tab_complete (const String& part) -> void; static METHOD get_session() -> RCONSession*; @@ -123,4 +127,5 @@ String m_hostname; int m_numAdmins; String m_level; + String m_lastTabComplete; };