diff -r 77d02446edf0 -r f7221183a994 sources/interface.cpp --- a/sources/interface.cpp Sun Dec 14 20:24:16 2014 +0200 +++ b/sources/interface.cpp Sun Dec 14 20:47:44 2014 +0200 @@ -45,6 +45,7 @@ static struct { char ch; int x; } g_cursorChar; static Vector g_output = {""}; static int g_outputScroll = 0; +static String g_title; // ------------------------------------------------------------------------------------------------- // @@ -66,6 +67,7 @@ ::noecho(); ::refresh(); ::timeout (0); + g_title = format (APPNAME " %1 (%2)", full_version_string(), changeset_date_string()); for (int i = 0; i < NUM_COLORS; ++i) for (int j = 0; j < NUM_COLORS; ++j) @@ -91,29 +93,32 @@ // ------------------------------------------------------------------------------------------------- // static FUNCTION -interface_clear_titlebar() -> void +interface_render_titlebar() -> void { - int pair = interface_color_pair (WHITE, BLUE); - attron (pair); - mvhline (0, 0, ' ', COLS); - attroff (pair); + if (g_title.length() <= COLS) + { + int pair = interface_color_pair (WHITE, BLUE); + int startx = (COLS - g_title.length()) / 2; + int endx = startx + g_title.length(); + print ("startx: %1, endx: %2\n", startx, endx); + + attron (pair); + mvprintw (0, startx, "%s", g_title.chars()); + mvhline (0, 0, ' ', startx); + mvhline (0, endx, ' ', COLS - endx); + attroff (pair); + } + + g_needRefresh = true; } // ------------------------------------------------------------------------------------------------- // -static FUNCTION -interface_render_titlebar() -> void +FUNCTION +Interface::set_title (const String& title) -> void { - String versionText = format (APPNAME " %1 (%2)", - full_version_string(), changeset_date_string()); - - if (versionText.length() <= COLS) - { - int pair = interface_color_pair (WHITE, BLUE); - attron (pair); - mvprintw (0, (COLS - versionText.length()) / 2, "%s", versionText.chars()); - attroff (pair); - } + g_title = title; + interface_render_titlebar(); } // ------------------------------------------------------------------------------------------------- @@ -148,8 +153,8 @@ static FUNCTION interface_render_input() -> void { - static char prompt[] = "> "; - int displaylength = COLS - strlen (prompt) - 1; + static char prompt[] = ">"; + int displaylength = COLS - strlen (prompt) - 2; int y = LINES - 2; // Ensure the cursor is within bounds @@ -164,12 +169,10 @@ int start = g_pan; int end = min (g_input.length(), start + displaylength); assert (g_cursor >= start and g_cursor <= end); - String displayTextBegin = g_input.mid (start, g_cursor); - String displayTextEnd = g_input.mid (g_cursor, end); // Clear, but only as much as is necessary. I want to avoid clearing the entire line to save // bandwidth over SSH connections. Perhaps needlessly? I'm paranoid. - int renderLength = strlen (prompt) + displayTextBegin.length() + displayTextEnd.length(); + int renderLength = strlen (prompt) + 1 + g_input.length(); static int lastRenderLength = 0; if (lastRenderLength > renderLength) @@ -180,11 +183,14 @@ // Render the input line, with the part of the input string that's before the cursor written // AFTER the part that comes afterwards. This is to ensure that the cursor is placed at the // position where our cursor is. It looks nice like that. :) + + int pair = interface_color_pair (WHITE, BLUE); + attron (pair); mvprintw (y, 0, "%s", prompt); - mvprintw (y, strlen (prompt) + displayTextBegin.length(), "%s", displayTextEnd.chars()); - mvprintw (y, strlen (prompt), "%s", displayTextBegin.chars()); + attroff (pair); + mvprintw (y, strlen (prompt) + 1, "%s", g_input.chars()); g_cursorChar.ch = g_cursor != 0 ? g_input[g_cursor - 1] : '\0'; - g_cursorChar.x = strlen (prompt) + displayTextBegin.length() - 1; + g_cursorChar.x = strlen (prompt) + (g_cursor - g_pan); g_needRefresh = true; g_needInputRender = false; } @@ -215,7 +221,6 @@ FUNCTION Interface::render_full() -> void { - interface_clear_titlebar(); interface_render_titlebar(); interface_render_output(); interface_render_statusbar();