# HG changeset patch # User Teemu Piippo # Date 1469015960 -10800 # Node ID da7d5a8e608f0b4d10202b33c9b77d634245e6d6 # Parent c909c38ca8866c97e314b1aeafaf653df32473d2 Restyled the names of the private methods of Interface diff -r c909c38ca886 -r da7d5a8e608f sources/interface.cpp --- a/sources/interface.cpp Wed Jul 20 14:53:12 2016 +0300 +++ b/sources/interface.cpp Wed Jul 20 14:59:20 2016 +0300 @@ -41,7 +41,7 @@ // ------------------------------------------------------------------------------------------------- // -chtype Interface::color_pair (Color fg, Color bg) +chtype Interface::getColorPair (Color fg, Color bg) { if (fg == DEFAULT && bg == DEFAULT) return 0; @@ -51,7 +51,7 @@ // ------------------------------------------------------------------------------------------------- // -const String& Interface::current_input() +const String& Interface::getCurrentInput() { return m_inputHistory[m_inputCursor]; } @@ -60,11 +60,11 @@ // // Makes current_input() the lastmost input (so that we won't modify history) // -void Interface::detach_input() +void Interface::detachInput() { if (m_inputCursor > 0) { - m_inputHistory[0] = current_input(); + m_inputHistory[0] = getCurrentInput(); m_inputCursor = 0; } } @@ -72,15 +72,15 @@ // ------------------------------------------------------------------------------------------------- // A version of current_input() that allows changing the contents of it. // -String& Interface::mutable_current_input() +String& Interface::getEditableInput() { - detach_input(); + detachInput(); return m_inputHistory[m_inputCursor]; } // ------------------------------------------------------------------------------------------------- // -void Interface::move_input_cursor (int delta) +void Interface::moveInputCursor (int delta) { // No input history when inputting addresses or passwords if (m_inputState != INPUTSTATE_NORMAL) @@ -94,14 +94,14 @@ if (m_inputCursor != oldcursor) { - m_cursorPosition = current_input().length(); + m_cursorPosition = getCurrentInput().length(); m_needInputRender = true; } } // ------------------------------------------------------------------------------------------------- // -String Interface::prompt_string() +String Interface::getPromptString() { String prompt; @@ -118,21 +118,21 @@ // ------------------------------------------------------------------------------------------------- // -void Interface::set_input_state (InputState newstate) +void Interface::setInputState (InputState newstate) { // Clear the input row (unless going to or from confirm state) if (newstate != INPUTSTATE_CONFIRM_DISCONNECTION and m_inputState != INPUTSTATE_CONFIRM_DISCONNECTION) { m_inputCursor = 0; - mutable_current_input().clear(); + getEditableInput().clear(); } switch (newstate) { case INPUTSTATE_ADDRESS: if (m_remoteAddress.host != 0) - mutable_current_input() = m_remoteAddress.to_string (IPAddress::WITH_PORT); + getEditableInput() = m_remoteAddress.to_string (IPAddress::WITH_PORT); break; default: @@ -169,7 +169,7 @@ m_outputLines.clear(); m_outputLines << ColoredLine(); m_session.set_interface (this); - reset_title(); + resetTitle(); if (::has_colors()) { @@ -201,11 +201,11 @@ // ------------------------------------------------------------------------------------------------- // -void Interface::render_titlebar() +void Interface::renderTitlebar() { if (m_title.length() <= COLS) { - chtype pair = color_pair (WHITE, BLUE); + chtype pair = getColorPair (WHITE, BLUE); int startx = (COLS - m_title.length()) / 2; int endx = startx + m_title.length(); attron (pair); @@ -223,17 +223,17 @@ void Interface::setTitle (const String& title) { m_title = title; - render_titlebar(); + renderTitlebar(); } // ------------------------------------------------------------------------------------------------- // -void Interface::safe_disconnect (std::function afterwards) +void Interface::safeDisconnect (std::function afterwards) { if (m_session.is_active()) { m_disconnectCallback = afterwards; - set_input_state (INPUTSTATE_CONFIRM_DISCONNECTION); + setInputState (INPUTSTATE_CONFIRM_DISCONNECTION); } else afterwards(false); @@ -241,7 +241,7 @@ // ------------------------------------------------------------------------------------------------- // -int Interface::nicklist_width() +int Interface::nicklistWidth() { // Allocate at least 12 characters, at most 24 characters, for the nicklist. If we cannot // afford that (o_O) then we probably shouldn't draw the nicklist at all I think. @@ -257,7 +257,7 @@ // Renders the given colored line onto the screen. Will wrap if allowWrap is true. Returns the // 'y' value for the next line. // -int Interface::render_colorline (int y, int x0, int width, const ColoredLine& line, bool allowWrap) +int Interface::renderColorline (int y, int x0, int width, const ColoredLine& line, bool allowWrap) { int x = x0; @@ -280,7 +280,7 @@ else if (byte >= RLINE_ON_COLOR and byte < (RLINE_ON_COLOR + 16)) { auto attrfunction = (byte < RLINE_OFF_COLOR ? &attron : &attroff); - (*attrfunction) (color_pair (Color ((byte - RLINE_ON_COLOR) & 7), DEFAULT)); + (*attrfunction) (getColorPair (Color ((byte - RLINE_ON_COLOR) & 7), DEFAULT)); } else switch (byte) { @@ -299,7 +299,7 @@ // ------------------------------------------------------------------------------------------------- // -void Interface::render_output() +void Interface::renderOutput() { if (m_outputLines.size() == 1) return; @@ -307,7 +307,7 @@ m_outputScroll = clamp (m_outputScroll, 0, m_outputLines.size() - 1); int height = LINES - 3; - int width = COLS - nicklist_width(); + int width = COLS - nicklistWidth(); int printOffset = 0; int end = m_outputLines.size() - 1 - m_outputScroll; int start = end; @@ -367,7 +367,7 @@ y += printOffset; for (int i : range(start, end)) - y = render_colorline (y, 0, width, m_outputLines[i], true); + y = renderColorline (y, 0, width, m_outputLines[i], true); m_needOutputRender = false; m_needRefresh = true; @@ -375,9 +375,9 @@ // ------------------------------------------------------------------------------------------------- // -void Interface::render_nicklist() +void Interface::renderNicklist() { - int width = nicklist_width(); + int width = nicklistWidth(); int height = LINES- 3; int y = 1; int x = COLS - width; @@ -390,7 +390,7 @@ mvhline (y, x, ' ', width); if (i < m_playerNames.size()) - render_colorline (y, x, width, m_playerNames[i], false); + renderColorline (y, x, width, m_playerNames[i], false); y++; } @@ -401,9 +401,9 @@ // ------------------------------------------------------------------------------------------------- // -void Interface::render_input() +void Interface::renderInput() { - chtype promptColor = color_pair (WHITE, BLUE); + chtype promptColor = getColorPair (WHITE, BLUE); // If we're asking the user if they want to disconnect, we don't render any input strings, // just the confirmation message. @@ -417,9 +417,9 @@ return; } - String prompt = prompt_string(); + String prompt = getPromptString(); int displayLength = COLS - prompt.length() - 2; - String displayString = current_input(); + String displayString = getCurrentInput(); int y = LINES - 2; // If we're inputting a password, replace it with asterisks @@ -462,9 +462,9 @@ // ------------------------------------------------------------------------------------------------- // -void Interface::render_statusbar() +void Interface::renderStatusBar() { - chtype color = color_pair (WHITE, BLUE); + chtype color = getColorPair (WHITE, BLUE); int y = LINES - 1; attron (color); mvhline (y, 0, ' ', COLS); @@ -531,16 +531,16 @@ void Interface::renderFull() { updateStatusBar(); - render_titlebar(); - render_output(); - render_statusbar(); - render_input(); - render_nicklist(); + renderTitlebar(); + renderOutput(); + renderStatusBar(); + renderInput(); + renderNicklist(); } // ------------------------------------------------------------------------------------------------- // -void Interface::position_cursor() +void Interface::positionCursor() { // This is only relevant if the input string is being drawn if (m_inputState == INPUTSTATE_CONFIRM_DISCONNECTION) @@ -551,14 +551,14 @@ if (m_cursorCharacter.ch != '\0') mvprintw (y, m_cursorCharacter.x, "%c", m_cursorCharacter.ch); else - mvprintw (y, prompt_string().length(), " "); + mvprintw (y, getPromptString().length(), " "); } // ------------------------------------------------------------------------------------------------- // -int Interface::find_previous_word() +int Interface::findPreviousWord() { - const String& input = current_input(); + const String& input = getCurrentInput(); int pos = m_cursorPosition; // Move past whitespace @@ -574,9 +574,9 @@ // ------------------------------------------------------------------------------------------------- // -int Interface::find_next_word() +int Interface::findNextWord() { - const String& input = current_input(); + const String& input = getCurrentInput(); int pos = m_cursorPosition; // Move past current whitespace @@ -600,7 +600,7 @@ if (m_cursorPosition > a and m_cursorPosition <= b) m_cursorPosition = a; - String& input = mutable_current_input(); + String& input = getEditableInput(); m_pasteBuffer = input.mid (a, b); input.remove (a, b - a); m_needInputRender = true; @@ -630,14 +630,14 @@ m_disconnectCallback(true); } else if (ch == 'n' or ch == 'N') - set_input_state (INPUTSTATE_NORMAL); + setInputState (INPUTSTATE_NORMAL); return; } if (ch >= 0x20 and ch <= 0x7E) { - mutable_current_input().insert (m_cursorPosition++, char (ch)); + getEditableInput().insert (m_cursorPosition++, char (ch)); m_needInputRender = true; } else switch (ch) @@ -649,11 +649,11 @@ break; case INPUTSTATE_NORMAL: - safe_disconnect ([&](bool hadsession) + safeDisconnect ([&](bool hadsession) { if (hadsession) { - set_input_state (INPUTSTATE_NORMAL); + setInputState (INPUTSTATE_NORMAL); } else { @@ -664,11 +664,11 @@ break; case INPUTSTATE_PASSWORD: - set_input_state (INPUTSTATE_ADDRESS); + setInputState (INPUTSTATE_ADDRESS); break; case INPUTSTATE_ADDRESS: - set_input_state (INPUTSTATE_NORMAL); + setInputState (INPUTSTATE_NORMAL); } break; @@ -683,7 +683,7 @@ case KEY_RIGHT: case 'F' - 'A' + 1: // readline ^F - if (m_cursorPosition < current_input().length()) + if (m_cursorPosition < getCurrentInput().length()) { m_cursorPosition++; m_needInputRender = true; @@ -692,7 +692,7 @@ case KEY_DOWN: case KEY_UP: - move_input_cursor (ch == KEY_DOWN ? -1 : 1); + moveInputCursor (ch == KEY_DOWN ? -1 : 1); break; case KEY_HOME: @@ -706,9 +706,9 @@ case KEY_END: case 'E' - 'A' + 1: // readline ^E - if (m_cursorPosition != current_input().length()) + if (m_cursorPosition != getCurrentInput().length()) { - m_cursorPosition = current_input().length(); + m_cursorPosition = getCurrentInput().length(); m_needInputRender = true; } break; @@ -717,16 +717,16 @@ case '\b': if (m_cursorPosition > 0) { - mutable_current_input().remove_at (--m_cursorPosition); + getEditableInput().remove_at (--m_cursorPosition); m_needInputRender = true; } break; case KEY_DC: case 'D' - 'A' + 1: // readline ^D - if (m_cursorPosition < current_input().length()) + if (m_cursorPosition < getCurrentInput().length()) { - mutable_current_input().remove_at (m_cursorPosition); + getEditableInput().remove_at (m_cursorPosition); m_needInputRender = true; } break; @@ -750,17 +750,17 @@ break; case 'K' - 'A' + 1: // readline ^K - delete from cursor to end - yank (m_cursorPosition, mutable_current_input().length()); + yank (m_cursorPosition, getEditableInput().length()); break; case 'W' - 'A' + 1: // readline ^W - delete from previous word bounary to current - yank (find_previous_word(), m_cursorPosition); + yank (findPreviousWord(), m_cursorPosition); break; case 'Y' - 'A' + 1: // readline ^Y - paste previously deleted text if (not m_pasteBuffer.is_empty()) { - mutable_current_input().insert (m_cursorPosition, m_pasteBuffer); + getEditableInput().insert (m_cursorPosition, m_pasteBuffer); m_cursorPosition += m_pasteBuffer.length(); m_needInputRender = true; } @@ -768,13 +768,13 @@ case '\t': { - int space = current_input().find (" "); + int space = getCurrentInput().find (" "); if (m_inputState == INPUTSTATE_NORMAL and m_cursorPosition > 0 and (space == -1 or space >= m_cursorPosition)) { - String start = current_input().mid (0, m_cursorPosition); + String start = getCurrentInput().mid (0, m_cursorPosition); m_session.request_tab_complete (start); } } @@ -791,7 +791,7 @@ case INPUTSTATE_ADDRESS: try { - m_remoteAddress = IPAddress::from_string (current_input()); + m_remoteAddress = IPAddress::from_string (getCurrentInput()); } catch (std::exception& e) { @@ -802,28 +802,28 @@ if (m_remoteAddress.port == 0) m_remoteAddress.port = 10666; - set_input_state (INPUTSTATE_PASSWORD); + setInputState (INPUTSTATE_PASSWORD); break; case INPUTSTATE_PASSWORD: - if (m_inputState == INPUTSTATE_PASSWORD and not current_input().is_empty()) + if (m_inputState == INPUTSTATE_PASSWORD and not getCurrentInput().is_empty()) { m_session.disconnect(); - m_session.set_password (current_input()); + m_session.set_password (getCurrentInput()); m_session.connect (m_remoteAddress); - set_input_state (INPUTSTATE_NORMAL); + setInputState (INPUTSTATE_NORMAL); } break; case INPUTSTATE_NORMAL: - if (current_input()[0] == '/') + if (getCurrentInput()[0] == '/') { - handleCommand(current_input()); - flush_input(); + handleCommand(getCurrentInput()); + flushInput(); } - else if (m_session.send_command (current_input())) + else if (m_session.send_command (getCurrentInput())) { - flush_input(); + flushInput(); } break; } @@ -831,7 +831,7 @@ case 'N' - 'A' + 1: // ^N if (m_inputState == INPUTSTATE_NORMAL) - safe_disconnect ([&](bool){set_input_state (INPUTSTATE_ADDRESS);}); + safeDisconnect ([&](bool){setInputState (INPUTSTATE_ADDRESS);}); break; case '\x1b': // Escape @@ -845,26 +845,26 @@ case 'b': case 'B': // readline alt-b - move one word to the left - m_cursorPosition = find_previous_word(); + m_cursorPosition = findPreviousWord(); m_needInputRender = true; break; case 'f': case 'F': // readline alt-f - move one word to the right - m_cursorPosition = find_next_word(); + m_cursorPosition = findNextWord(); m_needInputRender = true; break; case 'd': case 'D': // readline alt-d - delete from here till next word boundary - yank (m_cursorPosition, find_next_word()); + yank (m_cursorPosition, findNextWord()); break; case KEY_BACKSPACE: // alt+backspace, remove previous word case '\b': - yank (find_previous_word(), m_cursorPosition); + yank (findPreviousWord(), m_cursorPosition); break; } } @@ -872,9 +872,9 @@ { // No alt-key, handle pure escape if (m_inputState == INPUTSTATE_PASSWORD) - set_input_state (INPUTSTATE_ADDRESS); + setInputState (INPUTSTATE_ADDRESS); else if (m_inputState == INPUTSTATE_ADDRESS) - set_input_state (INPUTSTATE_NORMAL); + setInputState (INPUTSTATE_NORMAL); } break; } @@ -886,14 +886,14 @@ // void Interface::render() { - if (m_needStatusBarRender) render_statusbar(); - if (m_needInputRender) render_input(); - if (m_needOutputRender) render_output(); - if (m_needNicklistRender) render_nicklist(); + if (m_needStatusBarRender) renderStatusBar(); + if (m_needInputRender) renderInput(); + if (m_needOutputRender) renderOutput(); + if (m_needNicklistRender) renderNicklist(); if (m_needRefresh) { - position_cursor(); + positionCursor(); refresh(); m_needRefresh = false; } @@ -905,7 +905,7 @@ { String message; message.vsprintf (fmtstr, args); - print_to_console (message); + printToConsole (message); } // ------------------------------------------------------------------------------------------------- @@ -924,7 +924,7 @@ { va_list args; va_start (args, fmtstr); - print_to_console (TEXTCOLOR_BrightBlue); + printToConsole (TEXTCOLOR_BrightBlue); vprint (fmtstr, args); va_end (args); } @@ -935,7 +935,7 @@ { va_list args; va_start (args, fmtstr); - print_to_console (TEXTCOLOR_BrightYellow "-!- "); + printToConsole (TEXTCOLOR_BrightYellow "-!- "); vprint (fmtstr, args); va_end (args); } @@ -946,14 +946,14 @@ { va_list args; va_start (args, fmtstr); - print_to_console (TEXTCOLOR_BrightRed "!!! "); + printToConsole (TEXTCOLOR_BrightRed "!!! "); vprint (fmtstr, args); va_end (args); } // ------------------------------------------------------------------------------------------------- // -void Interface::print_to_console (String message) +void Interface::printToConsole (String message) { // Zandronum sometimes sends color codes as "\\c" and sometimes as "\x1C". // Let's correct that on our end and hope this won't cause conflicts. @@ -1032,7 +1032,7 @@ // void Interface::tabComplete (const String& part, String complete) { - String& input = mutable_current_input(); + String& input = getEditableInput(); if (input.starts_with (part)) { @@ -1103,20 +1103,20 @@ void Interface::disconnected() { print("Disconnected from %s\n", m_session.address().to_string(IPAddress::WITH_PORT).chars()); - reset_title(); + resetTitle(); renderFull(); } // ------------------------------------------------------------------------------------------------- // -void Interface::reset_title() +void Interface::resetTitle() { m_title.sprintf ("%s %s (%s)", application_name(), full_version_string(), changeset_date_string()); } // ------------------------------------------------------------------------------------------------- // -void Interface::flush_input() +void Interface::flushInput() { m_inputHistory.insert (0, ""); m_inputCursor = 0; diff -r c909c38ca886 -r da7d5a8e608f sources/interface.h --- a/sources/interface.h Wed Jul 20 14:53:12 2016 +0300 +++ b/sources/interface.h Wed Jul 20 14:59:20 2016 +0300 @@ -89,28 +89,28 @@ String m_pasteBuffer; RCONSession m_session; - void render_titlebar(); - void safe_disconnect (std::function afterwards); - int render_colorline (int y, int x0, int width, const ColoredLine& line, bool allowWrap); - int nicklist_width(); - void render_output(); - void render_nicklist(); - void render_input(); - void render_statusbar(); - void position_cursor(); - chtype color_pair (Color fg, Color bg); - const String& current_input(); - void detach_input(); - String& mutable_current_input(); - void move_input_cursor (int delta); - String prompt_string(); - void set_input_state (InputState newstate); - void print_to_console (String message); - void yank (int a, int b); - int find_previous_word(); - int find_next_word(); - void reset_title(); - void flush_input(); + void detachInput(); + int findNextWord(); + int findPreviousWord(); + void flushInput(); + chtype getColorPair(Color fg, Color bg); + const String& getCurrentInput(); + String& getEditableInput(); + String getPromptString(); + void moveInputCursor(int delta); + int nicklistWidth(); + void positionCursor(); + void printToConsole(String message); + int renderColorline(int y, int x0, int width, const ColoredLine& line, bool allowWrap); + void renderInput(); + void renderNicklist(); + void renderOutput(); + void renderStatusBar(); + void renderTitlebar(); + void resetTitle(); + void safeDisconnect(std::function afterwards); + void setInputState(InputState newstate); + void yank(int a, int b); }; END_ZFC_NAMESPACE \ No newline at end of file