--- a/sources/interface.cpp Sun Dec 14 18:15:28 2014 +0200 +++ b/sources/interface.cpp Sun Dec 14 19:38:47 2014 +0200 @@ -30,6 +30,7 @@ #include <string.h> #include "interface.h" +#include "network/rconsession.h" enum { PAGE_SIZE = 10 }; @@ -39,6 +40,7 @@ static bool g_needRefresh = false; static bool g_needStatusBarRender = false; static bool g_needInputRender = false; +static bool g_needOutputRender = false; static String g_statusBarText; static struct { char ch; int x; } g_cursorChar; static Vector<String> g_output = {""}; @@ -67,7 +69,7 @@ // ------------------------------------------------------------------------------------------------- // static FUNCTION -interface_render_log_area() -> void +interface_render_output() -> void { int height = LINES - 3; @@ -87,6 +89,8 @@ mvhline (y, 0, ' ', COLS); mvprintw (y++, 0, "%s", g_output[i].chars()); } + + g_needRefresh = true; } // ------------------------------------------------------------------------------------------------- @@ -98,6 +102,9 @@ int displaylength = COLS - strlen (prompt) - 1; int y = LINES - 2; + // Ensure the cursor is within bounds + g_cursor = clamp (g_cursor, 0, g_input.length()); + // Ensure that the cursor is always in view, adjust panning if this is not the case if (g_cursor > g_pan + displaylength) g_pan = g_cursor - displaylength; // cursor went too far right @@ -159,7 +166,7 @@ interface_render_full() -> void { interface_render_titlebar(); - interface_render_log_area(); + interface_render_output(); interface_render_statusbar(); interface_render_input(); } @@ -265,19 +272,33 @@ case KEY_PPAGE: g_outputScroll += PAGE_SIZE; - interface_render_log_area(); - g_needRefresh = true; + g_needOutputRender = true; break; case KEY_NPAGE: g_outputScroll -= PAGE_SIZE; - interface_render_log_area(); - g_needRefresh = true; + g_needOutputRender = true; + break; + + case '\n': + case KEY_ENTER: + if (RCONSession::get_session()->send_command (g_input)) + { + g_input.clear(); + g_needInputRender = true; + } break; } +} +// ------------------------------------------------------------------------------------------------- +// +FUNCTION +Interface::render() -> void +{ if (g_needStatusBarRender) interface_render_statusbar(); if (g_needInputRender) interface_render_input(); + if (g_needOutputRender) interface_render_output(); if (g_needRefresh) { @@ -287,6 +308,8 @@ } } +// ------------------------------------------------------------------------------------------------- +// FUNCTION print_to_console (const String& a) -> void { for (char ch : a) @@ -300,7 +323,5 @@ g_output[g_output.size() - 1] += ch; } - interface_render_log_area(); - interface_position_cursor(); - refresh(); + g_needOutputRender = true; }