Wed, 27 Jan 2021 19:42:49 +0200
update the status bar after getting disconnected
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
190 | 2 | Copyright 2014 - 2021 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 | |
128 | 40 | static const int PAGE_SIZE = 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 | // |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
44 | chtype Interface::getColorPair(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 |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
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 | // |
183
9b6a0daedfc0
renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
54 | const std::string& Interface::getCurrentInput() |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
55 | { |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
56 | return m_inputHistory[m_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 | // |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
61 | // Makes current_input() the lastmost input(so that we won't modify history) |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
62 | // |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
63 | void Interface::detachInput() |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
64 | { |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
65 | if (m_inputCursor > 0) |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
66 | { |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
67 | m_inputHistory[0] = getCurrentInput(); |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
68 | m_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 | // |
183
9b6a0daedfc0
renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
75 | std::string& Interface::getEditableInput() |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
76 | { |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
77 | detachInput(); |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
78 | return m_inputHistory[m_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 | // |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
83 | void Interface::moveInputCursor(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 |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
86 | if (m_inputState != INPUTSTATE_NORMAL) |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
87 | { |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
88 | m_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 | |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
92 | int oldcursor = m_inputCursor; |
179
7fc34735178e
start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents:
156
diff
changeset
|
93 | m_inputCursor = clamp(m_inputCursor + delta, 0, static_cast<int>(m_inputHistory.size() - 1)); |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
94 | |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
95 | if (m_inputCursor != oldcursor) |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
96 | { |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
97 | m_cursorPosition = getCurrentInput().length(); |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
98 | m_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 | // |
183
9b6a0daedfc0
renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
104 | std::string Interface::getPromptString() |
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 | { |
183
9b6a0daedfc0
renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
106 | std::string prompt; |
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
|
107 | |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
108 | switch (m_inputState) |
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 | // |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
121 | void Interface::setInputState(InputState newstate) |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
122 | { |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
123 | // Clear the input row(unless going to or from confirm state) |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
124 | if (newstate != INPUTSTATE_CONFIRM_DISCONNECTION |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
125 | and m_inputState != INPUTSTATE_CONFIRM_DISCONNECTION) |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
126 | { |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
127 | m_inputCursor = 0; |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
128 | getEditableInput().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: |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
134 | if (m_remoteAddress.host != 0) |
186
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
135 | getEditableInput() = net::ip_address_to_string(m_remoteAddress); |
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 | |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
142 | m_inputState = newstate; |
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
143 | m_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() : |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
149 | m_inputCursor(0), |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
150 | m_cursorPosition(0), |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
151 | m_inputPanning(0), |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
152 | m_needRefresh(false), |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
153 | m_needStatusBarRender(false), |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
154 | m_needInputRender(false), |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
155 | m_needOutputRender(false), |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
156 | m_needNicklistRender(false), |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
157 | m_outputScroll(0), |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
158 | m_inputState(INPUTSTATE_NORMAL), |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
159 | m_disconnectCallback(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(); |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
163 | ::keypad(stdscr, true); |
20
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(); |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
166 | ::timeout(0); |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
167 | m_inputHistory.clear(); |
179
7fc34735178e
start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents:
156
diff
changeset
|
168 | m_inputHistory.push_back(""); |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
169 | m_outputLines.clear(); |
181
e254398fcc7c
removed Container classes in favor of std::vector
Teemu Piippo <teemu@hecknology.net>
parents:
179
diff
changeset
|
170 | m_outputLines.push_back(ColoredLine()); |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
145
diff
changeset
|
171 | m_session.setInterface(this); |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
172 | resetTitle(); |
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(); |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
177 | bool hasDefaultColors =(::use_default_colors() == OK); |
119
9eb47f1899be
Fixed some warning on MSVC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
118
diff
changeset
|
178 | int defaultFg = hasDefaultColors ? -1 : COLOR_WHITE; |
9eb47f1899be
Fixed some warning on MSVC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
118
diff
changeset
|
179 | int defaultBg = hasDefaultColors ? -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 |
185
e83ec58cc458
removed the Range class too
Teemu Piippo <teemu@hecknology.net>
parents:
183
diff
changeset
|
182 | for (int i = 0; i < NUM_COLORS; i += 1) |
e83ec58cc458
removed the Range class too
Teemu Piippo <teemu@hecknology.net>
parents:
183
diff
changeset
|
183 | for (int j = 0; j < NUM_COLORS; j += 1) |
81
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); |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
186 | int fg =(i == DEFAULT) ? defaultFg : i; |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
187 | int bg =(j == DEFAULT) ? defaultBg : j; |
81
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 | { |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
191 | if (::init_pair(pairnum, fg, bg) == ERR) |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
192 | printWarning("Unable to initialize color pair %d(%d, %d)\n", pairnum, fg, bg); |
117
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 | |
138
c909c38ca886
Restyled Interface's public method names
Teemu Piippo <teemu@compsta2.com>
parents:
137
diff
changeset
|
197 | renderFull(); |
20
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
198 | refresh(); |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
199 | m_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 | |
192
94c67ae846fc
handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents:
190
diff
changeset
|
202 | Interface::~Interface() |
94c67ae846fc
handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents:
190
diff
changeset
|
203 | { |
94c67ae846fc
handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents:
190
diff
changeset
|
204 | ::endwin(); |
94c67ae846fc
handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents:
190
diff
changeset
|
205 | } |
94c67ae846fc
handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents:
190
diff
changeset
|
206 | |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
207 | // ------------------------------------------------------------------------------------------------- |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
208 | // |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
209 | void Interface::renderTitlebar() |
20
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
210 | { |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
211 | if (static_cast<signed>(m_title.length()) <= COLS) |
23
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
212 | { |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
213 | chtype pair = getColorPair(WHITE, BLUE); |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
214 | int startx =(COLS - m_title.length()) / 2; |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
215 | int endx = startx + m_title.length(); |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
216 | attron(pair); |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
217 | mvprintw(0, startx, "%s", m_title.data()); |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
218 | mvhline(0, 0, ' ', startx); |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
219 | mvhline(0, endx, ' ', COLS - endx); |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
220 | attroff(pair); |
23
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
221 | } |
f7221183a994
- the prompt is now colored
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
222 | |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
223 | m_needRefresh = true; |
20
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
224 | } |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
225 | |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
226 | // ------------------------------------------------------------------------------------------------- |
5f8cdc8febbb
- now in color! (titlebar at least anyway)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
227 | // |
183
9b6a0daedfc0
renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
228 | void Interface::setTitle(const std::string& title) |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
229 | { |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
230 | m_title = title; |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
231 | renderTitlebar(); |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
232 | } |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
233 | |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
234 | // ------------------------------------------------------------------------------------------------- |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
235 | // |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
236 | void Interface::safeDisconnect(std::function<void(bool)> afterwards) |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
237 | { |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
145
diff
changeset
|
238 | if (m_session.isActive()) |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
239 | { |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
240 | m_disconnectCallback = afterwards; |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
241 | setInputState(INPUTSTATE_CONFIRM_DISCONNECTION); |
27
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 | else |
111
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
244 | afterwards(false); |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
245 | } |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
246 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
247 | // ------------------------------------------------------------------------------------------------- |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
248 | // |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
249 | int Interface::nicklistWidth() |
47 | 250 | { |
251 | // Allocate at least 12 characters, at most 24 characters, for the nicklist. If we cannot | |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
252 | // afford that(o_O) then we probably shouldn't draw the nicklist at all I think. |
47 | 253 | int nicklistWidth = COLS / 4; |
254 | ||
255 | if (nicklistWidth < 12) | |
256 | return 0; | |
257 | ||
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
258 | return min(nicklistWidth, 24); |
47 | 259 | } |
260 | ||
261 | // ------------------------------------------------------------------------------------------------- | |
262 | // Renders the given colored line onto the screen. Will wrap if allowWrap is true. Returns the | |
263 | // 'y' value for the next line. | |
264 | // | |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
265 | int Interface::renderColorline(int y, int x0, int width, const ColoredLine& line, bool allowWrap) |
47 | 266 | { |
267 | int x = x0; | |
268 | ||
137
485cb6d6b98c
Made Range not include the 'max' parameter, replaced a lot of for()-loops with C++11-style range-for-loops
Teemu Piippo <teemu@compsta2.com>
parents:
132
diff
changeset
|
269 | for (int byte : line.data()) |
47 | 270 | { |
271 | if (x == x0 + width) | |
272 | { | |
273 | if (not allowWrap) | |
274 | return y; | |
275 | ||
276 | x = x0; | |
277 | ++y; | |
278 | } | |
279 | ||
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
280 | if (byte < 256 && isprint(byte)) |
47 | 281 | { |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
282 | mvaddch(y, x, char(byte)); |
47 | 283 | ++x; |
284 | } | |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
285 | 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
|
286 | { |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
287 | auto attrfunction =(byte < RLINE_OFF_COLOR ? &attron : &attroff); |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
288 | (*attrfunction)(getColorPair(Color((byte - RLINE_ON_COLOR) & 7), DEFAULT)); |
101
71f1cd8154a9
Slight refactor on the fix in the previous commit
Teemu Piippo <tsapii@utu.fi>
parents:
100
diff
changeset
|
289 | } |
47 | 290 | else switch (byte) |
291 | { | |
292 | case RLINE_ON_BOLD: | |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
293 | attron(A_BOLD); |
47 | 294 | break; |
295 | ||
296 | case RLINE_OFF_BOLD: | |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
297 | attroff(A_BOLD); |
47 | 298 | break; |
299 | } | |
300 | } | |
301 | ||
302 | return y + 1; | |
303 | } | |
304 | ||
305 | // ------------------------------------------------------------------------------------------------- | |
306 | // | |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
307 | void Interface::renderOutput() |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
308 | { |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
309 | if (m_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 | 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
|
311 | |
181
e254398fcc7c
removed Container classes in favor of std::vector
Teemu Piippo <teemu@hecknology.net>
parents:
179
diff
changeset
|
312 | m_outputScroll = clamp(m_outputScroll, 0, static_cast<signed>(m_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
|
313 | |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
314 | int height = LINES - 3; |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
315 | int width = COLS - nicklistWidth(); |
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
|
316 | int printOffset = 0; |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
317 | int end = m_outputLines.size() - 1 - m_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
|
318 | 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
|
319 | 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
|
320 | 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
|
321 | 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
|
322 | |
3caf69e7350b
- added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
33
diff
changeset
|
323 | // 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
|
324 | 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
|
325 | { |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
326 | int rows = m_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
|
327 | |
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 | 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
|
329 | { |
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 | // 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
|
331 | 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
|
332 | 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
|
333 | } |
3caf69e7350b
- added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
33
diff
changeset
|
334 | |
3caf69e7350b
- added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
33
diff
changeset
|
335 | 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
|
336 | 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
|
337 | } |
16
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
338 | |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
339 | // See if there's any more rows to use(end may be too small) |
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 | 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
|
341 | { |
181
e254398fcc7c
removed Container classes in favor of std::vector
Teemu Piippo <teemu@hecknology.net>
parents:
179
diff
changeset
|
342 | while (end < static_cast<int>(m_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
|
343 | { |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
344 | int rows = m_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
|
345 | |
3caf69e7350b
- added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
33
diff
changeset
|
346 | if (usedHeight + rows > height) |
3caf69e7350b
- added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
33
diff
changeset
|
347 | { |
3caf69e7350b
- added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
33
diff
changeset
|
348 | 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
|
349 | 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
|
350 | } |
16
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
351 | |
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
|
352 | 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
|
353 | 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
|
354 | } |
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 | } |
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 | |
3caf69e7350b
- added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
33
diff
changeset
|
357 | 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
|
358 | 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
|
359 | |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
360 | m_outputScroll = m_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
|
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 | 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
|
363 | 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
|
364 | |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
365 | assert(start <= end and start - end <= height); |
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
|
366 | |
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 | // Clear the display |
185
e83ec58cc458
removed the Range class too
Teemu Piippo <teemu@hecknology.net>
parents:
183
diff
changeset
|
368 | for (int i = 0; i < height; i += 1) |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
369 | mvhline(y + 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
|
370 | |
3caf69e7350b
- added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
33
diff
changeset
|
371 | // 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
|
372 | y += printOffset; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
373 | |
185
e83ec58cc458
removed the Range class too
Teemu Piippo <teemu@hecknology.net>
parents:
183
diff
changeset
|
374 | for (int i = start; i < end; i += 1) |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
375 | y = renderColorline(y, 0, width, m_outputLines[i], true); |
47 | 376 | |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
377 | m_needOutputRender = false; |
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
378 | m_needRefresh = true; |
47 | 379 | } |
380 | ||
381 | // ------------------------------------------------------------------------------------------------- | |
382 | // | |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
383 | void Interface::renderNicklist() |
47 | 384 | { |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
385 | int width = nicklistWidth(); |
47 | 386 | int height = LINES- 3; |
387 | int y = 1; | |
388 | int x = COLS - width; | |
389 | ||
137
485cb6d6b98c
Made Range not include the 'max' parameter, replaced a lot of for()-loops with C++11-style range-for-loops
Teemu Piippo <teemu@compsta2.com>
parents:
132
diff
changeset
|
390 | if (width > 0) |
47 | 391 | return; |
392 | ||
185
e83ec58cc458
removed the Range class too
Teemu Piippo <teemu@hecknology.net>
parents:
183
diff
changeset
|
393 | for (int i = 0; i < height; i += 1) |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
394 | { |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
395 | mvhline(y, x, ' ', width); |
32
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
396 | |
179
7fc34735178e
start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents:
156
diff
changeset
|
397 | if (i < static_cast<signed>(m_playerNames.size())) |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
398 | renderColorline(y, x, width, m_playerNames[i], false); |
32
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
399 | |
47 | 400 | y++; |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
401 | } |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
402 | |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
403 | m_needNicklistRender = false; |
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
404 | m_needRefresh = true; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
405 | } |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
406 | |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
407 | // ------------------------------------------------------------------------------------------------- |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
408 | // |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
409 | void Interface::renderInput() |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
410 | { |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
411 | chtype promptColor = getColorPair(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
|
412 | |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
413 | // 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
|
414 | // just the confirmation message. |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
415 | if (m_inputState == 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
|
416 | { |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
417 | attron(promptColor); |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
418 | mvhline(LINES - 2, 0, ' ', COLS); |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
419 | mvprintw(LINES - 2, 0, "Are you sure you want to disconnect? y/n"); |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
420 | attroff(promptColor); |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
421 | m_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
|
422 | 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
|
423 | } |
e651d02802c0
- the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents:
23
diff
changeset
|
424 | |
183
9b6a0daedfc0
renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
425 | std::string prompt = getPromptString(); |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
426 | int displayLength = COLS - prompt.length() - 2; |
183
9b6a0daedfc0
renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
427 | std::string displayString = getCurrentInput(); |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
428 | int y = LINES - 2; |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
429 | |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
430 | // If we're inputting a password, replace it with asterisks |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
431 | if (m_inputState == INPUTSTATE_PASSWORD) |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
432 | { |
137
485cb6d6b98c
Made Range not include the 'max' parameter, replaced a lot of for()-loops with C++11-style range-for-loops
Teemu Piippo <teemu@compsta2.com>
parents:
132
diff
changeset
|
433 | for (char &ch : displayString) |
485cb6d6b98c
Made Range not include the 'max' parameter, replaced a lot of for()-loops with C++11-style range-for-loops
Teemu Piippo <teemu@compsta2.com>
parents:
132
diff
changeset
|
434 | ch = '*'; |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
435 | } |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
436 | |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
437 | // Ensure the cursor is within bounds |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
438 | m_cursorPosition = clamp(m_cursorPosition, 0, static_cast<signed>(displayString.length())); |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
439 | |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
440 | // Ensure that the cursor is always in view, adjust panning if this is not the case |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
441 | if (m_cursorPosition > m_inputPanning + displayLength) |
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
442 | m_inputPanning = m_cursorPosition - displayLength; // cursor went too far right |
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
443 | else if (m_cursorPosition < m_inputPanning) |
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
444 | m_inputPanning = m_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
|
445 | |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
446 | // What part of the string to draw? |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
447 | int start = m_inputPanning; |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
448 | int end = min<int>(displayString.length(), start + displayLength); |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
449 | assert(m_cursorPosition >= start and m_cursorPosition <= end); |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
450 | |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
451 | // Render the input string |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
452 | mvhline(LINES - 2, 0, ' ', COLS); |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
453 | mvprintw(y, prompt.length() + 1, "%s", mid(displayString, start, end).data()); |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
454 | |
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
455 | // Render the prompt |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
456 | attron(promptColor); |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
457 | mvprintw(y, 0, "%s", prompt.data()); |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
458 | attroff(promptColor); |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
459 | |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
460 | // Store in memory where the cursor is now(so that we can re-draw it to position the terminal |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
461 | // cursor). |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
462 | m_cursorCharacter.ch = m_cursorPosition != 0 ? displayString[m_cursorPosition - 1] : '\0'; |
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
463 | m_cursorCharacter.x = prompt.length() + (m_cursorPosition - m_inputPanning); |
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
464 | m_needRefresh = true; |
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
465 | m_needInputRender = false; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
466 | } |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
467 | |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
468 | // ------------------------------------------------------------------------------------------------- |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
469 | // |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
470 | void Interface::renderStatusBar() |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
471 | { |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
472 | chtype color = getColorPair(WHITE, BLUE); |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
473 | int y = LINES - 1; |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
474 | attron(color); |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
475 | mvhline(y, 0, ' ', COLS); |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
476 | mvprintw(y, 0, "%s", m_statusBarText.data()); |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
477 | attroff(color); |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
478 | m_needRefresh = true; |
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
479 | m_needStatusBarRender = false; |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
480 | } |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
481 | |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
482 | // ------------------------------------------------------------------------------------------------- |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
483 | // |
138
c909c38ca886
Restyled Interface's public method names
Teemu Piippo <teemu@compsta2.com>
parents:
137
diff
changeset
|
484 | void Interface::updateStatusBar() |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
485 | { |
183
9b6a0daedfc0
renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
486 | std::string text; |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
487 | |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
145
diff
changeset
|
488 | switch (m_session.getState()) |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
489 | { |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
490 | case RCON_DISCONNECTED: |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
491 | text = "Disconnected."; |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
492 | break; |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
493 | |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
494 | case RCON_CONNECTING: |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
495 | case RCON_AUTHENTICATING: |
186
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
496 | text = "Connecting to " + net::ip_address_to_string(m_session.address()) + "..."; |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
497 | break; |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
498 | |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
499 | case RCON_CONNECTED: |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
500 | { |
183
9b6a0daedfc0
renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
501 | std::string adminText; |
72 | 502 | |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
145
diff
changeset
|
503 | if (m_session.getAdminCount() == 0) |
83
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
504 | { |
72 | 505 | 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
|
506 | } |
72 | 507 | else |
83
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
508 | { |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
509 | adminText = zfc::sprintf("%d other admin%s", m_session.getAdminCount(), |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
145
diff
changeset
|
510 | m_session.getAdminCount() != 1 ? "s" : ""); |
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 | |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
513 | text = zfc::sprintf("%s | %s | %s", |
186
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
514 | net::ip_address_to_string(m_session.address()).data(), |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
515 | m_session.getLevel().data(), |
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
516 | adminText.data()); |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
517 | } |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
518 | break; |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
519 | } |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
520 | |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
521 | if (not text.empty()) |
28
3cc042af3090
- added a help message to the statusbar
Teemu Piippo <crimsondusk64@gmail.com>
parents:
27
diff
changeset
|
522 | text += " | "; |
3cc042af3090
- added a help message to the statusbar
Teemu Piippo <crimsondusk64@gmail.com>
parents:
27
diff
changeset
|
523 | |
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
|
524 | text += "Ctrl+N to connect, Ctrl+Q to "; |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
145
diff
changeset
|
525 | text +=(m_session.getState() == RCON_DISCONNECTED) ? "quit" : "disconnect"; |
28
3cc042af3090
- added a help message to the statusbar
Teemu Piippo <crimsondusk64@gmail.com>
parents:
27
diff
changeset
|
526 | |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
527 | if (text != m_statusBarText) |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
528 | { |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
529 | m_statusBarText = text; |
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
530 | m_needStatusBarRender = true; |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
531 | } |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
532 | } |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
533 | |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
534 | // ------------------------------------------------------------------------------------------------- |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
535 | // |
138
c909c38ca886
Restyled Interface's public method names
Teemu Piippo <teemu@compsta2.com>
parents:
137
diff
changeset
|
536 | void Interface::renderFull() |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
537 | { |
138
c909c38ca886
Restyled Interface's public method names
Teemu Piippo <teemu@compsta2.com>
parents:
137
diff
changeset
|
538 | updateStatusBar(); |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
539 | renderTitlebar(); |
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
540 | renderOutput(); |
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
541 | renderStatusBar(); |
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
542 | renderInput(); |
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
543 | renderNicklist(); |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
544 | } |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
545 | |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
546 | // ------------------------------------------------------------------------------------------------- |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
547 | // |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
548 | void Interface::positionCursor() |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
549 | { |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
550 | // This is only relevant if the input string is being drawn |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
551 | if (m_inputState == INPUTSTATE_CONFIRM_DISCONNECTION) |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
552 | return; |
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
553 | |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
554 | int y = LINES - 2; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
555 | |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
556 | if (m_cursorCharacter.ch != '\0') |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
557 | mvprintw(y, m_cursorCharacter.x, "%c", m_cursorCharacter.ch); |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
558 | else |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
559 | mvprintw(y, getPromptString().length(), " "); |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
560 | } |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
561 | |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
562 | // ------------------------------------------------------------------------------------------------- |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
563 | // |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
564 | int Interface::findPreviousWord() |
43
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
565 | { |
183
9b6a0daedfc0
renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
566 | const std::string& input = getCurrentInput(); |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
567 | int pos = m_cursorPosition; |
43
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
568 | |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
569 | // Move past whitespace |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
570 | while (pos > 0 and isspace(input[pos - 1])) |
43
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
571 | pos--; |
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 | // Move past the word |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
574 | while (pos > 0 and not isspace(input[pos - 1])) |
43
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
575 | pos--; |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
576 | |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
577 | return pos; |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
578 | } |
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 | // ------------------------------------------------------------------------------------------------- |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
581 | // |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
582 | int Interface::findNextWord() |
43
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
583 | { |
183
9b6a0daedfc0
renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
584 | const std::string& input = getCurrentInput(); |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
585 | int pos = m_cursorPosition; |
43
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 | // Move past current whitespace |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
588 | while (pos < static_cast<signed>(input.length()) and isspace(input[pos])) |
43
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
589 | pos++; |
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 | // Move past the word |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
592 | while (input[pos] != '\0' and not isspace(input[pos])) |
43
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
593 | pos++; |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
594 | |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
595 | return pos; |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
596 | } |
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 | // ------------------------------------------------------------------------------------------------- |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
599 | // |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
600 | 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
|
601 | { |
8f1a6f40d1b4
- added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
52
diff
changeset
|
602 | if (a >= b) |
8f1a6f40d1b4
- added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
52
diff
changeset
|
603 | return; |
8f1a6f40d1b4
- added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
52
diff
changeset
|
604 | |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
605 | if (m_cursorPosition > a and m_cursorPosition <= b) |
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
606 | m_cursorPosition = a; |
53
8f1a6f40d1b4
- added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
52
diff
changeset
|
607 | |
183
9b6a0daedfc0
renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
608 | std::string& input = getEditableInput(); |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
609 | m_pasteBuffer = mid(input, a, b); |
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
610 | input = remove_range(input, a, b - a); |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
611 | m_needInputRender = true; |
53
8f1a6f40d1b4
- added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
52
diff
changeset
|
612 | } |
8f1a6f40d1b4
- added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
52
diff
changeset
|
613 | |
186
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
614 | bool Interface::tryResolveAddress(const std::string &address_string, net::ip_address* target) |
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
615 | { |
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
616 | std::stringstream errors; |
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
617 | const std::optional<net::ip_address> address_opt = net::ip_resolve(address_string, errors); |
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
618 | if (address_opt.has_value()) |
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
619 | { |
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
620 | *target = address_opt.value(); |
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
621 | if (target->port == 0) |
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
622 | { |
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
623 | target->port = 10666; |
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
624 | } |
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
625 | return true; |
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
626 | } |
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
627 | else |
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
628 | { |
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
629 | this->printError("%s\n", errors.str().data()); |
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
630 | return false; |
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
631 | } |
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
632 | } |
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
633 | |
53
8f1a6f40d1b4
- added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
52
diff
changeset
|
634 | // ------------------------------------------------------------------------------------------------- |
8f1a6f40d1b4
- added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
52
diff
changeset
|
635 | // |
192
94c67ae846fc
handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents:
190
diff
changeset
|
636 | void Interface::handleInput(bool* shouldquit) |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
637 | { |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
638 | int ch = ::getch(); |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
639 | |
81
a18aaf460648
Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
640 | if (ch < 0) |
a18aaf460648
Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
641 | return; |
a18aaf460648
Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
642 | |
33
bb209480d0ec
- handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
643 | if (ch == KEY_RESIZE) |
bb209480d0ec
- handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
644 | { |
bb209480d0ec
- handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
645 | ::clear(); |
138
c909c38ca886
Restyled Interface's public method names
Teemu Piippo <teemu@compsta2.com>
parents:
137
diff
changeset
|
646 | renderFull(); |
33
bb209480d0ec
- handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
647 | return; |
bb209480d0ec
- handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
648 | } |
bb209480d0ec
- handle resizing 8-)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
649 | |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
650 | if (m_inputState == 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
|
651 | { |
e651d02802c0
- the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents:
23
diff
changeset
|
652 | 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
|
653 | { |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
654 | m_session.disconnect(); |
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
655 | m_disconnectCallback(true); |
193
fb1709f27108
update the status bar after getting disconnected
Teemu Piippo <teemu@hecknology.net>
parents:
192
diff
changeset
|
656 | this->updateStatusBar(); |
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
|
657 | } |
24
e651d02802c0
- the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents:
23
diff
changeset
|
658 | else if (ch == 'n' or ch == 'N') |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
659 | setInputState(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
|
660 | |
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
|
661 | 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
|
662 | } |
e651d02802c0
- the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents:
23
diff
changeset
|
663 | |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
664 | 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
|
665 | { |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
666 | std::string& input = getEditableInput(); |
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
667 | input.insert(input.begin() + m_cursorPosition, char(ch)); |
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
668 | m_cursorPosition += 1; |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
669 | m_needInputRender = true; |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
670 | } |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
671 | else switch (ch) |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
672 | { |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
673 | case 'Q' - 'A' + 1: // ^Q |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
674 | switch (m_inputState) |
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 | case INPUTSTATE_CONFIRM_DISCONNECTION: |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
677 | break; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
678 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
679 | case INPUTSTATE_NORMAL: |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
680 | safeDisconnect([&](bool hadsession) |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
681 | { |
111
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
682 | if (hadsession) |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
683 | { |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
684 | setInputState(INPUTSTATE_NORMAL); |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
685 | } |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
686 | else |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
687 | { |
192
94c67ae846fc
handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents:
190
diff
changeset
|
688 | *shouldquit = true; |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
689 | } |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
690 | }); |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
691 | break; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
692 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
693 | case INPUTSTATE_PASSWORD: |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
694 | setInputState(INPUTSTATE_ADDRESS); |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
695 | break; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
696 | |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
697 | case INPUTSTATE_ADDRESS: |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
698 | setInputState(INPUTSTATE_NORMAL); |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
699 | } |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
700 | break; |
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
25
diff
changeset
|
701 | |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
702 | 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
|
703 | case 'B' - 'A' + 1: // readline ^B |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
704 | if (m_cursorPosition > 0) |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
705 | { |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
706 | m_cursorPosition--; |
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
707 | m_needInputRender = true; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
708 | } |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
709 | break; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
710 | |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
711 | 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
|
712 | case 'F' - 'A' + 1: // readline ^F |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
713 | if (m_cursorPosition < static_cast<int>(getCurrentInput().length())) |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
714 | { |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
715 | m_cursorPosition++; |
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
716 | m_needInputRender = true; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
717 | } |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
718 | break; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
719 | |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
720 | case KEY_DOWN: |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
721 | case KEY_UP: |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
722 | moveInputCursor(ch == KEY_DOWN ? -1 : 1); |
31
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
723 | break; |
b5b5a6a96d91
- added input history (use up/down to navigate)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
724 | |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
725 | 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
|
726 | case 'A' - 'A' + 1: // readline ^A |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
727 | if (m_cursorPosition != 0) |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
728 | { |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
729 | m_cursorPosition = 0; |
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
730 | m_needInputRender = true; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
731 | } |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
732 | break; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
733 | |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
734 | 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
|
735 | case 'E' - 'A' + 1: // readline ^E |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
736 | if (m_cursorPosition != static_cast<signed>(getCurrentInput().length())) |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
737 | { |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
738 | m_cursorPosition = getCurrentInput().length(); |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
739 | m_needInputRender = true; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
740 | } |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
741 | break; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
742 | |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
743 | case KEY_BACKSPACE: |
81
a18aaf460648
Allow compilation on Windows/MinGW
Teemu Piippo <crimsondusk64@gmail.com>
parents:
73
diff
changeset
|
744 | case '\b': |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
745 | if (m_cursorPosition > 0) |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
746 | { |
183
9b6a0daedfc0
renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
747 | std::string& input = getEditableInput(); |
187
53f9c7b2c068
fixed an off-by-one error
Teemu Piippo <teemu@hecknology.net>
parents:
186
diff
changeset
|
748 | input.erase(input.begin() + m_cursorPosition - 1); |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
749 | m_cursorPosition -= 1; |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
750 | m_needInputRender = true; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
751 | } |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
752 | break; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
753 | |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
754 | 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
|
755 | case 'D' - 'A' + 1: // readline ^D |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
756 | if (m_cursorPosition < static_cast<signed>(getCurrentInput().length())) |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
757 | { |
183
9b6a0daedfc0
renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
758 | std::string& input = getEditableInput(); |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
759 | input.erase(input.begin() + m_cursorPosition); |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
760 | m_needInputRender = true; |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
761 | } |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
762 | break; |
16
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
763 | |
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
764 | case KEY_PPAGE: |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
765 | m_outputScroll += min(PAGE_SIZE, LINES / 2); |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
766 | m_needOutputRender = true; |
16
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
767 | break; |
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
768 | |
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
769 | case KEY_NPAGE: |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
770 | m_outputScroll -= min(PAGE_SIZE, LINES / 2); |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
771 | m_needOutputRender = true; |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
772 | break; |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
773 | |
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
|
774 | case 'U' - 'A' + 1: // readline ^U - delete from start to cursor |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
775 | if (m_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
|
776 | { |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
777 | yank(0, m_cursorPosition); |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
778 | m_cursorPosition = 0; |
42
9699687081df
- added readline shortcuts: ^B, ^F, ^A, ^E, ^D (aliases to keyboard presses), ^U, ^K (new functionality)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
34
diff
changeset
|
779 | } |
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
|
780 | 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
|
781 | |
9699687081df
- added readline shortcuts: ^B, ^F, ^A, ^E, ^D (aliases to keyboard presses), ^U, ^K (new functionality)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
34
diff
changeset
|
782 | case 'K' - 'A' + 1: // readline ^K - delete from cursor to end |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
783 | yank(m_cursorPosition, getEditableInput().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
|
784 | 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
|
785 | |
44
693d7751fff0
- added readline alt-d and ^w support (delete till word boundaries)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
43
diff
changeset
|
786 | case 'W' - 'A' + 1: // readline ^W - delete from previous word bounary to current |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
787 | yank(findPreviousWord(), m_cursorPosition); |
53
8f1a6f40d1b4
- added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
52
diff
changeset
|
788 | break; |
44
693d7751fff0
- added readline alt-d and ^w support (delete till word boundaries)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
43
diff
changeset
|
789 | |
53
8f1a6f40d1b4
- added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
52
diff
changeset
|
790 | case 'Y' - 'A' + 1: // readline ^Y - paste previously deleted text |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
791 | if (not m_pasteBuffer.empty()) |
53
8f1a6f40d1b4
- added yanking/pasting (support for readline ^Y)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
52
diff
changeset
|
792 | { |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
793 | getEditableInput().insert(m_cursorPosition, m_pasteBuffer); |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
794 | m_cursorPosition += m_pasteBuffer.length(); |
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
795 | m_needInputRender = true; |
44
693d7751fff0
- added readline alt-d and ^w support (delete till word boundaries)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
43
diff
changeset
|
796 | } |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
797 | break; |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
798 | |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
799 | case '\t': |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
800 | { |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
801 | int space = getCurrentInput().find(" "); |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
802 | |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
803 | if (m_inputState == INPUTSTATE_NORMAL |
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
804 | and m_cursorPosition > 0 |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
805 | and(space == -1 or space >= m_cursorPosition)) |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
806 | { |
183
9b6a0daedfc0
renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
807 | std::string start = mid(getCurrentInput(), 0, m_cursorPosition); |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
145
diff
changeset
|
808 | m_session.requestTabCompletion(start); |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
809 | } |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
810 | } |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
811 | break; |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
812 | |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
813 | 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
|
814 | case '\r': |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
815 | case KEY_ENTER: |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
816 | switch (m_inputState) |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
817 | { |
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
|
818 | 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
|
819 | 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
|
820 | |
e651d02802c0
- the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents:
23
diff
changeset
|
821 | case INPUTSTATE_ADDRESS: |
186
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
822 | if (this->tryResolveAddress(this->getCurrentInput(), &this->m_remoteAddress)) |
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
|
823 | { |
186
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
824 | setInputState(INPUTSTATE_PASSWORD); |
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
|
825 | } |
25
88b41eea08e0
- cleanup, refactor + better input handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
24
diff
changeset
|
826 | 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
|
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 | case INPUTSTATE_PASSWORD: |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
829 | if (m_inputState == INPUTSTATE_PASSWORD and not getCurrentInput().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
|
830 | { |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
831 | m_session.disconnect(); |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
145
diff
changeset
|
832 | m_session.setPassword(getCurrentInput()); |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
833 | m_session.connect(m_remoteAddress); |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
834 | setInputState(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
|
835 | } |
e651d02802c0
- the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents:
23
diff
changeset
|
836 | 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
|
837 | |
e651d02802c0
- the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents:
23
diff
changeset
|
838 | case INPUTSTATE_NORMAL: |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
839 | if (getCurrentInput()[0] == '/') |
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
|
840 | { |
192
94c67ae846fc
handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents:
190
diff
changeset
|
841 | handleCommand(getCurrentInput(), shouldquit); |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
842 | flushInput(); |
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
|
843 | } |
156
ce66d7e374bf
Restyled RCONSession method names and paren style
Teemu Piippo <teemu@compsta2.com>
parents:
145
diff
changeset
|
844 | else if (m_session.sendCommand(getCurrentInput())) |
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
|
845 | { |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
846 | flushInput(); |
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
|
847 | } |
e651d02802c0
- the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents:
23
diff
changeset
|
848 | 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
|
849 | } |
e651d02802c0
- the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents:
23
diff
changeset
|
850 | 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
|
851 | |
e651d02802c0
- the interface is now able to connect to arbitrary hosts (uses ^N to start the prompt) instead of the hardcoded localhost:10666
Teemu Piippo <crimsondusk64@gmail.com>
parents:
23
diff
changeset
|
852 | case 'N' - 'A' + 1: // ^N |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
853 | if (m_inputState == INPUTSTATE_NORMAL) |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
854 | safeDisconnect([&](bool){setInputState(INPUTSTATE_ADDRESS);}); |
16
33bac54867bf
- added backlog scrolling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
855 | break; |
43
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
856 | |
91
ac02cf1c3576
'\e' is non-standard use '\x1b' instead
Teemu Piippo <tsapii@utu.fi>
parents:
89
diff
changeset
|
857 | 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
|
858 | // 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
|
859 | ch = ::getch(); |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
860 | |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
861 | if (ch != ERR) |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
862 | { |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
863 | switch (ch) |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
864 | { |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
865 | case 'b': |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
866 | case 'B': |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
867 | // readline alt-b - move one word to the left |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
868 | m_cursorPosition = findPreviousWord(); |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
869 | m_needInputRender = true; |
43
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
870 | break; |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
871 | |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
872 | case 'f': |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
873 | case 'F': |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
874 | // readline alt-f - move one word to the right |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
875 | m_cursorPosition = findNextWord(); |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
876 | m_needInputRender = true; |
43
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
877 | break; |
44
693d7751fff0
- added readline alt-d and ^w support (delete till word boundaries)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
43
diff
changeset
|
878 | |
693d7751fff0
- added readline alt-d and ^w support (delete till word boundaries)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
43
diff
changeset
|
879 | case 'd': |
693d7751fff0
- added readline alt-d and ^w support (delete till word boundaries)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
43
diff
changeset
|
880 | case 'D': |
693d7751fff0
- added readline alt-d and ^w support (delete till word boundaries)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
43
diff
changeset
|
881 | // readline alt-d - delete from here till next word boundary |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
882 | yank(m_cursorPosition, findNextWord()); |
44
693d7751fff0
- added readline alt-d and ^w support (delete till word boundaries)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
43
diff
changeset
|
883 | break; |
118
ae284bf1b5ff
Added support for alt+backspace, which removes the previous word
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
884 | |
ae284bf1b5ff
Added support for alt+backspace, which removes the previous word
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
885 | 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
|
886 | case '\b': |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
887 | yank(findPreviousWord(), m_cursorPosition); |
118
ae284bf1b5ff
Added support for alt+backspace, which removes the previous word
Teemu Piippo <crimsondusk64@gmail.com>
parents:
117
diff
changeset
|
888 | break; |
43
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
889 | } |
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 | else |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
892 | { |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
893 | // No alt-key, handle pure escape |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
894 | if (m_inputState == INPUTSTATE_PASSWORD) |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
895 | setInputState(INPUTSTATE_ADDRESS); |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
896 | else if (m_inputState == INPUTSTATE_ADDRESS) |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
897 | setInputState(INPUTSTATE_NORMAL); |
43
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
898 | } |
0bc07f54f522
- added readline alt-b and alt-f support (skip past words)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
899 | break; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
900 | } |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
901 | |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
902 | render(); |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
903 | } |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
904 | |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
905 | // ------------------------------------------------------------------------------------------------- |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
906 | // |
72 | 907 | void Interface::render() |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
908 | { |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
909 | if (m_needStatusBarRender) renderStatusBar(); |
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
910 | if (m_needInputRender) renderInput(); |
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
911 | if (m_needOutputRender) renderOutput(); |
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
912 | if (m_needNicklistRender) renderNicklist(); |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
913 | |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
914 | if (m_needRefresh) |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
915 | { |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
916 | positionCursor(); |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
917 | refresh(); |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
918 | m_needRefresh = false; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
919 | } |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
920 | } |
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
921 | |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
922 | // ------------------------------------------------------------------------------------------------- |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
16
diff
changeset
|
923 | // |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
924 | void Interface::vprint(const char* fmtstr, va_list args) |
83
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
925 | { |
183
9b6a0daedfc0
renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
926 | std::string message; |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
927 | message = vsprintf(fmtstr, args); |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
928 | printToConsole(message); |
83
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
929 | } |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
930 | |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
931 | // ------------------------------------------------------------------------------------------------- |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
932 | // |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
933 | void __cdecl Interface::printText(const char* 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
|
934 | { |
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
|
935 | va_list args; |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
936 | va_start(args, fmtstr); |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
937 | vprint(fmtstr, args); |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
938 | va_end(args); |
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 | } |
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
|
940 | |
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
|
941 | // ------------------------------------------------------------------------------------------------- |
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
|
942 | // |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
943 | void __cdecl Interface::print(const char* fmtstr, ...) |
83
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 | va_list args; |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
946 | va_start(args, fmtstr); |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
947 | printToConsole(TEXTCOLOR_BrightBlue); |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
948 | vprint(fmtstr, args); |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
949 | va_end(args); |
83
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
950 | } |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
951 | |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
952 | // ------------------------------------------------------------------------------------------------- |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
953 | // |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
954 | void __cdecl Interface::printWarning(const char* fmtstr, ...) |
83
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 | va_list args; |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
957 | va_start(args, fmtstr); |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
958 | printToConsole(TEXTCOLOR_BrightYellow "-!- "); |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
959 | vprint(fmtstr, args); |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
960 | va_end(args); |
83
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
961 | } |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
962 | |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
963 | // ------------------------------------------------------------------------------------------------- |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
964 | // |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
965 | void __cdecl Interface::printError(const char* fmtstr, ...) |
83
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 | va_list args; |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
968 | va_start(args, fmtstr); |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
969 | printToConsole(TEXTCOLOR_BrightRed "!!! "); |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
970 | vprint(fmtstr, args); |
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
971 | va_end(args); |
83
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
972 | } |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
973 | |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
974 | // ------------------------------------------------------------------------------------------------- |
08bfc3d9d2ae
Removed format.cpp and format.h, use built-in formatting instead
Teemu Piippo <crimsondusk64@gmail.com>
parents:
82
diff
changeset
|
975 | // |
183
9b6a0daedfc0
renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
976 | void Interface::printToConsole(std::string message) |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
977 | { |
72 | 978 | // Zandronum sometimes sends color codes as "\\c" and sometimes as "\x1C". |
979 | // Let's correct that on our end and hope this won't cause conflicts. | |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
980 | replace_all(message, "\\c", "\x1C"); |
32
ee770597a281
- added support for in-game colors
Teemu Piippo <crimsondusk64@gmail.com>
parents:
31
diff
changeset
|
981 | |
137
485cb6d6b98c
Made Range not include the 'max' parameter, replaced a lot of for()-loops with C++11-style range-for-loops
Teemu Piippo <teemu@compsta2.com>
parents:
132
diff
changeset
|
982 | for (char ch : message) |
15
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 | if (ch == '\n') |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
985 | { |
181
e254398fcc7c
removed Container classes in favor of std::vector
Teemu Piippo <teemu@hecknology.net>
parents:
179
diff
changeset
|
986 | zfc::last(m_outputLines).finalize(); |
e254398fcc7c
removed Container classes in favor of std::vector
Teemu Piippo <teemu@hecknology.net>
parents:
179
diff
changeset
|
987 | m_outputLines.push_back({}); |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
988 | continue; |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
989 | } |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
990 | |
181
e254398fcc7c
removed Container classes in favor of std::vector
Teemu Piippo <teemu@hecknology.net>
parents:
179
diff
changeset
|
991 | if (zfc::last(m_outputLines).length() == 0) |
51
481073b016a9
- added timestamps to output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
50
diff
changeset
|
992 | { |
481073b016a9
- added timestamps to output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
50
diff
changeset
|
993 | time_t now; |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
994 | time(&now); |
51
481073b016a9
- added timestamps to output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
50
diff
changeset
|
995 | char timestamp[32]; |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
996 | strftime(timestamp, sizeof timestamp, "[%H:%M:%S] ", localtime(&now)); |
51
481073b016a9
- added timestamps to output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
50
diff
changeset
|
997 | |
183
9b6a0daedfc0
renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
998 | for (char ch : std::string(timestamp)) |
181
e254398fcc7c
removed Container classes in favor of std::vector
Teemu Piippo <teemu@hecknology.net>
parents:
179
diff
changeset
|
999 | zfc::last(m_outputLines).addChar(ch); |
51
481073b016a9
- added timestamps to output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
50
diff
changeset
|
1000 | } |
481073b016a9
- added timestamps to output
Teemu Piippo <crimsondusk64@gmail.com>
parents:
50
diff
changeset
|
1001 | |
111
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1002 | // Remove some lines if there's too many of them. 20,000 should be enough, I hope. |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
1003 | while (m_outputLines.size() > 20000) |
181
e254398fcc7c
removed Container classes in favor of std::vector
Teemu Piippo <teemu@hecknology.net>
parents:
179
diff
changeset
|
1004 | m_outputLines.erase(m_outputLines.begin()); |
111
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1005 | |
181
e254398fcc7c
removed Container classes in favor of std::vector
Teemu Piippo <teemu@hecknology.net>
parents:
179
diff
changeset
|
1006 | zfc::last(m_outputLines).addChar(ch); |
15
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
1007 | } |
33da84af4bba
- log area done, re-enabled the rcon connection
Teemu Piippo <crimsondusk64@gmail.com>
parents:
14
diff
changeset
|
1008 | |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
1009 | m_needOutputRender = true; |
14
33b8f428bacb
- begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1010 | } |
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
|
1011 | |
21fba5183768
- added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
1012 | // ------------------------------------------------------------------------------------------------- |
21fba5183768
- added a simple command-line interface (you can now supply host and password on the command-line)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
1013 | // |
186
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
1014 | void Interface::connect(std::string address_string, std::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
|
1015 | { |
186
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
1016 | if (this->tryResolveAddress(address_string, &this->m_remoteAddress)) |
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 | { |
186
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
1018 | m_session.disconnect(); |
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
1019 | m_session.setPassword(password); |
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
1020 | m_session.connect(m_remoteAddress); |
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
|
1021 | } |
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 | } |
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
|
1023 | |
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
|
1024 | // ------------------------------------------------------------------------------------------------- |
3caf69e7350b
- added line-wrapping to the output widget: lines to output are now first compiled into renderer-friendly format. the output view then uses these pre-processed lines to determine what lines to render. Phew! What a monster of a commit.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
33
diff
changeset
|
1025 | // |
183
9b6a0daedfc0
renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
1026 | void Interface::setPlayerNames(const std::vector<std::string>& 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
|
1027 | { |
132
8a4690db252e
Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents:
128
diff
changeset
|
1028 | m_playerNames.clear(); |
8a4690db252e
Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents:
128
diff
changeset
|
1029 | |
183
9b6a0daedfc0
renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
1030 | for (const std::string& name : names) |
132
8a4690db252e
Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents:
128
diff
changeset
|
1031 | { |
8a4690db252e
Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents:
128
diff
changeset
|
1032 | ColoredLine coloredname; |
143
b9993733952a
Renamed the methods of ColoredLine
Teemu Piippo <teemu@compsta2.com>
parents:
140
diff
changeset
|
1033 | coloredname.addString(name); |
132
8a4690db252e
Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents:
128
diff
changeset
|
1034 | coloredname.finalize(); |
179
7fc34735178e
start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents:
156
diff
changeset
|
1035 | m_playerNames.push_back(coloredname); |
132
8a4690db252e
Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents:
128
diff
changeset
|
1036 | } |
8a4690db252e
Added support for colored nicknames
Teemu Piippo <crimsondusk64@gmail.com>
parents:
128
diff
changeset
|
1037 | |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
1038 | m_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
|
1039 | } |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
1040 | |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
1041 | // ------------------------------------------------------------------------------------------------- |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
1042 | // |
183
9b6a0daedfc0
renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
1043 | void Interface::tabComplete(const std::string& part, std::string complete) |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
1044 | { |
183
9b6a0daedfc0
renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
1045 | std::string& input = getEditableInput(); |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
1046 | |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
1047 | if (starts_with(input, part)) |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
1048 | { |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
1049 | if (input[part.length()] != ' ') |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
1050 | complete += ' '; |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
1051 | |
140
e49aa4aa98c0
Reformatted parentheses in interface.cpp.
Teemu Piippo <teemu@compsta2.com>
parents:
139
diff
changeset
|
1052 | input.replace(0, part.length(), complete); |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
1053 | m_cursorPosition = complete.length(); |
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
1054 | m_needInputRender = true; |
41
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
1055 | } |
9ab869656b9e
- re-commit tab-complete
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
1056 | } |
88
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
86
diff
changeset
|
1057 | |
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
|
1058 | // ------------------------------------------------------------------------------------------------- |
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 | // |
192
94c67ae846fc
handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents:
190
diff
changeset
|
1060 | void Interface::handleCommand(const std::string& input, bool* shouldquit) |
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
|
1061 | { |
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 | 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
|
1063 | 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
|
1064 | |
183
9b6a0daedfc0
renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
1065 | std::vector<std::string> args = split(right(input, input.length() - 1), " "); |
9b6a0daedfc0
renamed String and StringList uses
Teemu Piippo <teemu@hecknology.net>
parents:
182
diff
changeset
|
1066 | std::string command = to_lowercase(args[0]); |
179
7fc34735178e
start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents:
156
diff
changeset
|
1067 | args.erase(args.begin()); |
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
|
1068 | |
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 | 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
|
1070 | { |
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 | if (args.size() != 2) |
120
32ba3ae4daf1
Fixed missing newline in /connect usage message
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
1072 | { |
138
c909c38ca886
Restyled Interface's public method names
Teemu Piippo <teemu@compsta2.com>
parents:
137
diff
changeset
|
1073 | printError("Usage: /connect <address> <password>\n"); |
120
32ba3ae4daf1
Fixed missing newline in /connect usage message
Teemu Piippo <crimsondusk64@gmail.com>
parents:
119
diff
changeset
|
1074 | } |
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
|
1075 | 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
|
1076 | { |
186
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
1077 | this->connect(args[0], args[1]); |
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
|
1078 | } |
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 | } |
112 | 1080 | else if (command == "disconnect") |
1081 | { | |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
1082 | m_session.disconnect(); |
112 | 1083 | } |
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
|
1084 | 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
|
1085 | { |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
1086 | m_session.disconnect(); |
192
94c67ae846fc
handle exiting ZFC without using exceptions
Teemu Piippo <teemu@hecknology.net>
parents:
190
diff
changeset
|
1087 | *shouldquit = true; |
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
|
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 | else |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
1090 | printError("Unknown command: %s\n", command.data()); |
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
|
1091 | } |
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
|
1092 | |
111
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1093 | // ------------------------------------------------------------------------------------------------- |
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1094 | // |
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1095 | void Interface::disconnected() |
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1096 | { |
186
9330b93d9946
cleanup ip address code
Teemu Piippo <teemu@hecknology.net>
parents:
185
diff
changeset
|
1097 | print("Disconnected from %s\n", net::ip_address_to_string(m_session.address()).data()); |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
1098 | resetTitle(); |
138
c909c38ca886
Restyled Interface's public method names
Teemu Piippo <teemu@compsta2.com>
parents:
137
diff
changeset
|
1099 | renderFull(); |
111
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1100 | } |
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1101 | |
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1102 | // ------------------------------------------------------------------------------------------------- |
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1103 | // |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
1104 | void Interface::resetTitle() |
111
51c93a0cc317
Now disconnects properly without instantly quitting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
1105 | { |
182
20ca0a6be175
removed the String class in favor of std::string
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
1106 | m_title = sprintf("%s %s (%s)", application_name(), full_version_string(), changeset_date_string()); |
111
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 | |
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
|
1109 | // ------------------------------------------------------------------------------------------------- |
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
|
1110 | // |
139
da7d5a8e608f
Restyled the names of the private methods of Interface
Teemu Piippo <teemu@compsta2.com>
parents:
138
diff
changeset
|
1111 | void Interface::flushInput() |
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
|
1112 | { |
179
7fc34735178e
start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents:
156
diff
changeset
|
1113 | m_inputHistory.insert(m_inputHistory.begin(), ""); |
127
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
1114 | m_inputCursor = 0; |
6610b8b29848
Restyled the names of Interface's private members
Teemu Piippo <crimsondusk64@gmail.com>
parents:
126
diff
changeset
|
1115 | m_needInputRender = true; |
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
|
1116 | } |
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
|
1117 | |
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
|
1118 | END_ZFC_NAMESPACE |