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