Mon, 11 Jan 2016 02:49:29 +0200
Added support for alt+backspace, which removes the previous word
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
109 | 2 | Copyright 2014 - 2016 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 | { |
117
39e05a6ba8d7
Improved the color handling a tad
Teemu Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
46 | if (fg == DEFAULT && bg == DEFAULT) |
39e05a6ba8d7
Improved the color handling a tad
Teemu Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
47 | return 0; |
39e05a6ba8d7
Improved the color handling a tad
Teemu Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
48 | else |
39e05a6ba8d7
Improved the color handling a tad
Teemu Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
49 | 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
|
50 | } |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
51 | |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
52 | // ------------------------------------------------------------------------------------------------- |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
53 | // |
72 | 54 | const String& Interface::current_input() |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
55 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
56 | return InputHistory[InputCursor]; |
31
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 | |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
59 | // ------------------------------------------------------------------------------------------------- |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
60 | // |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
61 | // 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
|
62 | // |
72 | 63 | void Interface::detach_input() |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
64 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
65 | if (InputCursor > 0) |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
66 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
67 | InputHistory[0] = current_input(); |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
68 | InputCursor = 0; |
31
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 | } |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
71 | |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
72 | // ------------------------------------------------------------------------------------------------- |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
73 | // 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
|
74 | // |
72 | 75 | String& Interface::mutable_current_input() |
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 | detach_input(); |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
78 | return InputHistory[InputCursor]; |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
79 | } |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
80 | |
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 | // |
72 | 83 | 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
|
84 | { |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
85 | // 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
|
86 | if (CurrentInputState != INPUTSTATE_NORMAL) |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
87 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
88 | InputCursor = 0; |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
89 | return; |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
90 | } |
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 | int oldcursor = InputCursor; |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
93 | 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
|
94 | |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
95 | if (InputCursor != oldcursor) |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
96 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
97 | CursorPosition = current_input().length(); |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
98 | NeedInputRender = true; |
31
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 | } |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
101 | |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
102 | // ------------------------------------------------------------------------------------------------- |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
103 | // |
72 | 104 | 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
|
105 | { |
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 | 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
|
107 | |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
108 | 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
|
109 | { |
e651d02802c0
- the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents:
23
diff
changeset
|
110 | 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
|
111 | 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
|
112 | 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
|
113 | 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
|
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 | 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
|
117 | } |
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
|
118 | |
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
|
119 | // ------------------------------------------------------------------------------------------------- |
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
|
120 | // |
72 | 121 | void Interface::set_input_state (InputState newstate) |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
122 | { |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
123 | // 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
|
124 | if (newstate != INPUTSTATE_CONFIRM_DISCONNECTION |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
125 | and CurrentInputState != INPUTSTATE_CONFIRM_DISCONNECTION) |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
126 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
127 | InputCursor = 0; |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
128 | mutable_current_input().clear(); |
27
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 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
131 | switch (newstate) |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
132 | { |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
133 | case INPUTSTATE_ADDRESS: |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
134 | if (CurrentAddress.host != 0) |
88
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
86
diff
changeset
|
135 | 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
|
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 | default: |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
139 | break; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
140 | } |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
141 | |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
142 | CurrentInputState = newstate; |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
143 | NeedInputRender = true; |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
144 | } |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
145 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
146 | // ------------------------------------------------------------------------------------------------- |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
147 | // |
72 | 148 | Interface::Interface() : |
88
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
86
diff
changeset
|
149 | InputCursor (0), |
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
86
diff
changeset
|
150 | CursorPosition (0), |
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
86
diff
changeset
|
151 | InputPanning (0), |
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
86
diff
changeset
|
152 | NeedRefresh (false), |
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
86
diff
changeset
|
153 | NeedStatusBarRender (false), |
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
86
diff
changeset
|
154 | NeedInputRender (false), |
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
86
diff
changeset
|
155 | NeedOutputRender (false), |
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
86
diff
changeset
|
156 | NeedNicklistRender (false), |
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
86
diff
changeset
|
157 | OutputScroll (0), |
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
86
diff
changeset
|
158 | CurrentInputState (INPUTSTATE_NORMAL), |
96 | 159 | DisconnectConfirmFunction (nullptr) |
20
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
160 | { |
92 | 161 | ::initscr(); |
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
|
162 | ::raw(); |
20
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
163 | ::keypad (stdscr, true); |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
164 | ::noecho(); |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
165 | ::refresh(); |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
166 | ::timeout (0); |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
167 | InputHistory.clear(); |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
168 | InputHistory << ""; |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
169 | OutputLines.clear(); |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
170 | OutputLines << ColoredLine(); |
92 | 171 | Session.set_interface (this); |
111
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
172 | reset_title(); |
20
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
173 | |
81
a18aaf460648
Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
174 | if (::has_colors()) |
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 | ::start_color(); |
117
39e05a6ba8d7
Improved the color handling a tad
Teemu Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
177 | bool hasDefaultColors = ::use_default_colors(); |
39e05a6ba8d7
Improved the color handling a tad
Teemu Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
178 | int defaultFg = (hasDefaultColors == OK) ? -1 : COLOR_WHITE; |
39e05a6ba8d7
Improved the color handling a tad
Teemu Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
179 | int defaultBg = (hasDefaultColors == OK) ? -1 : COLOR_BLACK; |
81
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 | // Initialize color pairs |
a18aaf460648
Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
182 | for (int i = 0; i < NUM_COLORS; ++i) |
a18aaf460648
Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
183 | for (int j = 0; j < NUM_COLORS; ++j) |
a18aaf460648
Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
184 | { |
a18aaf460648
Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
185 | int pairnum = 1 + (i * NUM_COLORS + j); |
a18aaf460648
Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
186 | int fg = (i == DEFAULT) ? defaultFg : i; |
a18aaf460648
Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
187 | int bg = (j == DEFAULT) ? defaultBg : j; |
a18aaf460648
Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
188 | |
117
39e05a6ba8d7
Improved the color handling a tad
Teemu Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
189 | if (fg != -1 || bg != -1) |
39e05a6ba8d7
Improved the color handling a tad
Teemu Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
190 | { |
39e05a6ba8d7
Improved the color handling a tad
Teemu Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
191 | if (::init_pair (pairnum, fg, bg) == ERR) |
39e05a6ba8d7
Improved the color handling a tad
Teemu Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
192 | print_warning ("Unable to initialize color pair %d (%d, %d)\n", pairnum, fg, bg); |
39e05a6ba8d7
Improved the color handling a tad
Teemu Piippo <crimsondusk64@gmail.com>
parents:
116
diff
changeset
|
193 | } |
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 | } |
20
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
196 | |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
197 | render_full(); |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
198 | refresh(); |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
199 | NeedRefresh = false; |
20
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
200 | } |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
201 | |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
202 | // ------------------------------------------------------------------------------------------------- |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
203 | // |
72 | 204 | void Interface::render_titlebar() |
20
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
205 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
206 | if (Title.length() <= COLS) |
23
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
207 | { |
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
|
208 | chtype pair = color_pair (WHITE, BLUE); |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
209 | int startx = (COLS - Title.length()) / 2; |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
210 | int endx = startx + Title.length(); |
23
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
211 | attron (pair); |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
212 | mvprintw (0, startx, "%s", Title.chars()); |
23
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
213 | mvhline (0, 0, ' ', startx); |
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
214 | mvhline (0, endx, ' ', COLS - endx); |
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
215 | attroff (pair); |
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
216 | } |
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
217 | |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
218 | NeedRefresh = true; |
20
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
219 | } |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
220 | |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
221 | // ------------------------------------------------------------------------------------------------- |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
222 | // |
72 | 223 | 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
|
224 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
225 | Title = title; |
72 | 226 | render_titlebar(); |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
227 | } |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
228 | |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
229 | // ------------------------------------------------------------------------------------------------- |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
230 | // |
111
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
231 | void Interface::safe_disconnect (std::function<void(bool)> afterwards) |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
232 | { |
72 | 233 | if (Session.is_active()) |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
234 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
235 | DisconnectConfirmFunction = afterwards; |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
236 | set_input_state (INPUTSTATE_CONFIRM_DISCONNECTION); |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
237 | } |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
238 | else |
111
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
239 | afterwards(false); |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
240 | } |
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 | // ------------------------------------------------------------------------------------------------- |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
243 | // |
72 | 244 | int Interface::nicklist_width() |
47 | 245 | { |
246 | // Allocate at least 12 characters, at most 24 characters, for the nicklist. If we cannot | |
247 | // afford that (o_O) then we probably shouldn't draw the nicklist at all I think. | |
248 | int nicklistWidth = COLS / 4; | |
249 | ||
250 | if (nicklistWidth < 12) | |
251 | return 0; | |
252 | ||
253 | return min (nicklistWidth, 24); | |
254 | } | |
255 | ||
256 | // ------------------------------------------------------------------------------------------------- | |
257 | // Renders the given colored line onto the screen. Will wrap if allowWrap is true. Returns the | |
258 | // 'y' value for the next line. | |
259 | // | |
72 | 260 | int Interface::render_colorline (int y, int x0, int width, const ColoredLine& line, bool allowWrap) |
47 | 261 | { |
262 | int x = x0; | |
263 | ||
100
d301ead29d7c
Apply Leonard's patch for fixing the colors:
Teemu Piippo <tsapii@utu.fi>
parents:
96
diff
changeset
|
264 | for (int i = 0; i < line.data().size(); ++i) |
47 | 265 | { |
88
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
86
diff
changeset
|
266 | int byte = line.data()[i]; |
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
86
diff
changeset
|
267 | |
47 | 268 | if (x == x0 + width) |
269 | { | |
270 | if (not allowWrap) | |
271 | return y; | |
272 | ||
273 | x = x0; | |
274 | ++y; | |
275 | } | |
276 | ||
100
d301ead29d7c
Apply Leonard's patch for fixing the colors:
Teemu Piippo <tsapii@utu.fi>
parents:
96
diff
changeset
|
277 | if (byte < 256 && isprint (byte)) |
47 | 278 | { |
279 | mvaddch (y, x, char (byte)); | |
280 | ++x; | |
281 | } | |
102
3492f8f0ee7e
And another refactor on that..
Teemu Piippo <tsapii@utu.fi>
parents:
101
diff
changeset
|
282 | else if (byte >= RLINE_ON_COLOR and byte < (RLINE_ON_COLOR + 16)) |
101
71f1cd8154a9
Slight refactor on the fix in the previous commit
Teemu Piippo <tsapii@utu.fi>
parents:
100
diff
changeset
|
283 | { |
71f1cd8154a9
Slight refactor on the fix in the previous commit
Teemu Piippo <tsapii@utu.fi>
parents:
100
diff
changeset
|
284 | auto attrfunction = (byte < RLINE_OFF_COLOR ? &attron : &attroff); |
71f1cd8154a9
Slight refactor on the fix in the previous commit
Teemu Piippo <tsapii@utu.fi>
parents:
100
diff
changeset
|
285 | (*attrfunction) (color_pair (Color ((byte - RLINE_ON_COLOR) & 7), DEFAULT)); |
71f1cd8154a9
Slight refactor on the fix in the previous commit
Teemu Piippo <tsapii@utu.fi>
parents:
100
diff
changeset
|
286 | } |
47 | 287 | else switch (byte) |
288 | { | |
289 | case RLINE_ON_BOLD: | |
290 | attron (A_BOLD); | |
291 | break; | |
292 | ||
293 | case RLINE_OFF_BOLD: | |
294 | attroff (A_BOLD); | |
295 | break; | |
296 | } | |
297 | } | |
298 | ||
299 | return y + 1; | |
300 | } | |
301 | ||
302 | // ------------------------------------------------------------------------------------------------- | |
303 | // | |
72 | 304 | 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
|
305 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
306 | 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
|
307 | 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
|
308 | |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
309 | 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
|
310 | |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
311 | int height = LINES - 3; |
72 | 312 | 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
|
313 | int printOffset = 0; |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
314 | 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
|
315 | 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
|
316 | 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
|
317 | 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
|
318 | 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
|
319 | |
3caf69e7350b
- added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
33
diff
changeset
|
320 | // 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
|
321 | 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
|
322 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
323 | 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
|
324 | |
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
|
325 | 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
|
326 | { |
3caf69e7350b
- added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
33
diff
changeset
|
327 | // 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
|
328 | 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
|
329 | 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
|
330 | } |
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 | |
3caf69e7350b
- added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
33
diff
changeset
|
332 | 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
|
333 | 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
|
334 | } |
16
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
335 | |
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 | // 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
|
337 | 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
|
338 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
339 | 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
|
340 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
341 | 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
|
342 | |
3caf69e7350b
- added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
33
diff
changeset
|
343 | 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
|
344 | { |
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 | 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
|
346 | 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
|
347 | } |
16
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
348 | |
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
|
349 | 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
|
350 | 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
|
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 | |
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 | 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
|
355 | 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
|
356 | |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
357 | 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
|
358 | |
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 | 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
|
360 | 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
|
361 | |
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
|
362 | 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
|
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 | // 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
|
365 | for (int i = y; i < y + height; ++i) |
47 | 366 | 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
|
367 | |
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 | // 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
|
369 | y += printOffset; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
370 | |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
371 | for (int i = start; i < end; ++i) |
72 | 372 | y = render_colorline (y, 0, width, OutputLines[i], true); |
47 | 373 | |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
374 | NeedOutputRender = false; |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
375 | NeedRefresh = true; |
47 | 376 | } |
377 | ||
378 | // ------------------------------------------------------------------------------------------------- | |
379 | // | |
72 | 380 | void Interface::render_nicklist() |
47 | 381 | { |
72 | 382 | int width = nicklist_width(); |
47 | 383 | int height = LINES- 3; |
384 | int y = 1; | |
385 | int x = COLS - width; | |
386 | ||
387 | if (width == 0) | |
388 | return; | |
389 | ||
390 | 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
|
391 | { |
47 | 392 | mvhline (y, x, ' ', width); |
32
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
393 | |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
394 | if (i < PlayerNames.size()) |
32
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
395 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
396 | String displaynick = PlayerNames[i]; |
47 | 397 | |
398 | if (displaynick.length() > width) | |
32
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
399 | { |
47 | 400 | displaynick = displaynick.mid (0, width - 3); |
401 | displaynick += "..."; | |
32
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
402 | } |
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
403 | |
47 | 404 | 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
|
405 | } |
32
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
406 | |
47 | 407 | y++; |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
408 | } |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
409 | |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
410 | NeedNicklistRender = false; |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
411 | NeedRefresh = true; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
412 | } |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
413 | |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
414 | // ------------------------------------------------------------------------------------------------- |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
415 | // |
72 | 416 | 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
|
417 | { |
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
|
418 | 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
|
419 | |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
420 | // 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
|
421 | // just the confirmation message. |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
422 | 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
|
423 | { |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
424 | 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
|
425 | 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
|
426 | 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
|
427 | attroff (promptColor); |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
428 | 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
|
429 | 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
|
430 | } |
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
|
431 | |
72 | 432 | String prompt = prompt_string(); |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
433 | int displayLength = COLS - prompt.length() - 2; |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
434 | 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
|
435 | int y = LINES - 2; |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
436 | |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
437 | // 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
|
438 | if (CurrentInputState == INPUTSTATE_PASSWORD) |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
439 | { |
88
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
86
diff
changeset
|
440 | 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
|
441 | displayString[i] = '*'; |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
442 | } |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
443 | |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
444 | // Ensure the cursor is within bounds |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
445 | CursorPosition = clamp (CursorPosition, 0, displayString.length()); |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
446 | |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
447 | // 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
|
448 | if (CursorPosition > InputPanning + displayLength) |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
449 | InputPanning = CursorPosition - displayLength; // cursor went too far right |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
450 | else if (CursorPosition < InputPanning) |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
451 | 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
|
452 | |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
453 | // What part of the string to draw? |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
454 | int start = InputPanning; |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
455 | 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
|
456 | 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
|
457 | |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
458 | // 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
|
459 | mvhline (LINES - 2, 0, ' ', COLS); |
49
9e0f26f020e1
- fixed: horizontal input scrolling was broken
Teemu Piippo <crimsondusk64@gmail.com>
parents:
48
diff
changeset
|
460 | 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
|
461 | |
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
462 | // Render the prompt |
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
463 | 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
|
464 | mvprintw (y, 0, "%s", prompt.chars()); |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
465 | attroff (promptColor); |
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
466 | |
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
467 | // 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
|
468 | // cursor). |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
469 | CursorCharacter.ch = CursorPosition != 0 ? displayString[CursorPosition - 1] : '\0'; |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
470 | CursorCharacter.x = prompt.length() + (CursorPosition - InputPanning); |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
471 | NeedRefresh = true; |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
472 | NeedInputRender = false; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
473 | } |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
474 | |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
475 | // ------------------------------------------------------------------------------------------------- |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
476 | // |
72 | 477 | 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
|
478 | { |
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
|
479 | 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
|
480 | int y = LINES - 1; |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
481 | attron (color); |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
482 | mvhline (y, 0, ' ', COLS); |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
483 | mvprintw (y, 0, "%s", StatusBarText.chars()); |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
484 | attroff (color); |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
485 | NeedRefresh = true; |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
486 | NeedStatusBarRender = false; |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
487 | } |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
488 | |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
489 | // ------------------------------------------------------------------------------------------------- |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
490 | // |
72 | 491 | void Interface::update_statusbar() |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
492 | { |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
493 | String text; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
494 | |
72 | 495 | switch (Session.state()) |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
496 | { |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
497 | case RCON_DISCONNECTED: |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
498 | text = "Disconnected."; |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
499 | break; |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
500 | |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
501 | case RCON_CONNECTING: |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
502 | case RCON_AUTHENTICATING: |
88
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
86
diff
changeset
|
503 | 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
|
504 | break; |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
505 | |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
506 | case RCON_CONNECTED: |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
507 | { |
72 | 508 | String adminText; |
509 | ||
510 | 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
|
511 | { |
72 | 512 | 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
|
513 | } |
72 | 514 | else |
83
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
515 | { |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
516 | 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
|
517 | 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
|
518 | } |
72 | 519 | |
88
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
86
diff
changeset
|
520 | text.sprintf ("%s | %s | %s", |
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
86
diff
changeset
|
521 | 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
|
522 | Session.level().chars(), |
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
86
diff
changeset
|
523 | adminText.chars()); |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
524 | } |
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 | } |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
527 | |
28
3cc042af3090
- added a help message to the statusbar
Teemu Piippo <crimsondusk64@gmail.com>
parents:
27
diff
changeset
|
528 | if (not text.is_empty()) |
3cc042af3090
- added a help message to the statusbar
Teemu Piippo <crimsondusk64@gmail.com>
parents:
27
diff
changeset
|
529 | text += " | "; |
3cc042af3090
- added a help message to the statusbar
Teemu Piippo <crimsondusk64@gmail.com>
parents:
27
diff
changeset
|
530 | |
115
bb7ef7c33dad
ZFC's own messages are now printed in blue to distinguish them from messages from the server.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
112
diff
changeset
|
531 | text += "Ctrl+N to connect, Ctrl+Q to "; |
bb7ef7c33dad
ZFC's own messages are now printed in blue to distinguish them from messages from the server.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
112
diff
changeset
|
532 | text += (Session.state() == RCON_DISCONNECTED) ? "quit" : "disconnect"; |
28
3cc042af3090
- added a help message to the statusbar
Teemu Piippo <crimsondusk64@gmail.com>
parents:
27
diff
changeset
|
533 | |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
534 | if (text != StatusBarText) |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
535 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
536 | StatusBarText = text; |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
537 | NeedStatusBarRender = true; |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
538 | } |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
539 | } |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
540 | |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
541 | // ------------------------------------------------------------------------------------------------- |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
542 | // |
72 | 543 | 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
|
544 | { |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
545 | update_statusbar(); |
72 | 546 | render_titlebar(); |
547 | render_output(); | |
548 | render_statusbar(); | |
549 | render_input(); | |
550 | render_nicklist(); | |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
551 | } |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
552 | |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
553 | // ------------------------------------------------------------------------------------------------- |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
554 | // |
72 | 555 | void Interface::position_cursor() |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
556 | { |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
557 | // 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
|
558 | if (CurrentInputState == INPUTSTATE_CONFIRM_DISCONNECTION) |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
559 | return; |
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
560 | |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
561 | int y = LINES - 2; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
562 | |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
563 | if (CursorCharacter.ch != '\0') |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
564 | 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
|
565 | else |
72 | 566 | 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
|
567 | } |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
568 | |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
569 | // ------------------------------------------------------------------------------------------------- |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
570 | // |
72 | 571 | 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
|
572 | { |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
573 | const String& input = current_input(); |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
574 | 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
|
575 | |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
576 | // Move past whitespace |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
577 | 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
|
578 | pos--; |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
579 | |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
580 | // 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
|
581 | 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
|
582 | pos--; |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
583 | |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
584 | return pos; |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
585 | } |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
586 | |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
587 | // ------------------------------------------------------------------------------------------------- |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
588 | // |
72 | 589 | 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
|
590 | { |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
591 | const String& input = current_input(); |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
592 | 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
|
593 | |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
594 | // 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
|
595 | 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
|
596 | pos++; |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
597 | |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
598 | // 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
|
599 | 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
|
600 | pos++; |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
601 | |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
602 | return 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 | |
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 | // |
72 | 607 | 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
|
608 | { |
8f1a6f40d1b4
- added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
52
diff
changeset
|
609 | if (a >= b) |
8f1a6f40d1b4
- added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
52
diff
changeset
|
610 | return; |
8f1a6f40d1b4
- added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
52
diff
changeset
|
611 | |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
612 | if (CursorPosition > a and CursorPosition <= b) |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
613 | CursorPosition = a; |
53
8f1a6f40d1b4
- added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
52
diff
changeset
|
614 | |
8f1a6f40d1b4
- added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
52
diff
changeset
|
615 | String& input = mutable_current_input(); |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
616 | PasteBuffer = input.mid (a, b); |
53
8f1a6f40d1b4
- added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
52
diff
changeset
|
617 | input.remove (a, b - a); |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
618 | NeedInputRender = true; |
53
8f1a6f40d1b4
- added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
52
diff
changeset
|
619 | } |
8f1a6f40d1b4
- added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
52
diff
changeset
|
620 | |
8f1a6f40d1b4
- added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
52
diff
changeset
|
621 | // ------------------------------------------------------------------------------------------------- |
8f1a6f40d1b4
- added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
52
diff
changeset
|
622 | // |
72 | 623 | 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
|
624 | { |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
625 | int ch = ::getch(); |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
626 | |
81
a18aaf460648
Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
627 | if (ch < 0) |
a18aaf460648
Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
628 | return; |
a18aaf460648
Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
629 | |
33
bb209480d0ec
- handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
630 | if (ch == KEY_RESIZE) |
bb209480d0ec
- handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
631 | { |
bb209480d0ec
- handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
632 | ::clear(); |
bb209480d0ec
- handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
633 | render_full(); |
bb209480d0ec
- handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
634 | return; |
bb209480d0ec
- handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
635 | } |
bb209480d0ec
- handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
636 | |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
637 | 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
|
638 | { |
e651d02802c0
- the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents:
23
diff
changeset
|
639 | 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
|
640 | { |
72 | 641 | Session.disconnect(); |
111
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
642 | DisconnectConfirmFunction(true); |
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
|
643 | } |
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
|
644 | else if (ch == 'n' or ch == 'N') |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
645 | 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
|
646 | |
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
|
647 | 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
|
648 | } |
e651d02802c0
- the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents:
23
diff
changeset
|
649 | |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
650 | 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
|
651 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
652 | mutable_current_input().insert (CursorPosition++, char (ch)); |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
653 | NeedInputRender = true; |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
654 | } |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
655 | else switch (ch) |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
656 | { |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
657 | case 'Q' - 'A' + 1: // ^Q |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
658 | switch (CurrentInputState) |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
659 | { |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
660 | case INPUTSTATE_CONFIRM_DISCONNECTION: |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
661 | break; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
662 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
663 | case INPUTSTATE_NORMAL: |
111
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
664 | safe_disconnect ([&](bool hadsession) |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
665 | { |
111
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
666 | if (hadsession) |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
667 | { |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
668 | set_input_state (INPUTSTATE_NORMAL); |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
669 | } |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
670 | else |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
671 | { |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
672 | endwin(); |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
673 | throw Exitception(); |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
674 | } |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
675 | }); |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
676 | break; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
677 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
678 | case INPUTSTATE_PASSWORD: |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
679 | set_input_state (INPUTSTATE_ADDRESS); |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
680 | break; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
681 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
682 | case INPUTSTATE_ADDRESS: |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
683 | set_input_state (INPUTSTATE_NORMAL); |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
684 | } |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
685 | break; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
686 | |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
687 | 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
|
688 | case 'B' - 'A' + 1: // readline ^B |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
689 | if (CursorPosition > 0) |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
690 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
691 | CursorPosition--; |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
692 | NeedInputRender = true; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
693 | } |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
694 | break; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
695 | |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
696 | 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
|
697 | case 'F' - 'A' + 1: // readline ^F |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
698 | 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
|
699 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
700 | CursorPosition++; |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
701 | NeedInputRender = true; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
702 | } |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
703 | break; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
704 | |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
705 | case KEY_DOWN: |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
706 | case KEY_UP: |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
707 | 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
|
708 | break; |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
709 | |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
710 | 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
|
711 | case 'A' - 'A' + 1: // readline ^A |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
712 | if (CursorPosition != 0) |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
713 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
714 | CursorPosition = 0; |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
715 | NeedInputRender = true; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
716 | } |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
717 | break; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
718 | |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
719 | 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
|
720 | case 'E' - 'A' + 1: // readline ^E |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
721 | 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
|
722 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
723 | CursorPosition = current_input().length(); |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
724 | NeedInputRender = true; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
725 | } |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
726 | break; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
727 | |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
728 | case KEY_BACKSPACE: |
81
a18aaf460648
Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
729 | case '\b': |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
730 | if (CursorPosition > 0) |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
731 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
732 | mutable_current_input().remove_at (--CursorPosition); |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
733 | NeedInputRender = true; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
734 | } |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
735 | break; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
736 | |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
737 | 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
|
738 | case 'D' - 'A' + 1: // readline ^D |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
739 | if (CursorPosition < current_input().length()) |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
740 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
741 | mutable_current_input().remove_at (CursorPosition); |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
742 | NeedInputRender = true; |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
743 | } |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
744 | break; |
16
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
745 | |
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
746 | case KEY_PPAGE: |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
747 | OutputScroll += min (g_pageSize, LINES / 2); |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
748 | NeedOutputRender = true; |
16
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
749 | break; |
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
750 | |
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
751 | case KEY_NPAGE: |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
752 | OutputScroll -= min (g_pageSize, LINES / 2); |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
753 | NeedOutputRender = true; |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
754 | break; |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
755 | |
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
|
756 | 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
|
757 | 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
|
758 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
759 | yank (0, CursorPosition); |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
760 | 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
|
761 | } |
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
|
762 | 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
|
763 | |
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
|
764 | 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
|
765 | 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
|
766 | 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
|
767 | |
44
693d7751fff0
- added readline alt-d and ^w support (delete till word boundaries)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
43
diff
changeset
|
768 | case 'W' - 'A' + 1: // readline ^W - delete from previous word bounary to current |
72 | 769 | yank (find_previous_word(), CursorPosition); |
53
8f1a6f40d1b4
- added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
52
diff
changeset
|
770 | break; |
44
693d7751fff0
- added readline alt-d and ^w support (delete till word boundaries)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
43
diff
changeset
|
771 | |
53
8f1a6f40d1b4
- added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
52
diff
changeset
|
772 | 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
|
773 | if (not PasteBuffer.is_empty()) |
53
8f1a6f40d1b4
- added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
52
diff
changeset
|
774 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
775 | mutable_current_input().insert (CursorPosition, PasteBuffer); |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
776 | CursorPosition += PasteBuffer.length(); |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
777 | NeedInputRender = true; |
44
693d7751fff0
- added readline alt-d and ^w support (delete till word boundaries)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
43
diff
changeset
|
778 | } |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
779 | break; |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
780 | |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
781 | case '\t': |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
782 | { |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
783 | int space = current_input().find (" "); |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
784 | |
71 | 785 | if (CurrentInputState == INPUTSTATE_NORMAL |
72 | 786 | and CursorPosition > 0 |
787 | and (space == -1 or space >= CursorPosition)) | |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
788 | { |
72 | 789 | String start = current_input().mid (0, CursorPosition); |
790 | Session.request_tab_complete (start); | |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
791 | } |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
792 | } |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
793 | break; |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
794 | |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
795 | 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
|
796 | case '\r': |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
797 | case KEY_ENTER: |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
798 | switch (CurrentInputState) |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
799 | { |
24
e651d02802c0
- the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents:
23
diff
changeset
|
800 | 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
|
801 | 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
|
802 | |
e651d02802c0
- the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents:
23
diff
changeset
|
803 | 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
|
804 | 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
|
805 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
806 | 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
|
807 | } |
e651d02802c0
- the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents:
23
diff
changeset
|
808 | 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
|
809 | { |
83
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
810 | 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
|
811 | 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
|
812 | } |
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
|
813 | |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
814 | if (CurrentAddress.port == 0) |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
815 | 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
|
816 | |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
817 | set_input_state (INPUTSTATE_PASSWORD); |
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
818 | 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
|
819 | |
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
|
820 | case INPUTSTATE_PASSWORD: |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
821 | 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
|
822 | { |
72 | 823 | Session.disconnect(); |
824 | Session.set_password (current_input()); | |
825 | Session.connect (CurrentAddress); | |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
826 | 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
|
827 | } |
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 | 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
|
829 | |
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 | case INPUTSTATE_NORMAL: |
105
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
831 | if (current_input()[0] == '/') |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
832 | { |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
833 | handle_command(current_input()); |
116
552909484712
Fixed: sending a message from earlier history did not flush to a new input line, instead just up a single level in history
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
834 | flush_input(); |
105
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
835 | } |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
836 | else 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
|
837 | { |
116
552909484712
Fixed: sending a message from earlier history did not flush to a new input line, instead just up a single level in history
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
838 | flush_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
|
839 | } |
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 | 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
|
841 | } |
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
|
842 | 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
|
843 | |
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
|
844 | case 'N' - 'A' + 1: // ^N |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
845 | if (CurrentInputState == INPUTSTATE_NORMAL) |
111
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
846 | safe_disconnect ([&](bool){set_input_state (INPUTSTATE_ADDRESS);}); |
16
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
847 | break; |
43
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
848 | |
91
ac02cf1c3576
'\e' is non-standard use '\x1b' instead
Teemu Piippo <tsapii@utu.fi>
parents:
89
diff
changeset
|
849 | case '\x1b': // Escape |
43
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
850 | // 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
|
851 | ch = ::getch(); |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
852 | |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
853 | if (ch != ERR) |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
854 | { |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
855 | switch (ch) |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
856 | { |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
857 | case 'b': |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
858 | case 'B': |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
859 | // readline alt-b - move one word to the left |
72 | 860 | CursorPosition = find_previous_word(); |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
861 | NeedInputRender = true; |
43
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
862 | break; |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
863 | |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
864 | case 'f': |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
865 | case 'F': |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
866 | // readline alt-f - move one word to the right |
72 | 867 | CursorPosition = find_next_word(); |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
868 | NeedInputRender = true; |
43
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
869 | break; |
44
693d7751fff0
- added readline alt-d and ^w support (delete till word boundaries)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
43
diff
changeset
|
870 | |
693d7751fff0
- added readline alt-d and ^w support (delete till word boundaries)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
43
diff
changeset
|
871 | case 'd': |
693d7751fff0
- added readline alt-d and ^w support (delete till word boundaries)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
43
diff
changeset
|
872 | case 'D': |
693d7751fff0
- added readline alt-d and ^w support (delete till word boundaries)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
43
diff
changeset
|
873 | // readline alt-d - delete from here till next word boundary |
72 | 874 | 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
|
875 | break; |
118
ae284bf1b5ff
Added support for alt+backspace, which removes the previous word
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
876 | |
ae284bf1b5ff
Added support for alt+backspace, which removes the previous word
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
877 | case KEY_BACKSPACE: // alt+backspace, remove previous word |
ae284bf1b5ff
Added support for alt+backspace, which removes the previous word
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
878 | case '\b': |
ae284bf1b5ff
Added support for alt+backspace, which removes the previous word
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
879 | yank (find_previous_word(), CursorPosition); |
ae284bf1b5ff
Added support for alt+backspace, which removes the previous word
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
880 | break; |
43
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
881 | } |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
882 | } |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
883 | else |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
884 | { |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
885 | // No alt-key, handle pure escape |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
886 | 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
|
887 | set_input_state (INPUTSTATE_ADDRESS); |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
888 | 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
|
889 | 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
|
890 | } |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
891 | break; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
892 | } |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
893 | |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
894 | render(); |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
895 | } |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
896 | |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
897 | // ------------------------------------------------------------------------------------------------- |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
898 | // |
72 | 899 | void Interface::render() |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
900 | { |
72 | 901 | if (NeedStatusBarRender) render_statusbar(); |
902 | if (NeedInputRender) render_input(); | |
903 | if (NeedOutputRender) render_output(); | |
904 | if (NeedNicklistRender) render_nicklist(); | |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
905 | |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
906 | if (NeedRefresh) |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
907 | { |
72 | 908 | position_cursor(); |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
909 | refresh(); |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
910 | NeedRefresh = false; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
911 | } |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
912 | } |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
913 | |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
914 | // ------------------------------------------------------------------------------------------------- |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
915 | // |
83
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
916 | 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
|
917 | { |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
918 | String message; |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
919 | 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
|
920 | 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
|
921 | } |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
922 | |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
923 | // ------------------------------------------------------------------------------------------------- |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
924 | // |
115
bb7ef7c33dad
ZFC's own messages are now printed in blue to distinguish them from messages from the server.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
112
diff
changeset
|
925 | void __cdecl Interface::print_text (const char* fmtstr, ...) |
bb7ef7c33dad
ZFC's own messages are now printed in blue to distinguish them from messages from the server.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
112
diff
changeset
|
926 | { |
bb7ef7c33dad
ZFC's own messages are now printed in blue to distinguish them from messages from the server.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
112
diff
changeset
|
927 | va_list args; |
bb7ef7c33dad
ZFC's own messages are now printed in blue to distinguish them from messages from the server.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
112
diff
changeset
|
928 | va_start (args, fmtstr); |
bb7ef7c33dad
ZFC's own messages are now printed in blue to distinguish them from messages from the server.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
112
diff
changeset
|
929 | vprint (fmtstr, args); |
bb7ef7c33dad
ZFC's own messages are now printed in blue to distinguish them from messages from the server.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
112
diff
changeset
|
930 | va_end (args); |
bb7ef7c33dad
ZFC's own messages are now printed in blue to distinguish them from messages from the server.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
112
diff
changeset
|
931 | } |
bb7ef7c33dad
ZFC's own messages are now printed in blue to distinguish them from messages from the server.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
112
diff
changeset
|
932 | |
bb7ef7c33dad
ZFC's own messages are now printed in blue to distinguish them from messages from the server.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
112
diff
changeset
|
933 | // ------------------------------------------------------------------------------------------------- |
bb7ef7c33dad
ZFC's own messages are now printed in blue to distinguish them from messages from the server.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
112
diff
changeset
|
934 | // |
83
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
935 | 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
|
936 | { |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
937 | va_list args; |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
938 | va_start (args, fmtstr); |
115
bb7ef7c33dad
ZFC's own messages are now printed in blue to distinguish them from messages from the server.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
112
diff
changeset
|
939 | print_to_console (TEXTCOLOR_BrightBlue); |
83
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
940 | vprint (fmtstr, args); |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
941 | va_end (args); |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
942 | } |
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 | 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
|
947 | { |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
948 | va_list args; |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
949 | 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
|
950 | 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
|
951 | vprint (fmtstr, args); |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
952 | va_end (args); |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
953 | } |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
954 | |
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 | 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
|
958 | { |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
959 | va_list args; |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
960 | 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
|
961 | 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
|
962 | vprint (fmtstr, args); |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
963 | va_end (args); |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
964 | } |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
965 | |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
966 | // ------------------------------------------------------------------------------------------------- |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
967 | // |
88
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
86
diff
changeset
|
968 | 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
|
969 | { |
72 | 970 | // Zandronum sometimes sends color codes as "\\c" and sometimes as "\x1C". |
971 | // 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
|
972 | message.replace ("\\c", "\x1C"); |
32
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
973 | |
88
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
86
diff
changeset
|
974 | 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
|
975 | { |
88
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
86
diff
changeset
|
976 | char ch = message[i]; |
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
86
diff
changeset
|
977 | |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
978 | if (ch == '\n') |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
979 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
980 | OutputLines.last().finalize(); |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
981 | OutputLines << ColoredLine(); |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
982 | continue; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
983 | } |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
984 | |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
985 | if (OutputLines.last().length() == 0) |
51
481073b016a9
- added timestamps to output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
50
diff
changeset
|
986 | { |
481073b016a9
- added timestamps to output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
50
diff
changeset
|
987 | time_t now; |
481073b016a9
- added timestamps to output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
50
diff
changeset
|
988 | time (&now); |
481073b016a9
- added timestamps to output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
50
diff
changeset
|
989 | char timestamp[32]; |
481073b016a9
- added timestamps to output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
50
diff
changeset
|
990 | strftime (timestamp, sizeof timestamp, "[%H:%M:%S] ", localtime (&now)); |
481073b016a9
- added timestamps to output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
50
diff
changeset
|
991 | |
481073b016a9
- added timestamps to output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
50
diff
changeset
|
992 | for (char* cp = timestamp; *cp != '\0'; ++cp) |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
993 | OutputLines.last().add_char (*cp); |
51
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 | |
111
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
996 | // Remove some lines if there's too many of them. 20,000 should be enough, I hope. |
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
997 | while (OutputLines.size() > 20000) |
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
998 | OutputLines.remove_at(0); |
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
999 | |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
1000 | OutputLines.last().add_char (ch); |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
1001 | } |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
1002 | |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
1003 | NeedOutputRender = true; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1004 | } |
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
|
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 | // ------------------------------------------------------------------------------------------------- |
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
|
1007 | // |
72 | 1008 | 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
|
1009 | { |
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 | 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
|
1011 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
1012 | 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
|
1013 | } |
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 | 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
|
1015 | { |
83
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
1016 | 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
|
1017 | 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
|
1018 | } |
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
|
1019 | |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
1020 | if (CurrentAddress.port == 0) |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
1021 | 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
|
1022 | |
72 | 1023 | Session.disconnect(); |
1024 | Session.set_password (password); | |
1025 | 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
|
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 | // ------------------------------------------------------------------------------------------------- |
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
|
1029 | // |
72 | 1030 | 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
|
1031 | { |
69
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
1032 | PlayerNames = names; |
eb4c25284a19
Removed a lot of boilerplate code
Teemu Piippo <crimsondusk64@gmail.com>
parents:
58
diff
changeset
|
1033 | 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
|
1034 | } |
41
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 | // ------------------------------------------------------------------------------------------------- |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
1037 | // |
72 | 1038 | void Interface::tab_complete (const String& part, String complete) |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
1039 | { |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
1040 | String& input = mutable_current_input(); |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
1041 | |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
1042 | if (input.starts_with (part)) |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
1043 | { |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
1044 | if (input[part.length()] != ' ') |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
1045 | complete += ' '; |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
1046 | |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
1047 | input.replace (0, part.length(), complete); |
72 | 1048 | CursorPosition = complete.length(); |
71 | 1049 | NeedInputRender = true; |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
1050 | } |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
1051 | } |
88
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
86
diff
changeset
|
1052 | |
105
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1053 | // ------------------------------------------------------------------------------------------------- |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1054 | // |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1055 | void Interface::handle_command(const String& input) |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1056 | { |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1057 | if (input[0] != '/') |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1058 | return; |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1059 | |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1060 | StringList args = input.right(input.length() - 1).split(" "); |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1061 | String command = args[0].to_lowercase(); |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1062 | args.remove_at(0); |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1063 | |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1064 | if (command == "connect") |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1065 | { |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1066 | if (args.size() != 2) |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1067 | print_error("Usage: /connect <address> <password>"); |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1068 | else |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1069 | { |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1070 | IPAddress address; |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1071 | |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1072 | try |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1073 | { |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1074 | address = IPAddress::from_string(args[0]); |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1075 | } |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1076 | catch (std::exception& e) |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1077 | { |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1078 | print_error("%s\n", e.what()); |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1079 | return; |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1080 | } |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1081 | |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1082 | if (address.port == 0) |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1083 | address.port = 10666; |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1084 | |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1085 | Session.set_password(args[1]); |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1086 | Session.disconnect(); |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1087 | Session.connect(CurrentAddress = address); |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1088 | } |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1089 | } |
112 | 1090 | else if (command == "disconnect") |
1091 | { | |
1092 | Session.disconnect(); | |
1093 | } | |
105
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1094 | else if (command == "quit") |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1095 | { |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1096 | Session.disconnect(); |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1097 | endwin(); |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1098 | throw Exitception(); |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1099 | } |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1100 | else |
115
bb7ef7c33dad
ZFC's own messages are now printed in blue to distinguish them from messages from the server.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
112
diff
changeset
|
1101 | print_error("Unknown command: %s\n", command.chars()); |
105
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1102 | } |
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1103 | |
111
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1104 | // ------------------------------------------------------------------------------------------------- |
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1105 | // |
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1106 | void Interface::disconnected() |
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1107 | { |
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1108 | print("Disconnected from %s\n", Session.address().to_string(IPAddress::WITH_PORT).chars()); |
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1109 | reset_title(); |
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1110 | render_full(); |
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1111 | } |
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1112 | |
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1113 | // ------------------------------------------------------------------------------------------------- |
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1114 | // |
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1115 | void Interface::reset_title() |
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1116 | { |
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1117 | Title.sprintf (APPNAME " %s (%s)", full_version_string(), changeset_date_string()); |
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1118 | } |
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1119 | |
116
552909484712
Fixed: sending a message from earlier history did not flush to a new input line, instead just up a single level in history
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
1120 | // ------------------------------------------------------------------------------------------------- |
552909484712
Fixed: sending a message from earlier history did not flush to a new input line, instead just up a single level in history
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
1121 | // |
552909484712
Fixed: sending a message from earlier history did not flush to a new input line, instead just up a single level in history
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
1122 | void Interface::flush_input() |
552909484712
Fixed: sending a message from earlier history did not flush to a new input line, instead just up a single level in history
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
1123 | { |
552909484712
Fixed: sending a message from earlier history did not flush to a new input line, instead just up a single level in history
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
1124 | InputHistory.insert (0, ""); |
552909484712
Fixed: sending a message from earlier history did not flush to a new input line, instead just up a single level in history
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
1125 | InputCursor = 0; |
552909484712
Fixed: sending a message from earlier history did not flush to a new input line, instead just up a single level in history
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
1126 | NeedInputRender = true; |
552909484712
Fixed: sending a message from earlier history did not flush to a new input line, instead just up a single level in history
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
1127 | } |
552909484712
Fixed: sending a message from earlier history did not flush to a new input line, instead just up a single level in history
Teemu Piippo <crimsondusk64@gmail.com>
parents:
115
diff
changeset
|
1128 | |
105
b4466472aecd
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
Teemu Piippo <crimsondusk64@gmail.com>
parents:
102
diff
changeset
|
1129 | END_ZFC_NAMESPACE |