sources/interface.cpp

Sun, 17 May 2015 22:07:48 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sun, 17 May 2015 22:07:48 +0300
branch
protocol5
changeset 80
f992b027374b
parent 78
c1d43ade656e
child 84
3bd32eec3d57
permissions
-rw-r--r--

Added support for SVRC_YOUREDISCONNECTED

14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
73
07dda51a7a8e Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
2 Copyright 2014, 2015 Teemu Piippo
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 All rights reserved.
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 Redistribution and use in source and binary forms, with or without
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 modification, are permitted provided that the following conditions
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 are met:
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 1. Redistributions of source code must retain the above copyright
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 notice, this list of conditions and the following disclaimer.
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 2. Redistributions in binary form must reproduce the above copyright
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 notice, this list of conditions and the following disclaimer in the
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 documentation and/or other materials provided with the distribution.
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 3. Neither the name of the copyright holder nor the names of its
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 contributors may be used to endorse or promote products derived from
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 this software without specific prior written permission.
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 */
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 #include <string.h>
51
481073b016a9 - added timestamps to output
Teemu Piippo <crimsondusk64@gmail.com>
parents: 50
diff changeset
32 #include <time.h>
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 #include "interface.h"
17
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
34 #include "network/rconsession.h"
24
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
35 #include "network/ipaddress.h"
46
19be47c9bab7 - renamed RendererLine to ColoredLine and split it into its own files
Teemu Piippo <crimsondusk64@gmail.com>
parents: 45
diff changeset
36 #include "coloredline.h"
34
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
37
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
38 static const int g_pageSize = 10;
16
33bac54867bf - added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
39
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 // -------------------------------------------------------------------------------------------------
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
42 int Interface::color_pair (Color fg, Color bg)
20
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
43 {
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
44 return COLOR_PAIR ((int (fg) * NUM_COLORS) + int (bg));
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
45 }
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
46
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
47 // -------------------------------------------------------------------------------------------------
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
48 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
49 const String& Interface::current_input()
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
50 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
51 return InputHistory[InputCursor];
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
52 }
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
53
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
54 // -------------------------------------------------------------------------------------------------
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
55 //
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
56 // Makes current_input() the lastmost input (so that we won't modify history)
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
57 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
58 void Interface::detach_input()
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
59 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
60 if (InputCursor > 0)
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
61 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
62 InputHistory[0] = current_input();
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
63 InputCursor = 0;
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
64 }
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
65 }
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
66
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
67 // -------------------------------------------------------------------------------------------------
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
68 // A version of current_input() that allows changing the contents of it.
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
69 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
70 String& Interface::mutable_current_input()
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
71 {
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
72 detach_input();
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
73 return InputHistory[InputCursor];
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
74 }
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
75
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
76 // -------------------------------------------------------------------------------------------------
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
77 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
78 void Interface::move_input_cursor (int delta)
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
79 {
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
80 // No input history when inputting addresses or passwords
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
81 if (CurrentInputState != INPUTSTATE_NORMAL)
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
82 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
83 InputCursor = 0;
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
84 return;
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
85 }
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
86
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
87 int oldcursor = InputCursor;
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
88 InputCursor = clamp (InputCursor + delta, 0, InputHistory.size() - 1);
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
89
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
90 if (InputCursor != oldcursor)
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
91 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
92 CursorPosition = current_input().length();
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
93 NeedInputRender = true;
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
94 }
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
95 }
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
96
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
97 // -------------------------------------------------------------------------------------------------
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
98 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
99 String Interface::prompt_string()
24
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
100 {
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
101 String prompt;
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
102
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
103 switch (CurrentInputState)
24
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
104 {
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
105 case INPUTSTATE_NORMAL: prompt = ">"; break;
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
106 case INPUTSTATE_ADDRESS: prompt = "address:"; break;
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
107 case INPUTSTATE_PASSWORD: prompt = "password:"; break;
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
108 case INPUTSTATE_CONFIRM_DISCONNECTION: break;
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
109 }
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
110
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
111 return prompt;
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
112 }
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
113
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
114 // -------------------------------------------------------------------------------------------------
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
115 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
116 void Interface::set_input_state (InputState newstate)
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
117 {
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
118 // Clear the input row (unless going to or from confirm state)
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
119 if (newstate != INPUTSTATE_CONFIRM_DISCONNECTION
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
120 and CurrentInputState != INPUTSTATE_CONFIRM_DISCONNECTION)
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
121 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
122 InputCursor = 0;
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
123 mutable_current_input().clear();
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
124 }
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
125
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
126 switch (newstate)
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
127 {
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
128 case INPUTSTATE_ADDRESS:
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
129 if (CurrentAddress.host != 0)
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
130 mutable_current_input() = CurrentAddress.to_string (IP_WITH_PORT);
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
131 break;
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
132
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
133 default:
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
134 break;
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
135 }
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
136
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
137 CurrentInputState = newstate;
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
138 NeedInputRender = true;
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
139 }
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
140
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
141 // -------------------------------------------------------------------------------------------------
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
142 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
143 Interface::Interface() :
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
144 Session (this)
20
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
145 {
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
146 ::initscr();
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
147 ::start_color();
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
148 ::raw();
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
149 ::keypad (stdscr, true);
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
150 ::noecho();
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
151 ::refresh();
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
152 ::timeout (0);
30
21fba5183768 - added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
153 ::use_default_colors();
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
154 InputHistory.clear();
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
155 InputHistory << "";
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
156 OutputLines.clear();
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
157 OutputLines << ColoredLine();
20
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
158
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
159 for (int i = 0; i < NUM_COLORS; ++i)
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
160 for (int j = 0; j < NUM_COLORS; ++j)
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
161 {
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
162 init_pair ((i * NUM_COLORS + j),
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
163 (i == DEFAULT) ? -1 : i,
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
164 (j == DEFAULT) ? -1 : j);
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
165 }
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
166
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
167 render_full();
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
168 refresh();
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
169 NeedRefresh = false;
20
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
170 }
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
172 // -------------------------------------------------------------------------------------------------
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
173 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
174 void Interface::render_titlebar()
20
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
175 {
80
f992b027374b Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents: 78
diff changeset
176 String message = Title;
f992b027374b Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents: 78
diff changeset
177
f992b027374b Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents: 78
diff changeset
178 if (Title.is_empty())
f992b027374b Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents: 78
diff changeset
179 message = format (APPNAME " %1 (%2)", full_version_string(), changeset_date_string());
f992b027374b Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents: 78
diff changeset
180
f992b027374b Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents: 78
diff changeset
181 if (message.length() <= COLS)
23
f7221183a994 - the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
182 {
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
183 int pair = color_pair (WHITE, BLUE);
80
f992b027374b Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents: 78
diff changeset
184 int startx = (COLS - message.length()) / 2;
f992b027374b Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents: 78
diff changeset
185 int endx = startx + message.length();
23
f7221183a994 - the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
186 attron (pair);
80
f992b027374b Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents: 78
diff changeset
187 mvprintw (0, startx, "%s", message.chars());
23
f7221183a994 - the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
188 mvhline (0, 0, ' ', startx);
f7221183a994 - the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
189 mvhline (0, endx, ' ', COLS - endx);
f7221183a994 - the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
190 attroff (pair);
f7221183a994 - the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
191 }
f7221183a994 - the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
192
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
193 NeedRefresh = true;
20
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
194 }
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
195
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
196 // -------------------------------------------------------------------------------------------------
5f8cdc8febbb - now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
197 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
198 void Interface::set_title (const String& title)
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
199 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
200 Title = title;
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
201 render_titlebar();
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
202 }
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
203
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
204 // -------------------------------------------------------------------------------------------------
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
205 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
206 void Interface::safe_disconnect (Function<void()> afterwards)
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
207 {
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
208 if (Session.is_active())
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
209 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
210 DisconnectConfirmFunction = afterwards;
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
211 set_input_state (INPUTSTATE_CONFIRM_DISCONNECTION);
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
212 }
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
213 else
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
214 afterwards();
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
215 }
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
216
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
217 // -------------------------------------------------------------------------------------------------
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
218 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
219 int Interface::nicklist_width()
47
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
220 {
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
221 // Allocate at least 12 characters, at most 24 characters, for the nicklist. If we cannot
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
222 // afford that (o_O) then we probably shouldn't draw the nicklist at all I think.
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
223 int nicklistWidth = COLS / 4;
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
224
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
225 if (nicklistWidth < 12)
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
226 return 0;
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
227
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
228 return min (nicklistWidth, 24);
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
229 }
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
230
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
231 // -------------------------------------------------------------------------------------------------
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
232 // Renders the given colored line onto the screen. Will wrap if allowWrap is true. Returns the
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
233 // 'y' value for the next line.
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
234 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
235 int Interface::render_colorline (int y, int x0, int width, const ColoredLine& line, bool allowWrap)
47
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
236 {
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
237 int x = x0;
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
238
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
239 for (int byte : line.data())
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
240 {
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
241 if (x == x0 + width)
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
242 {
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
243 if (not allowWrap)
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
244 return y;
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
245
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
246 x = x0;
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
247 ++y;
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
248 }
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
249
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
250 if (isprint (byte))
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
251 {
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
252 mvaddch (y, x, char (byte));
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
253 ++x;
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
254 }
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
255 else switch (byte)
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
256 {
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
257 case RLINE_ON_BLACK:
48
02009f1ec2b7 - cleanup, fixed red text not rendering
Teemu Piippo <crimsondusk64@gmail.com>
parents: 47
diff changeset
258 case RLINE_ON_RED:
47
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
259 case RLINE_ON_GREEN:
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
260 case RLINE_ON_YELLOW:
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
261 case RLINE_ON_BLUE:
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
262 case RLINE_ON_MAGENTA:
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
263 case RLINE_ON_CYAN:
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
264 case RLINE_ON_WHITE:
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
265 attron (color_pair (Color (byte - RLINE_ON_BLACK), DEFAULT));
47
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
266 break;
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
267
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
268 case RLINE_OFF_BLACK:
48
02009f1ec2b7 - cleanup, fixed red text not rendering
Teemu Piippo <crimsondusk64@gmail.com>
parents: 47
diff changeset
269 case RLINE_OFF_RED:
47
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
270 case RLINE_OFF_GREEN:
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
271 case RLINE_OFF_YELLOW:
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
272 case RLINE_OFF_BLUE:
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
273 case RLINE_OFF_MAGENTA:
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
274 case RLINE_OFF_CYAN:
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
275 case RLINE_OFF_WHITE:
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
276 attroff (color_pair (Color (byte - RLINE_OFF_BLACK), DEFAULT));
47
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
277 break;
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
278
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
279 case RLINE_ON_BOLD:
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
280 attron (A_BOLD);
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
281 break;
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
282
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
283 case RLINE_OFF_BOLD:
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
284 attroff (A_BOLD);
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
285 break;
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
286 }
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
287 }
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
288
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
289 return y + 1;
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
290 }
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
291
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
292 // -------------------------------------------------------------------------------------------------
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
293 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
294 void Interface::render_output()
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
295 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
296 if (OutputLines.size() == 1)
34
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
297 return;
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
298
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
299 OutputScroll = clamp (OutputScroll, 0, OutputLines.size() - 1);
34
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
300
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
301 int height = LINES - 3;
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
302 int width = COLS - nicklist_width();
34
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
303 int printOffset = 0;
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
304 int end = OutputLines.size() - 1 - OutputScroll;
34
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
305 int start = end;
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
306 int usedHeight = 0;
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
307 int y = 1;
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
308 bool tightFit = false;
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
309
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
310 // Where to start?
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
311 while (start > 0)
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
312 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
313 int rows = OutputLines[start - 1].rows (width);
34
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
314
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
315 if (usedHeight + rows > height)
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
316 {
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
317 // This line won't fit anymore.
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
318 tightFit = true;
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
319 break;
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
320 }
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
321
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
322 start--;
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
323 usedHeight += rows;
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
324 }
16
33bac54867bf - added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
325
34
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
326 // See if there's any more rows to use (end may be too small)
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
327 if (not tightFit)
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
328 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
329 while (end < OutputLines.size())
34
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
330 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
331 int rows = OutputLines[end].rows (width);
34
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
332
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
333 if (usedHeight + rows > height)
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
334 {
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
335 tightFit = true;
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
336 break;
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
337 }
16
33bac54867bf - added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
338
34
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
339 end++;
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
340 usedHeight += rows;
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
341 }
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
342 }
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
343
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
344 if (start > 0)
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
345 printOffset = height - usedHeight;
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
346
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
347 OutputScroll = OutputLines.size() - 1 - end;
34
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
348
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
349 if (start < 0 or start == end or printOffset >= height)
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
350 return;
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
351
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
352 assert (start <= end and start - end <= height);
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
353
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
354 // Clear the display
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
355 for (int i = y; i < y + height; ++i)
47
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
356 mvhline (i, 0, ' ', width);
34
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
357
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
358 // Print the lines
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
359 y += printOffset;
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
360
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
361 for (int i = start; i < end; ++i)
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
362 y = render_colorline (y, 0, width, OutputLines[i], true);
47
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
363
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
364 NeedOutputRender = false;
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
365 NeedRefresh = true;
47
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
366 }
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
367
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
368 // -------------------------------------------------------------------------------------------------
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
369 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
370 void Interface::render_nicklist()
47
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
371 {
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
372 int width = nicklist_width();
47
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
373 int height = LINES- 3;
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
374 int y = 1;
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
375 int x = COLS - width;
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
376
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
377 if (width == 0)
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
378 return;
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
379
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
380 for (int i = 0; i < height; ++i)
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
381 {
47
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
382 mvhline (y, x, ' ', width);
32
ee770597a281 - added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
383
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
384 if (i < PlayerNames.size())
78
c1d43ade656e Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
385 render_colorline (y, x, width, PlayerNames[i], false);
32
ee770597a281 - added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
386
47
35b968619b0c - added a nicklist!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 46
diff changeset
387 y++;
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
388 }
17
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
389
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
390 NeedNicklistRender = false;
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
391 NeedRefresh = true;
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
392 }
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
393
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
394 // -------------------------------------------------------------------------------------------------
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
395 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
396 void Interface::render_input()
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
397 {
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
398 int promptColor = color_pair (WHITE, BLUE);
24
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
399
25
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
400 // If we're asking the user if they want to disconnect, we don't render any input strings,
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
401 // just the confirmation message.
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
402 if (CurrentInputState == INPUTSTATE_CONFIRM_DISCONNECTION)
24
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
403 {
25
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
404 attron (promptColor);
24
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
405 mvhline (LINES - 2, 0, ' ', COLS);
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
406 mvprintw (LINES - 2, 0, "Are you sure you want to disconnect? y/n");
25
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
407 attroff (promptColor);
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
408 NeedRefresh = true;
24
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
409 return;
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
410 }
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
411
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
412 String prompt = prompt_string();
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
413 int displayLength = COLS - prompt.length() - 2;
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
414 String displayString = current_input();
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
415 int y = LINES - 2;
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
416
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
417 // If we're inputting a password, replace it with asterisks
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
418 if (CurrentInputState == INPUTSTATE_PASSWORD)
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
419 {
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
420 for (char& ch : displayString)
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
421 ch = '*';
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
422 }
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
423
17
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
424 // Ensure the cursor is within bounds
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
425 CursorPosition = clamp (CursorPosition, 0, displayString.length());
17
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
426
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
427 // Ensure that the cursor is always in view, adjust panning if this is not the case
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
428 if (CursorPosition > InputPanning + displayLength)
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
429 InputPanning = CursorPosition - displayLength; // cursor went too far right
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
430 else if (CursorPosition < InputPanning)
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
431 InputPanning = CursorPosition; // cursor went past the pan value to the left
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
432
25
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
433 // What part of the string to draw?
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
434 int start = InputPanning;
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
435 int end = min<int> (displayString.length(), start + displayLength);
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
436 assert (CursorPosition >= start and CursorPosition <= end);
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
437
25
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
438 // Render the input string
24
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
439 mvhline (LINES - 2, 0, ' ', COLS);
49
9e0f26f020e1 - fixed: horizontal input scrolling was broken
Teemu Piippo <crimsondusk64@gmail.com>
parents: 48
diff changeset
440 mvprintw (y, prompt.length() + 1, "%s", displayString.mid (start, end).chars());
25
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
441
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
442 // Render the prompt
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
443 attron (promptColor);
24
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
444 mvprintw (y, 0, "%s", prompt.chars());
25
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
445 attroff (promptColor);
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
446
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
447 // Store in memory where the cursor is now (so that we can re-draw it to position the terminal
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
448 // cursor).
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
449 CursorCharacter.ch = CursorPosition != 0 ? displayString[CursorPosition - 1] : '\0';
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
450 CursorCharacter.x = prompt.length() + (CursorPosition - InputPanning);
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
451 NeedRefresh = true;
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
452 NeedInputRender = false;
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
453 }
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
454
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
455 // -------------------------------------------------------------------------------------------------
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
456 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
457 void Interface::render_statusbar()
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
458 {
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
459 int color = color_pair (WHITE, BLUE);
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
460 int y = LINES - 1;
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
461 attron (color);
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
462 mvhline (y, 0, ' ', COLS);
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
463 mvprintw (y, 0, "%s", StatusBarText.chars());
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
464 attroff (color);
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
465 NeedRefresh = true;
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
466 NeedStatusBarRender = false;
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
467 }
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
468
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
469 // -------------------------------------------------------------------------------------------------
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
470 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
471 void Interface::update_statusbar()
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
472 {
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
473 String text;
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
474
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
475 switch (Session.state())
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
476 {
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
477 case RCON_DISCONNECTED:
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
478 text = "Disconnected.";
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
479 break;
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
480
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
481 case RCON_CONNECTING:
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
482 case RCON_AUTHENTICATING:
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
483 text = "Connecting to " + Session.address().to_string (IP_WITH_PORT) + "...";
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
484 break;
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
485
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
486 case RCON_CONNECTED:
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
487 {
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
488 String adminText;
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
489
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
490 if (Session.num_admins() == 0)
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
491 adminText = "No other admins";
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
492 else
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
493 adminText = format ("%1 other admin%s1", Session.num_admins());
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
494
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
495 text = format ("%1 | %2 | %3", Session.address().to_string (IP_WITH_PORT),
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
496 Session.level(), adminText);
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
497 }
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
498 break;
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
499 }
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
500
28
3cc042af3090 - added a help message to the statusbar
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
501 if (not text.is_empty())
3cc042af3090 - added a help message to the statusbar
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
502 text += " | ";
3cc042af3090 - added a help message to the statusbar
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
503
3cc042af3090 - added a help message to the statusbar
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
504 text += "^N to connect, ^Q to quit";
3cc042af3090 - added a help message to the statusbar
Teemu Piippo <crimsondusk64@gmail.com>
parents: 27
diff changeset
505
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
506 if (text != StatusBarText)
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
507 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
508 StatusBarText = text;
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
509 NeedStatusBarRender = true;
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
510 }
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
511 }
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
512
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
513 // -------------------------------------------------------------------------------------------------
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
514 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
515 void Interface::render_full()
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
516 {
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
517 update_statusbar();
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
518 render_titlebar();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
519 render_output();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
520 render_statusbar();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
521 render_input();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
522 render_nicklist();
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
523 }
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
524
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
525 // -------------------------------------------------------------------------------------------------
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
526 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
527 void Interface::position_cursor()
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
528 {
25
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
529 // This is only relevant if the input string is being drawn
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
530 if (CurrentInputState == INPUTSTATE_CONFIRM_DISCONNECTION)
25
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
531 return;
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
532
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
533 int y = LINES - 2;
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
534
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
535 if (CursorCharacter.ch != '\0')
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
536 mvprintw (y, CursorCharacter.x, "%c", CursorCharacter.ch);
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
537 else
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
538 mvprintw (y, prompt_string().length(), " ");
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
539 }
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
540
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
541 // -------------------------------------------------------------------------------------------------
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
542 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
543 int Interface::find_previous_word()
43
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
544 {
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
545 const String& input = current_input();
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
546 int pos = CursorPosition;
43
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
547
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
548 // Move past whitespace
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
549 while (pos > 0 and isspace (input[pos - 1]))
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
550 pos--;
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
551
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
552 // Move past the word
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
553 while (pos > 0 and not isspace (input[pos - 1]))
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
554 pos--;
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
555
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
556 return pos;
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
557 }
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
558
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
559 // -------------------------------------------------------------------------------------------------
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
560 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
561 int Interface::find_next_word()
43
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
562 {
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
563 const String& input = current_input();
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
564 int pos = CursorPosition;
43
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
565
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
566 // Move past current whitespace
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
567 while (pos < input.length() and isspace (input[pos]))
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
568 pos++;
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
569
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
570 // Move past the word
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
571 while (input[pos] != '\0' and not isspace (input[pos]))
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
572 pos++;
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
573
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
574 return pos;
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
575 }
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
576
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
577 // -------------------------------------------------------------------------------------------------
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
578 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
579 void Interface::yank (int a, int b)
53
8f1a6f40d1b4 - added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
580 {
8f1a6f40d1b4 - added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
581 if (a >= b)
8f1a6f40d1b4 - added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
582 return;
8f1a6f40d1b4 - added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
583
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
584 if (CursorPosition > a and CursorPosition <= b)
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
585 CursorPosition = a;
53
8f1a6f40d1b4 - added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
586
8f1a6f40d1b4 - added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
587 String& input = mutable_current_input();
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
588 PasteBuffer = input.mid (a, b);
53
8f1a6f40d1b4 - added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
589 input.remove (a, b - a);
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
590 NeedInputRender = true;
53
8f1a6f40d1b4 - added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
591 }
8f1a6f40d1b4 - added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
592
8f1a6f40d1b4 - added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
593 // -------------------------------------------------------------------------------------------------
8f1a6f40d1b4 - added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
594 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
595 void Interface::handle_input()
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
596 {
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
597 int ch = ::getch();
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
598
33
bb209480d0ec - handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
599 if (ch == KEY_RESIZE)
bb209480d0ec - handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
600 {
bb209480d0ec - handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
601 ::clear();
bb209480d0ec - handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
602 render_full();
bb209480d0ec - handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
603 return;
bb209480d0ec - handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
604 }
bb209480d0ec - handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 32
diff changeset
605
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
606 if (CurrentInputState == INPUTSTATE_CONFIRM_DISCONNECTION)
24
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
607 {
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
608 if (ch == 'y' or ch == 'Y')
30
21fba5183768 - added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
609 {
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
610 Session.disconnect();
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
611 DisconnectConfirmFunction();
30
21fba5183768 - added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
612 }
24
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
613 else if (ch == 'n' or ch == 'N')
25
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
614 set_input_state (INPUTSTATE_NORMAL);
30
21fba5183768 - added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
615
24
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
616 return;
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
617 }
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
618
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
619 if (ch >= 0x20 and ch <= 0x7E)
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
620 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
621 mutable_current_input().insert (CursorPosition++, char (ch));
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
622 NeedInputRender = true;
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
623 }
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
624 else switch (ch)
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
625 {
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
626 case 'Q' - 'A' + 1: // ^Q
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
627 switch (CurrentInputState)
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
628 {
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
629 case INPUTSTATE_CONFIRM_DISCONNECTION:
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
630 break;
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
631
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
632 case INPUTSTATE_NORMAL:
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
633 safe_disconnect ([&]()
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
634 {
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
635 if (Session.is_active())
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
636 {
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
637 Session.disconnect();
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
638 set_input_state (INPUTSTATE_NORMAL);
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
639 }
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
640 else
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
641 {
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
642 endwin();
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
643 throw Exitception();
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
644 }
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
645 });
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
646 break;
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
647
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
648 case INPUTSTATE_PASSWORD:
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
649 set_input_state (INPUTSTATE_ADDRESS);
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
650 break;
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
651
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
652 case INPUTSTATE_ADDRESS:
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
653 set_input_state (INPUTSTATE_NORMAL);
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
654 }
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
655 break;
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 25
diff changeset
656
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
657 case KEY_LEFT:
42
9699687081df - added readline shortcuts: ^B, ^F, ^A, ^E, ^D (aliases to keyboard presses), ^U, ^K (new functionality)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
658 case 'B' - 'A' + 1: // readline ^B
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
659 if (CursorPosition > 0)
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
660 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
661 CursorPosition--;
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
662 NeedInputRender = true;
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
663 }
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
664 break;
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
665
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
666 case KEY_RIGHT:
42
9699687081df - added readline shortcuts: ^B, ^F, ^A, ^E, ^D (aliases to keyboard presses), ^U, ^K (new functionality)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
667 case 'F' - 'A' + 1: // readline ^F
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
668 if (CursorPosition < current_input().length())
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
669 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
670 CursorPosition++;
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
671 NeedInputRender = true;
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
672 }
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
673 break;
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
674
31
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
675 case KEY_DOWN:
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
676 case KEY_UP:
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
677 move_input_cursor (ch == KEY_DOWN ? -1 : 1);
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
678 break;
b5b5a6a96d91 - added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
679
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
680 case KEY_HOME:
42
9699687081df - added readline shortcuts: ^B, ^F, ^A, ^E, ^D (aliases to keyboard presses), ^U, ^K (new functionality)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
681 case 'A' - 'A' + 1: // readline ^A
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
682 if (CursorPosition != 0)
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
683 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
684 CursorPosition = 0;
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
685 NeedInputRender = true;
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
686 }
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
687 break;
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
688
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
689 case KEY_END:
42
9699687081df - added readline shortcuts: ^B, ^F, ^A, ^E, ^D (aliases to keyboard presses), ^U, ^K (new functionality)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
690 case 'E' - 'A' + 1: // readline ^E
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
691 if (CursorPosition != current_input().length())
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
692 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
693 CursorPosition = current_input().length();
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
694 NeedInputRender = true;
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
695 }
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
696 break;
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
697
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
698 case KEY_BACKSPACE:
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
699 if (CursorPosition > 0)
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
700 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
701 mutable_current_input().remove_at (--CursorPosition);
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
702 NeedInputRender = true;
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
703 }
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
704 break;
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
705
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
706 case KEY_DC:
42
9699687081df - added readline shortcuts: ^B, ^F, ^A, ^E, ^D (aliases to keyboard presses), ^U, ^K (new functionality)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
707 case 'D' - 'A' + 1: // readline ^D
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
708 if (CursorPosition < current_input().length())
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
709 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
710 mutable_current_input().remove_at (CursorPosition);
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
711 NeedInputRender = true;
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
712 }
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
713 break;
16
33bac54867bf - added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
714
33bac54867bf - added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
715 case KEY_PPAGE:
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
716 OutputScroll += min (g_pageSize, LINES / 2);
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
717 NeedOutputRender = true;
16
33bac54867bf - added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
718 break;
33bac54867bf - added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
719
33bac54867bf - added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
720 case KEY_NPAGE:
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
721 OutputScroll -= min (g_pageSize, LINES / 2);
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
722 NeedOutputRender = true;
17
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
723 break;
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
724
42
9699687081df - added readline shortcuts: ^B, ^F, ^A, ^E, ^D (aliases to keyboard presses), ^U, ^K (new functionality)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
725 case 'U' - 'A' + 1: // readline ^U - delete from start to cursor
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
726 if (CursorPosition > 0)
42
9699687081df - added readline shortcuts: ^B, ^F, ^A, ^E, ^D (aliases to keyboard presses), ^U, ^K (new functionality)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
727 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
728 yank (0, CursorPosition);
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
729 CursorPosition = 0;
42
9699687081df - added readline shortcuts: ^B, ^F, ^A, ^E, ^D (aliases to keyboard presses), ^U, ^K (new functionality)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
730 }
9699687081df - added readline shortcuts: ^B, ^F, ^A, ^E, ^D (aliases to keyboard presses), ^U, ^K (new functionality)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
731 break;
9699687081df - added readline shortcuts: ^B, ^F, ^A, ^E, ^D (aliases to keyboard presses), ^U, ^K (new functionality)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
732
9699687081df - added readline shortcuts: ^B, ^F, ^A, ^E, ^D (aliases to keyboard presses), ^U, ^K (new functionality)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
733 case 'K' - 'A' + 1: // readline ^K - delete from cursor to end
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
734 yank (CursorPosition, mutable_current_input().length());
42
9699687081df - added readline shortcuts: ^B, ^F, ^A, ^E, ^D (aliases to keyboard presses), ^U, ^K (new functionality)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
735 break;
9699687081df - added readline shortcuts: ^B, ^F, ^A, ^E, ^D (aliases to keyboard presses), ^U, ^K (new functionality)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 34
diff changeset
736
44
693d7751fff0 - added readline alt-d and ^w support (delete till word boundaries)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 43
diff changeset
737 case 'W' - 'A' + 1: // readline ^W - delete from previous word bounary to current
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
738 yank (find_previous_word(), CursorPosition);
53
8f1a6f40d1b4 - added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
739 break;
44
693d7751fff0 - added readline alt-d and ^w support (delete till word boundaries)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 43
diff changeset
740
53
8f1a6f40d1b4 - added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
741 case 'Y' - 'A' + 1: // readline ^Y - paste previously deleted text
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
742 if (not PasteBuffer.is_empty())
53
8f1a6f40d1b4 - added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 52
diff changeset
743 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
744 mutable_current_input().insert (CursorPosition, PasteBuffer);
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
745 CursorPosition += PasteBuffer.length();
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
746 NeedInputRender = true;
44
693d7751fff0 - added readline alt-d and ^w support (delete till word boundaries)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 43
diff changeset
747 }
17
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
748 break;
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
749
41
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
750 case '\t':
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
751 {
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
752 int space = current_input().find (" ");
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
753
71
4f7c2c944637 Merge tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 69 41
diff changeset
754 if (CurrentInputState == INPUTSTATE_NORMAL
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
755 and CursorPosition > 0
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
756 and (space == -1 or space >= CursorPosition))
41
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
757 {
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
758 String start = current_input().mid (0, CursorPosition);
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
759 Session.request_tab_complete (start);
41
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
760 }
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
761 }
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
762 break;
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
763
17
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
764 case '\n':
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
765 case KEY_ENTER:
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
766 switch (CurrentInputState)
17
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
767 {
24
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
768 case INPUTSTATE_CONFIRM_DISCONNECTION:
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
769 break; // handled above
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
770
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
771 case INPUTSTATE_ADDRESS:
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
772 try
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
773 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
774 CurrentAddress = IPAddress::from_string (current_input());
24
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
775 }
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
776 catch (std::exception& e)
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
777 {
50
874bbfa55da8 - fixed: IPAddress::StringParseError did not inherit from std::exception and was thus not caught properly
Teemu Piippo <crimsondusk64@gmail.com>
parents: 49
diff changeset
778 print ("%1\n", e.what());
24
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
779 return;
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
780 }
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
781
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
782 if (CurrentAddress.port == 0)
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
783 CurrentAddress.port = 10666;
24
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
784
25
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
785 set_input_state (INPUTSTATE_PASSWORD);
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
786 break;
24
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
787
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
788 case INPUTSTATE_PASSWORD:
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
789 if (CurrentInputState == INPUTSTATE_PASSWORD and not current_input().is_empty())
24
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
790 {
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
791 Session.disconnect();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
792 Session.set_password (current_input());
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
793 Session.connect (CurrentAddress);
25
88b41eea08e0 - cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
794 set_input_state (INPUTSTATE_NORMAL);
24
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
795 }
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
796 break;
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
797
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
798 case INPUTSTATE_NORMAL:
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
799 if (Session.send_command (current_input()))
24
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
800 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
801 InputHistory.insert (0, "");
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
802 NeedInputRender = true;
24
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
803 }
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
804 break;
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
805 }
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
806 break;
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
807
e651d02802c0 - the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents: 23
diff changeset
808 case 'N' - 'A' + 1: // ^N
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
809 if (CurrentInputState == INPUTSTATE_NORMAL)
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
810 safe_disconnect ([&]() {set_input_state (INPUTSTATE_ADDRESS);});
16
33bac54867bf - added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
811 break;
43
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
812
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
813 case '\e': // Escape
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
814 // We may have an alt key coming
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
815 ch = ::getch();
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
816
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
817 if (ch != ERR)
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
818 {
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
819 switch (ch)
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
820 {
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
821 case 'b':
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
822 case 'B':
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
823 // readline alt-b - move one word to the left
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
824 CursorPosition = find_previous_word();
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
825 NeedInputRender = true;
43
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
826 break;
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
827
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
828 case 'f':
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
829 case 'F':
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
830 // readline alt-f - move one word to the right
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
831 CursorPosition = find_next_word();
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
832 NeedInputRender = true;
43
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
833 break;
44
693d7751fff0 - added readline alt-d and ^w support (delete till word boundaries)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 43
diff changeset
834
693d7751fff0 - added readline alt-d and ^w support (delete till word boundaries)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 43
diff changeset
835 case 'd':
693d7751fff0 - added readline alt-d and ^w support (delete till word boundaries)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 43
diff changeset
836 case 'D':
693d7751fff0 - added readline alt-d and ^w support (delete till word boundaries)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 43
diff changeset
837 // readline alt-d - delete from here till next word boundary
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
838 yank (CursorPosition, find_next_word());
44
693d7751fff0 - added readline alt-d and ^w support (delete till word boundaries)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 43
diff changeset
839 break;
43
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
840 }
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
841 }
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
842 else
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
843 {
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
844 // No alt-key, handle pure escape
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
845 if (CurrentInputState == INPUTSTATE_PASSWORD)
43
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
846 set_input_state (INPUTSTATE_ADDRESS);
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
847 else if (CurrentInputState == INPUTSTATE_ADDRESS)
43
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
848 set_input_state (INPUTSTATE_NORMAL);
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
849 }
0bc07f54f522 - added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 42
diff changeset
850 break;
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
851 }
41
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
852
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
853 render();
17
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
854 }
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
855
17
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
856 // -------------------------------------------------------------------------------------------------
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
857 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
858 void Interface::render()
17
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
859 {
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
860 if (NeedStatusBarRender) render_statusbar();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
861 if (NeedInputRender) render_input();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
862 if (NeedOutputRender) render_output();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
863 if (NeedNicklistRender) render_nicklist();
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
864
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
865 if (NeedRefresh)
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
866 {
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
867 position_cursor();
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
868 refresh();
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
869 NeedRefresh = false;
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
870 }
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
871 }
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
872
17
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
873 // -------------------------------------------------------------------------------------------------
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 16
diff changeset
874 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
875 void Interface::print_to_console (String a)
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
876 {
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
877 // Zandronum sometimes sends color codes as "\\c" and sometimes as "\x1C".
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
878 // Let's correct that on our end and hope this won't cause conflicts.
32
ee770597a281 - added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
879 a.replace ("\\c", "\x1C");
ee770597a281 - added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 31
diff changeset
880
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
881 for (char ch : a)
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
882 {
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
883 if (ch == '\n')
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
884 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
885 OutputLines.last().finalize();
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
886 OutputLines << ColoredLine();
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
887 continue;
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
888 }
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
889
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
890 if (OutputLines.last().length() == 0)
51
481073b016a9 - added timestamps to output
Teemu Piippo <crimsondusk64@gmail.com>
parents: 50
diff changeset
891 {
481073b016a9 - added timestamps to output
Teemu Piippo <crimsondusk64@gmail.com>
parents: 50
diff changeset
892 time_t now;
481073b016a9 - added timestamps to output
Teemu Piippo <crimsondusk64@gmail.com>
parents: 50
diff changeset
893 time (&now);
481073b016a9 - added timestamps to output
Teemu Piippo <crimsondusk64@gmail.com>
parents: 50
diff changeset
894 char timestamp[32];
481073b016a9 - added timestamps to output
Teemu Piippo <crimsondusk64@gmail.com>
parents: 50
diff changeset
895 strftime (timestamp, sizeof timestamp, "[%H:%M:%S] ", localtime (&now));
481073b016a9 - added timestamps to output
Teemu Piippo <crimsondusk64@gmail.com>
parents: 50
diff changeset
896
481073b016a9 - added timestamps to output
Teemu Piippo <crimsondusk64@gmail.com>
parents: 50
diff changeset
897 for (char* cp = timestamp; *cp != '\0'; ++cp)
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
898 OutputLines.last().add_char (*cp);
51
481073b016a9 - added timestamps to output
Teemu Piippo <crimsondusk64@gmail.com>
parents: 50
diff changeset
899 }
481073b016a9 - added timestamps to output
Teemu Piippo <crimsondusk64@gmail.com>
parents: 50
diff changeset
900
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
901 OutputLines.last().add_char (ch);
15
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
902 }
33da84af4bba - log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents: 14
diff changeset
903
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
904 NeedOutputRender = true;
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
905 }
30
21fba5183768 - added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
906
21fba5183768 - added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
907 // -------------------------------------------------------------------------------------------------
21fba5183768 - added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
908 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
909 void Interface::connect (String address, String password)
30
21fba5183768 - added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
910 {
21fba5183768 - added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
911 try
21fba5183768 - added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
912 {
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
913 CurrentAddress = IPAddress::from_string (address);
30
21fba5183768 - added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
914 }
21fba5183768 - added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
915 catch (std::exception& e)
21fba5183768 - added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
916 {
50
874bbfa55da8 - fixed: IPAddress::StringParseError did not inherit from std::exception and was thus not caught properly
Teemu Piippo <crimsondusk64@gmail.com>
parents: 49
diff changeset
917 print ("%1\n", e.what());
30
21fba5183768 - added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
918 return;
21fba5183768 - added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
919 }
21fba5183768 - added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 29
diff changeset
920
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
921 if (CurrentAddress.port == 0)
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
922 CurrentAddress.port = 10666;
34
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
923
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
924 Session.disconnect();
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
925 Session.set_password (password);
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
926 Session.connect (CurrentAddress);
34
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
927 }
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
928
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
929 // -------------------------------------------------------------------------------------------------
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
930 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
931 void Interface::set_player_names (const StringList& names)
34
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
932 {
78
c1d43ade656e Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
933 PlayerNames.clear();
c1d43ade656e Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
934
c1d43ade656e Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
935 for (const String& name : names)
c1d43ade656e Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
936 {
c1d43ade656e Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
937 ColoredLine coloredname;
c1d43ade656e Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
938 coloredname.add_string (name);
c1d43ade656e Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
939 coloredname.finalize();
c1d43ade656e Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
940 PlayerNames.append (coloredname);
c1d43ade656e Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
941 }
c1d43ade656e Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
942
69
eb4c25284a19 Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents: 58
diff changeset
943 NeedNicklistRender = true;
34
3caf69e7350b - added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 33
diff changeset
944 }
41
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
945
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
946 // -------------------------------------------------------------------------------------------------
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
947 //
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
948 void Interface::tab_complete (const String& part, String complete)
41
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
949 {
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
950 String& input = mutable_current_input();
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
951
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
952 if (input.starts_with (part))
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
953 {
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
954 if (input[part.length()] != ' ')
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
955 complete += ' ';
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
956
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
957 input.replace (0, part.length(), complete);
72
1b9c53e0c846 Massive refactor
Teemu Piippo <crimsondusk64@gmail.com>
parents: 71
diff changeset
958 CursorPosition = complete.length();
71
4f7c2c944637 Merge tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 69 41
diff changeset
959 NeedInputRender = true;
41
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
960 }
9ab869656b9e - re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents: 40
diff changeset
961 }
80
f992b027374b Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents: 78
diff changeset
962
f992b027374b Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents: 78
diff changeset
963 // -------------------------------------------------------------------------------------------------
f992b027374b Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents: 78
diff changeset
964 //
f992b027374b Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents: 78
diff changeset
965 void Interface::disconnected()
f992b027374b Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents: 78
diff changeset
966 {
f992b027374b Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents: 78
diff changeset
967 Title = "";
f992b027374b Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents: 78
diff changeset
968 update_statusbar();
f992b027374b Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents: 78
diff changeset
969 render_titlebar();
f992b027374b Added support for SVRC_YOUREDISCONNECTED
Teemu Piippo <crimsondusk64@gmail.com>
parents: 78
diff changeset
970 }

mercurial