Mon, 15 Dec 2014 04:10:27 +0200
- handle resizing 8-)
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | Copyright 2014 Teemu Piippo |
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> |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | #include "interface.h" |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
33 | #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
|
34 | #include "network/ipaddress.h" |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | |
16
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
36 | enum { PAGE_SIZE = 10 }; |
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
37 | |
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
|
38 | enum InputState |
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
|
39 | { |
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
|
40 | INPUTSTATE_NORMAL, |
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
|
41 | 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
|
42 | INPUTSTATE_PASSWORD, |
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
|
43 | 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
|
44 | }; |
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
|
45 | |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
46 | static StringList g_input; |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
47 | static int g_inputCursor = 0; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | static int g_cursor = 0; |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | static int g_pan = 0; |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | static bool g_needRefresh = false; |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
51 | static bool g_needStatusBarRender = false; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
52 | static bool g_needInputRender = false; |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
53 | static bool g_needOutputRender = false; |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
54 | static struct { char ch; int x; } g_cursorChar; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
55 | static Vector<String> g_output = {""}; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
56 | static int g_outputScroll = 0; |
23
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
57 | static String g_title; |
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
|
58 | static InputState g_inputState = INPUTSTATE_NORMAL; |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
59 | static Function<void (void)> g_disconnectConfirmFunction = nullptr; |
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
|
60 | static IPAddress g_address; |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
61 | static String g_statusBarText; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | |
32
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
63 | static const struct { Color color; bool bold; } g_colorCodes['v' - 'a' + 1] = |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
64 | { |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
65 | { RED, true }, // a - brick |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
66 | { YELLOW, true }, // b - tan |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
67 | { WHITE, false }, // c - gray |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
68 | { GREEN, true }, // d - light green |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
69 | { YELLOW, false }, // e - brown |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
70 | { YELLOW, true }, // f - gold yellow |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
71 | { RED, true }, // g - bright red |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
72 | { BLUE, false }, // h - dark blue |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
73 | { YELLOW, false }, // i - orange |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
74 | { WHITE, true }, // j - white |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
75 | { YELLOW, true }, // k - fire yellow |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
76 | { DEFAULT, false }, // l - untranslated |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
77 | { BLACK, false }, // m - black |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
78 | { BLUE, true }, // n - light blue |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
79 | { YELLOW, true }, // o - cream |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
80 | { GREEN, true }, // p - olive green |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
81 | { GREEN, false }, // q - dark green |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
82 | { RED, false }, // r - dark red |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
83 | { YELLOW, false }, // s - dark brown |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
84 | { MAGENTA, false }, // t - purple |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
85 | { BLACK, true }, // u - dark gray |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
86 | { CYAN, true }, // v - cyan |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
87 | }; |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
88 | |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | // ------------------------------------------------------------------------------------------------- |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | // |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | static FUNCTION |
20
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
92 | interface_color_pair (Color fg, Color bg) -> int |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
93 | { |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
94 | 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
|
95 | } |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
96 | |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
97 | // ------------------------------------------------------------------------------------------------- |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
98 | // |
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
|
99 | static FUNCTION |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
100 | current_input() -> const String& |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
101 | { |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
102 | return g_input[g_inputCursor]; |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
103 | } |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
104 | |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
105 | // ------------------------------------------------------------------------------------------------- |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
106 | // |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
107 | // 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
|
108 | // |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
109 | static FUNCTION |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
110 | detach_input() -> void |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
111 | { |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
112 | if (g_inputCursor > 0) |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
113 | { |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
114 | g_input[0] = current_input(); |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
115 | g_inputCursor = 0; |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
116 | } |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
117 | } |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
118 | |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
119 | // ------------------------------------------------------------------------------------------------- |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
120 | // 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
|
121 | // |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
122 | static FUNCTION |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
123 | mutable_current_input() -> String& |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
124 | { |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
125 | detach_input(); |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
126 | return g_input[g_inputCursor]; |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
127 | } |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
128 | |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
129 | // ------------------------------------------------------------------------------------------------- |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
130 | // |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
131 | static FUNCTION |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
132 | move_input_cursor (int delta) -> void |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
133 | { |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
134 | // No input history when inputting addresses or passwords |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
135 | if (g_inputState != INPUTSTATE_NORMAL) |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
136 | { |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
137 | g_inputCursor = 0; |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
138 | return; |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
139 | } |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
140 | |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
141 | int oldcursor = g_inputCursor; |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
142 | g_inputCursor = clamp (g_inputCursor + delta, 0, g_input.size() - 1); |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
143 | |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
144 | if (g_inputCursor != oldcursor) |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
145 | { |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
146 | g_cursor = current_input().length(); |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
147 | g_needInputRender = true; |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
148 | } |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
149 | } |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
150 | |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
151 | // ------------------------------------------------------------------------------------------------- |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
152 | // |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
153 | static FUNCTION |
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
|
154 | interface_prompt_string() -> String |
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
|
155 | { |
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
|
156 | 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
|
157 | |
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
|
158 | switch (g_inputState) |
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
|
159 | { |
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
|
160 | 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
|
161 | 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
|
162 | 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
|
163 | 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
|
164 | } |
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
|
165 | |
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
|
166 | 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
|
167 | } |
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
|
168 | |
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
|
169 | // ------------------------------------------------------------------------------------------------- |
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
|
170 | // |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
171 | static FUNCTION |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
172 | set_input_state (InputState newstate) -> void |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
173 | { |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
174 | // 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
|
175 | if (newstate != INPUTSTATE_CONFIRM_DISCONNECTION |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
176 | and g_inputState != INPUTSTATE_CONFIRM_DISCONNECTION) |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
177 | { |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
178 | g_inputCursor = 0; |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
179 | mutable_current_input().clear(); |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
180 | } |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
181 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
182 | switch (newstate) |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
183 | { |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
184 | case INPUTSTATE_ADDRESS: |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
185 | if (g_address.host != 0) |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
186 | mutable_current_input() = g_address.to_string (IP_WITH_PORT); |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
187 | break; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
188 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
189 | default: |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
190 | break; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
191 | } |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
192 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
193 | g_inputState = newstate; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
194 | g_needInputRender = true; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
195 | } |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
196 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
197 | // ------------------------------------------------------------------------------------------------- |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
198 | // |
20
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
199 | FUNCTION |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
200 | Interface::initialize() -> void |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
201 | { |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
202 | ::initscr(); |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
203 | ::start_color(); |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
204 | ::raw(); |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
205 | ::keypad (stdscr, true); |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
206 | ::noecho(); |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
207 | ::refresh(); |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
208 | ::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
|
209 | ::use_default_colors(); |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
210 | g_input.clear(); |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
211 | g_input << ""; |
23
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
212 | g_title = format (APPNAME " %1 (%2)", full_version_string(), changeset_date_string()); |
20
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
213 | |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
214 | 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
|
215 | 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
|
216 | { |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
217 | init_pair ((i * NUM_COLORS + j), |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
218 | (i == DEFAULT) ? -1 : i, |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
219 | (j == DEFAULT) ? -1 : j); |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
220 | } |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
221 | |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
222 | render_full(); |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
223 | refresh(); |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
224 | g_needRefresh = false; |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
225 | } |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
226 | |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
227 | // ------------------------------------------------------------------------------------------------- |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
228 | // |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
229 | static FUNCTION |
23
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
230 | interface_render_titlebar() -> void |
20
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
231 | { |
23
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
232 | if (g_title.length() <= COLS) |
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
233 | { |
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
234 | int pair = interface_color_pair (WHITE, BLUE); |
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
235 | int startx = (COLS - g_title.length()) / 2; |
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
236 | int endx = startx + g_title.length(); |
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
237 | attron (pair); |
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
238 | mvprintw (0, startx, "%s", g_title.chars()); |
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
239 | mvhline (0, 0, ' ', startx); |
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
240 | mvhline (0, endx, ' ', COLS - endx); |
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
241 | attroff (pair); |
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
242 | } |
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
243 | |
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
244 | g_needRefresh = true; |
20
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
245 | } |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
246 | |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
247 | // ------------------------------------------------------------------------------------------------- |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
248 | // |
23
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
249 | FUNCTION |
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
250 | Interface::set_title (const String& title) -> void |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
251 | { |
23
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
252 | g_title = title; |
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
253 | interface_render_titlebar(); |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
254 | } |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
255 | |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
256 | // ------------------------------------------------------------------------------------------------- |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
257 | // |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
258 | static FUNCTION |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
259 | safe_disconnect (Function<void()> afterwards) -> void |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
260 | { |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
261 | if (RCONSession::get_session()->is_active()) |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
262 | { |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
263 | g_disconnectConfirmFunction = afterwards; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
264 | set_input_state (INPUTSTATE_CONFIRM_DISCONNECTION); |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
265 | } |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
266 | else |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
267 | afterwards(); |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
268 | } |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
269 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
270 | // ------------------------------------------------------------------------------------------------- |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
271 | // |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
272 | static FUNCTION |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
273 | interface_render_output() -> void |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
274 | { |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
275 | int height = LINES - 3; |
16
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
276 | |
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
277 | // ensure we're within bounds |
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
278 | if (g_outputScroll + height >= g_output.size()) |
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
279 | g_outputScroll = g_output.size() - height - 1; |
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
280 | else if (g_outputScroll < 0) |
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
281 | g_outputScroll = 0; |
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
282 | |
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
283 | int start = max (0, g_output.size() - height - 1 - g_outputScroll); |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
284 | int end = min (g_output.size(), start + height); |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
285 | int y = 1; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
286 | assert (end - start <= height); |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
287 | |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
288 | for (int i = start; i < end; ++i) |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
289 | { |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
290 | mvhline (y, 0, ' ', COLS); |
32
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
291 | int activeColor = -1; |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
292 | bool boldActive = false; |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
293 | int x = 0; |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
294 | |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
295 | for (int j = 0; j < g_output[i].length(); ++j) |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
296 | { |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
297 | char ch = g_output[i][j]; |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
298 | |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
299 | if (ch == '\x1C' and j + 1 < g_output[i].length()) |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
300 | { |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
301 | if (activeColor != -1) |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
302 | attroff (activeColor); |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
303 | |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
304 | if (boldActive) |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
305 | attroff (A_BOLD); |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
306 | |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
307 | char colorChar = g_output[i][j + 1]; |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
308 | |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
309 | if (colorChar >= 'a' and colorChar <= 'v' and colorChar != 'l') |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
310 | { |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
311 | auto colorInfo = g_colorCodes[colorChar - 'a']; |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
312 | activeColor = interface_color_pair (colorInfo.color, DEFAULT); |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
313 | boldActive = colorInfo.bold; |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
314 | attron (activeColor); |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
315 | |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
316 | if (boldActive) |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
317 | attron (A_BOLD); |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
318 | } |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
319 | |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
320 | j++; |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
321 | continue; |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
322 | } |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
323 | |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
324 | mvaddch (y, x++, g_output[i][j]); |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
325 | } |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
326 | |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
327 | if (activeColor != -1) |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
328 | attroff (activeColor); |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
329 | |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
330 | if (boldActive) |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
331 | attroff (A_BOLD); |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
332 | |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
333 | ++y; |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
334 | } |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
335 | |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
336 | g_needRefresh = true; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
337 | } |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
338 | |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
339 | // ------------------------------------------------------------------------------------------------- |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
340 | // |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
341 | static FUNCTION |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
342 | interface_render_input() -> void |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
343 | { |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
344 | int promptColor = interface_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
|
345 | |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
346 | // 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
|
347 | // just the confirmation message. |
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
|
348 | if (g_inputState == 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
|
349 | { |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
350 | 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
|
351 | 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
|
352 | 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
|
353 | attroff (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
|
354 | 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
|
355 | } |
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
|
356 | |
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
|
357 | String prompt = interface_prompt_string(); |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
358 | int displayLength = COLS - prompt.length() - 2; |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
359 | 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
|
360 | int y = LINES - 2; |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
361 | |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
362 | // If we're inputting a password, replace it with asterisks |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
363 | if (g_inputState == INPUTSTATE_PASSWORD) |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
364 | { |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
365 | for (char& ch : displayString) |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
366 | ch = '*'; |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
367 | } |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
368 | |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
369 | // Ensure the cursor is within bounds |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
370 | g_cursor = clamp (g_cursor, 0, displayString.length()); |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
371 | |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
372 | // Ensure that the cursor is always in view, adjust panning if this is not the case |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
373 | if (g_cursor > g_pan + displayLength) |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
374 | g_pan = g_cursor - displayLength; // cursor went too far right |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
375 | else if (g_cursor < g_pan) |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
376 | g_pan = g_cursor; // cursor went past the pan value to the left |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
377 | |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
378 | // What part of the string to draw? |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
379 | int start = g_pan; |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
380 | int end = min<int> (displayString.length(), start + displayLength); |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
381 | assert (g_cursor >= start and g_cursor <= end); |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
382 | |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
383 | // 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
|
384 | mvhline (LINES - 2, 0, ' ', COLS); |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
385 | mvprintw (y, prompt.length() + 1, "%s", displayString.chars()); |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
386 | |
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
387 | // Render the prompt |
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
388 | 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
|
389 | mvprintw (y, 0, "%s", prompt.chars()); |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
390 | attroff (promptColor); |
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
391 | |
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
392 | // 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
|
393 | // cursor). |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
394 | g_cursorChar.ch = g_cursor != 0 ? displayString[g_cursor - 1] : '\0'; |
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
|
395 | g_cursorChar.x = prompt.length() + (g_cursor - g_pan); |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
396 | g_needRefresh = true; |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
397 | g_needInputRender = false; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
398 | } |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
399 | |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
400 | // ------------------------------------------------------------------------------------------------- |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
401 | // |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
402 | static FUNCTION |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
403 | interface_render_statusbar() -> void |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
404 | { |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
405 | int color = interface_color_pair (WHITE, BLUE); |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
406 | int y = LINES - 1; |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
407 | attron (color); |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
408 | mvhline (y, 0, ' ', COLS); |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
409 | mvprintw (y, 0, "%s", g_statusBarText.chars()); |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
410 | attroff (color); |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
411 | g_needRefresh = true; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
412 | g_needStatusBarRender = false; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
413 | } |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
414 | |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
415 | // ------------------------------------------------------------------------------------------------- |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
416 | // |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
417 | FUNCTION |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
418 | Interface::update_statusbar() -> void |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
419 | { |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
420 | String text; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
421 | RCONSession* session = RCONSession::get_session(); |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
422 | |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
423 | switch (session->state()) |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
424 | { |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
425 | case RCON_DISCONNECTED: |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
426 | text = "Disconnected."; |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
427 | break; |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
428 | |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
429 | case RCON_CONNECTING: |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
430 | case RCON_AUTHENTICATING: |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
431 | text = "Connecting to " + session->address().to_string (IP_WITH_PORT) + "..."; |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
432 | break; |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
433 | |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
434 | case RCON_CONNECTED: |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
435 | { |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
436 | String adminText = (session->num_admins() == 0) ? "No other admins" |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
437 | : format ("%1 other admin%s1", session->num_admins()); |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
438 | text = format ("%1 | %2 | %3", session->address().to_string (IP_WITH_PORT), |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
439 | session->level(), adminText); |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
440 | } |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
441 | break; |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
442 | } |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
443 | |
28
3cc042af3090
- added a help message to the statusbar
Teemu Piippo <crimsondusk64@gmail.com>
parents:
27
diff
changeset
|
444 | if (not text.is_empty()) |
3cc042af3090
- added a help message to the statusbar
Teemu Piippo <crimsondusk64@gmail.com>
parents:
27
diff
changeset
|
445 | text += " | "; |
3cc042af3090
- added a help message to the statusbar
Teemu Piippo <crimsondusk64@gmail.com>
parents:
27
diff
changeset
|
446 | |
3cc042af3090
- added a help message to the statusbar
Teemu Piippo <crimsondusk64@gmail.com>
parents:
27
diff
changeset
|
447 | text += "^N to connect, ^Q to quit"; |
3cc042af3090
- added a help message to the statusbar
Teemu Piippo <crimsondusk64@gmail.com>
parents:
27
diff
changeset
|
448 | |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
449 | if (text != g_statusBarText) |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
450 | { |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
451 | g_statusBarText = text; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
452 | g_needStatusBarRender = true; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
453 | } |
14
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 | // ------------------------------------------------------------------------------------------------- |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
457 | // |
20
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
458 | FUNCTION |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
459 | Interface::render_full() -> void |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
460 | { |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
461 | update_statusbar(); |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
462 | interface_render_titlebar(); |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
463 | interface_render_output(); |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
464 | interface_render_statusbar(); |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
465 | interface_render_input(); |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
466 | } |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
467 | |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
468 | // ------------------------------------------------------------------------------------------------- |
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 | static FUNCTION |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
471 | interface_position_cursor() -> void |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
472 | { |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
473 | // This is only relevant if the input string is being drawn |
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
474 | if (g_inputState == INPUTSTATE_CONFIRM_DISCONNECTION) |
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
475 | return; |
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
476 | |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
477 | int y = LINES - 2; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
478 | |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
479 | if (g_cursorChar.ch != '\0') |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
480 | mvprintw (y, g_cursorChar.x, "%c", g_cursorChar.ch); |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
481 | else |
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
|
482 | mvprintw (y, interface_prompt_string().length(), " "); |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
483 | } |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
484 | |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
485 | // ------------------------------------------------------------------------------------------------- |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
486 | // |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
487 | FUNCTION |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
488 | Interface::handle_input() -> void |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
489 | { |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
490 | int ch = ::getch(); |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
491 | |
33
bb209480d0ec
- handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
492 | if (ch == KEY_RESIZE) |
bb209480d0ec
- handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
493 | { |
bb209480d0ec
- handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
494 | ::clear(); |
bb209480d0ec
- handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
495 | render_full(); |
bb209480d0ec
- handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
496 | return; |
bb209480d0ec
- handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
497 | } |
bb209480d0ec
- handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
498 | |
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
|
499 | if (g_inputState == 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
|
500 | { |
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
|
501 | 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
|
502 | { |
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
|
503 | RCONSession::get_session()->disconnect(); |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
504 | g_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
|
505 | } |
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
|
506 | else if (ch == 'n' or ch == 'N') |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
507 | 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
|
508 | |
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
|
509 | 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
|
510 | } |
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
|
511 | |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
512 | 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
|
513 | { |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
514 | mutable_current_input().insert (g_cursor++, char (ch)); |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
515 | g_needInputRender = true; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
516 | } |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
517 | else switch (ch) |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
518 | { |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
519 | case 'Q' - 'A' + 1: // ^Q |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
520 | switch (g_inputState) |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
521 | { |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
522 | case INPUTSTATE_CONFIRM_DISCONNECTION: |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
523 | break; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
524 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
525 | case INPUTSTATE_NORMAL: |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
526 | safe_disconnect ([]() |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
527 | { |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
528 | RCONSession* session = RCONSession::get_session(); |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
529 | |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
530 | if (session->is_active()) |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
531 | { |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
532 | session->disconnect(); |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
533 | set_input_state (INPUTSTATE_NORMAL); |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
534 | } |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
535 | else |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
536 | { |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
537 | endwin(); |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
538 | throw Exitception(); |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
539 | } |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
540 | }); |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
541 | break; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
542 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
543 | case INPUTSTATE_PASSWORD: |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
544 | set_input_state (INPUTSTATE_ADDRESS); |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
545 | break; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
546 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
547 | case INPUTSTATE_ADDRESS: |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
548 | set_input_state (INPUTSTATE_NORMAL); |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
549 | } |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
550 | break; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
551 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
552 | case '\e': |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
553 | if (g_inputState == INPUTSTATE_PASSWORD) |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
554 | set_input_state (INPUTSTATE_ADDRESS); |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
555 | else if (g_inputState == INPUTSTATE_ADDRESS) |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
556 | set_input_state (INPUTSTATE_NORMAL); |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
557 | break; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
558 | |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
559 | case KEY_LEFT: |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
560 | if (g_cursor > 0) |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
561 | { |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
562 | g_cursor--; |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
563 | g_needInputRender = true; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
564 | } |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
565 | break; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
566 | |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
567 | case KEY_RIGHT: |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
568 | if (g_cursor < current_input().length()) |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
569 | { |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
570 | g_cursor++; |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
571 | g_needInputRender = true; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
572 | } |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
573 | break; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
574 | |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
575 | case KEY_DOWN: |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
576 | case KEY_UP: |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
577 | 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
|
578 | break; |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
579 | |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
580 | case KEY_HOME: |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
581 | if (g_cursor != 0) |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
582 | { |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
583 | g_cursor = 0; |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
584 | g_needInputRender = true; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
585 | } |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
586 | break; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
587 | |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
588 | case KEY_END: |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
589 | if (g_cursor != current_input().length()) |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
590 | { |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
591 | g_cursor = current_input().length(); |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
592 | g_needInputRender = true; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
593 | } |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
594 | break; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
595 | |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
596 | case KEY_BACKSPACE: |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
597 | if (g_cursor > 0) |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
598 | { |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
599 | mutable_current_input().remove_at (--g_cursor); |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
600 | g_needInputRender = true; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
601 | } |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
602 | break; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
603 | |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
604 | case KEY_DC: |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
605 | if (g_cursor < current_input().length()) |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
606 | { |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
607 | mutable_current_input().remove_at (g_cursor); |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
608 | g_needInputRender = true; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
609 | } |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
610 | break; |
16
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
611 | |
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
612 | case KEY_PPAGE: |
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
613 | g_outputScroll += PAGE_SIZE; |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
614 | g_needOutputRender = true; |
16
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
615 | break; |
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
616 | |
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
617 | case KEY_NPAGE: |
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
618 | g_outputScroll -= PAGE_SIZE; |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
619 | g_needOutputRender = true; |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
620 | break; |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
621 | |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
622 | case '\n': |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
623 | case KEY_ENTER: |
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
|
624 | switch (g_inputState) |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
625 | { |
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
|
626 | 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
|
627 | 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
|
628 | |
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
|
629 | 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
|
630 | 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
|
631 | { |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
632 | g_address = 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
|
633 | } |
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
|
634 | 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
|
635 | { |
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
|
636 | print (e.what()); |
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
|
637 | 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
|
638 | } |
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
|
639 | |
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
|
640 | if (g_address.port == 0) |
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
|
641 | g_address.port = 10666; |
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
|
642 | |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
643 | set_input_state (INPUTSTATE_PASSWORD); |
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
644 | 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
|
645 | |
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
|
646 | case INPUTSTATE_PASSWORD: |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
647 | if (g_inputState == 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
|
648 | { |
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
|
649 | RCONSession* session = RCONSession::new_session(); |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
650 | session->set_password (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
|
651 | session->connect (g_address); |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
652 | 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
|
653 | } |
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
|
654 | 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
|
655 | |
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
|
656 | case INPUTSTATE_NORMAL: |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
657 | if (RCONSession::get_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
|
658 | { |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
659 | g_input.insert (0, ""); |
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
|
660 | g_needInputRender = true; |
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
|
661 | } |
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
|
662 | 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
|
663 | } |
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
|
664 | 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
|
665 | |
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
|
666 | case 'N' - 'A' + 1: // ^N |
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
|
667 | if (g_inputState == INPUTSTATE_NORMAL) |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
668 | safe_disconnect ([]() {set_input_state (INPUTSTATE_ADDRESS);}); |
16
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
669 | break; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
670 | } |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
671 | } |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
672 | |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
673 | // ------------------------------------------------------------------------------------------------- |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
674 | // |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
675 | FUNCTION |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
676 | Interface::render() -> void |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
677 | { |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
678 | if (g_needStatusBarRender) interface_render_statusbar(); |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
679 | if (g_needInputRender) interface_render_input(); |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
680 | if (g_needOutputRender) interface_render_output(); |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
681 | |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
682 | if (g_needRefresh) |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
683 | { |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
684 | interface_position_cursor(); |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
685 | refresh(); |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
686 | g_needRefresh = false; |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
687 | } |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
688 | } |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
689 | |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
690 | // ------------------------------------------------------------------------------------------------- |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
691 | // |
32
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
692 | FUNCTION print_to_console (String a) -> void |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
693 | { |
32
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
694 | // Zandronum is retarded and SOMETIMES sends color codes as "\\c" and sometimes as "\x1C". |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
695 | // Let's correct that on our end and HOPE this won't cause conflicts. |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
696 | a.replace ("\\c", "\x1C"); |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
697 | |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
698 | for (char ch : a) |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
699 | { |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
700 | if (ch == '\n') |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
701 | { |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
702 | g_output << ""; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
703 | continue; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
704 | } |
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 | g_output[g_output.size() - 1] += ch; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
707 | } |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
708 | |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
709 | g_needOutputRender = true; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
710 | } |
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
|
711 | |
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
|
712 | // ------------------------------------------------------------------------------------------------- |
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
|
713 | // |
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
|
714 | FUNCTION |
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
|
715 | Interface::connect (String address, String password) -> void |
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
|
716 | { |
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
|
717 | 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
|
718 | { |
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
|
719 | g_address = IPAddress::from_string (address); |
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
|
720 | } |
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
|
721 | 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
|
722 | { |
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
|
723 | print (e.what()); |
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
|
724 | 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
|
725 | } |
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
|
726 | |
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
|
727 | if (g_address.port == 0) |
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
|
728 | g_address.port = 10666; |
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
|
729 | |
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
|
730 | RCONSession* session = RCONSession::new_session(); |
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
|
731 | session->set_password (password); |
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
|
732 | session->connect (g_address); |
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
|
733 | } |