From 445b267e22e8a6d4c75b7667835ac3b386a41150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=8B=D1=87=D0=BA=D0=BE=D0=B2=20=D0=90=D0=BD=D0=B4?= =?UTF-8?q?=D1=80=D0=B5=D0=B9?= Date: Mon, 17 Apr 2017 13:24:16 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/pip@388 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- src/console/piconsole.cpp | 10 +++++ src/console/piconsole.h | 32 +++++++------- src/console/piscreen.cpp | 87 ++++++++++++++++++++++++++++++++------- src/console/piscreen.h | 20 +++------ 4 files changed, 105 insertions(+), 44 deletions(-) diff --git a/src/console/piconsole.cpp b/src/console/piconsole.cpp index 5b61c7aa..df895280 100644 --- a/src/console/piconsole.cpp +++ b/src/console/piconsole.cpp @@ -270,6 +270,16 @@ void PIConsole::key_event(PIKbdListener::KeyEvent key, void * t) { } +int PIConsole::couts(const PIString & v) { + return printf("%s", v.data()); +} + + +int PIConsole::couts(const char * v) { + return printf("%s", v); +} + + void PIConsole::clearVariables(bool clearScreen) { if (isRunning()) lock(); if (clearScreen && isRunning()) { diff --git a/src/console/piconsole.h b/src/console/piconsole.h index 9b1e3185..75aa7a2a 100644 --- a/src/console/piconsole.h +++ b/src/console/piconsole.h @@ -391,22 +391,22 @@ public: PIVector & columns() {return tabs[cur_tab].columns;} Column & column(int index) {return tabs[cur_tab].columns[index - 1];} - inline int couts(const PIString & v) {return printf("%s", v.data());} - inline int couts(const char * v) {return printf("%s", v);} - inline int couts(const bool v); - inline int couts(const char v); - inline int couts(const short v); - inline int couts(const int v); - inline int couts(const long v); - inline int couts(const llong v); - inline int couts(const uchar v); - inline int couts(const ushort v); - inline int couts(const uint v); - inline int couts(const ulong v); - inline int couts(const ullong v); - inline int couts(const float v); - inline int couts(const double v); - inline int couts(const PISystemTime & v); + int couts(const PIString & v); + int couts(const char * v); + int couts(const bool v); + int couts(const char v); + int couts(const short v); + int couts(const int v); + int couts(const long v); + int couts(const llong v); + int couts(const uchar v); + int couts(const ushort v); + int couts(const uint v); + int couts(const ulong v); + int couts(const ullong v); + int couts(const float v); + int couts(const double v); + int couts(const PISystemTime & v); struct RemoteClient; diff --git a/src/console/piscreen.cpp b/src/console/piscreen.cpp index 826df451..16b26b15 100644 --- a/src/console/piscreen.cpp +++ b/src/console/piscreen.cpp @@ -278,22 +278,24 @@ ushort PIScreen::SystemConsole::attributes(const PIScreenTypes::Cell & c) { } #undef FOREGROUND_MASK #undef BACKGROUND_MASK -void PIScreen::SystemConsole::getWinCurCoord() {GetConsoleScreenBufferInfo(PRIVATE->hOut, &PRIVATE->csbi); PRIVATE->ccoord = PRIVATE->csbi.dwCursorPosition;} -void PIScreen::SystemConsole::toUpperLeft() {SetConsoleCursorPosition(PRIVATE->hOut, PRIVATE->ulcoord);} -void PIScreen::SystemConsole::moveTo(int x, int y) {PRIVATE->ccoord.X = x; PRIVATE->ccoord.Y = PRIVATE->ulcoord.Y + y; SetConsoleCursorPosition(PRIVATE->hOut, PRIVATE->ccoord);} -void PIScreen::SystemConsole::clearScreen() {toUpperLeft(); FillConsoleOutputAttribute(PRIVATE->hOut, PRIVATE->dattr, width * (height + 1), PRIVATE->ulcoord, &PRIVATE->written); - FillConsoleOutputCharacter(PRIVATE->hOut, ' ', width * (height + 1), PRIVATE->ulcoord, &PRIVATE->written);} -void PIScreen::SystemConsole::clearScreenLower() {getWinCurCoord(); FillConsoleOutputAttribute(PRIVATE->hOut, PRIVATE->dattr, width * height - width * PRIVATE->ccoord.Y + PRIVATE->ccoord.X, PRIVATE->ccoord, &PRIVATE->written); - FillConsoleOutputCharacter(PRIVATE->hOut, ' ', width * height - width * PRIVATE->ccoord.Y + PRIVATE->ccoord.X, PRIVATE->ccoord, &PRIVATE->written);} -void PIScreen::SystemConsole::clearLine() {getWinCurCoord(); FillConsoleOutputAttribute(PRIVATE->hOut, PRIVATE->dattr, width - PRIVATE->ccoord.X, PRIVATE->ccoord, &PRIVATE->written); - FillConsoleOutputCharacter(PRIVATE->hOut, ' ', width - PRIVATE->ccoord.X, PRIVATE->ccoord, &PRIVATE->written);} -void PIScreen::SystemConsole::newLine() {getWinCurCoord(); PRIVATE->ccoord.X = 0; PRIVATE->ccoord.Y++; SetConsoleCursorPosition(PRIVATE->hOut, PRIVATE->ccoord);} -void PIScreen::SystemConsole::hideCursor() {PRIVATE->curinfo.bVisible = false; SetConsoleCursorInfo(PRIVATE->hOut, &PRIVATE->curinfo);} -void PIScreen::SystemConsole::showCursor() {PRIVATE->curinfo.bVisible = true; SetConsoleCursorInfo(PRIVATE->hOut, &PRIVATE->curinfo);} -#endif +void PIScreen::SystemConsole::getWinCurCoord() { + GetConsoleScreenBufferInfo(PRIVATE->hOut, &PRIVATE->csbi); + PRIVATE->ccoord = PRIVATE->csbi.dwCursorPosition; +} -#ifndef WINDOWS +void PIScreen::SystemConsole::clearLine() { + getWinCurCoord(); + FillConsoleOutputAttribute(PRIVATE->hOut, PRIVATE->dattr, width - PRIVATE->ccoord.X, PRIVATE->ccoord, &PRIVATE->written); + FillConsoleOutputCharacter(PRIVATE->hOut, ' ', width - PRIVATE->ccoord.X, PRIVATE->ccoord, &PRIVATE->written); +} + +void PIScreen::SystemConsole::newLine() { + getWinCurCoord(); + PRIVATE->ccoord.X = 0; PRIVATE->ccoord.Y++; + SetConsoleCursorPosition(PRIVATE->hOut, PRIVATE->ccoord); +} +#else // WINDOWS PIString PIScreen::SystemConsole::formatString(const PIScreenTypes::Cell & c) { PIString ts("\e[0"); switch (c.format.color_char) { @@ -322,7 +324,64 @@ PIString PIScreen::SystemConsole::formatString(const PIScreenTypes::Cell & c) { if ((c.format.flags & Inverse) == Inverse) ts += ";7"; return ts + "m"; } +#endif // WINDOWS + + +void PIScreen::SystemConsole::toUpperLeft() { +#ifdef WINDOWS + SetConsoleCursorPosition(PRIVATE->hOut, PRIVATE->ulcoord); +#else + printf("\e[H"); #endif +} + +void PIScreen::SystemConsole::moveTo(int x, int y) { +#ifdef WINDOWS + PRIVATE->ccoord.X = x; + PRIVATE->ccoord.Y = PRIVATE->ulcoord.Y + y; + SetConsoleCursorPosition(PRIVATE->hOut, PRIVATE->ccoord); +#else + printf("\e[%d;%dH", y + 1, x + 1); +#endif +} + +void PIScreen::SystemConsole::clearScreen() { +#ifdef WINDOWS + toUpperLeft(); + FillConsoleOutputAttribute(PRIVATE->hOut, PRIVATE->dattr, width * (height + 1), PRIVATE->ulcoord, &PRIVATE->written); + FillConsoleOutputCharacter(PRIVATE->hOut, ' ', width * (height + 1), PRIVATE->ulcoord, &PRIVATE->written); +#else + printf("\e[0m\e[H\e[J"); +#endif +} + +void PIScreen::SystemConsole::clearScreenLower() { +#ifdef WINDOWS + getWinCurCoord(); + FillConsoleOutputAttribute(PRIVATE->hOut, PRIVATE->dattr, width * height - width * PRIVATE->ccoord.Y + PRIVATE->ccoord.X, PRIVATE->ccoord, &PRIVATE->written); + FillConsoleOutputCharacter(PRIVATE->hOut, ' ', width * height - width * PRIVATE->ccoord.Y + PRIVATE->ccoord.X, PRIVATE->ccoord, &PRIVATE->written); +#else + printf("\e[0m\e[J"); +#endif +} + +void PIScreen::SystemConsole::hideCursor() { +#ifdef WINDOWS + PRIVATE->curinfo.bVisible = false; + SetConsoleCursorInfo(PRIVATE->hOut, &PRIVATE->curinfo); +#else + printf("\e[?25l"); +#endif +} + +void PIScreen::SystemConsole::showCursor() { +#ifdef WINDOWS + PRIVATE->curinfo.bVisible = true; + SetConsoleCursorInfo(PRIVATE->hOut, &PRIVATE->curinfo); +#else + printf("\e[?25h"); +#endif +} diff --git a/src/console/piscreen.h b/src/console/piscreen.h index 01f00864..6fc8baf1 100644 --- a/src/console/piscreen.h +++ b/src/console/piscreen.h @@ -106,26 +106,18 @@ private: void clear(); void print(); void resize(int w, int h); -#ifdef WINDOWS - void getWinCurCoord(); void toUpperLeft(); - void moveRight(int n = 1); - void moveLeft(int n = 1); void moveTo(int x = 0, int y = 0); - void clearScreen(); - void clearScreenLower(); - void clearLine(); - void newLine(); void hideCursor(); void showCursor(); + void clearScreen(); + void clearScreenLower(); +#ifdef WINDOWS + void getWinCurCoord(); + void clearLine(); + void newLine(); ushort attributes(const PIScreenTypes::Cell & c); #else - void toUpperLeft() {printf("\e[H");} - void moveTo(int x = 0, int y = 0) {printf("\e[%d;%dH", y + 1, x + 1);} - void hideCursor() {printf("\e[?25l");} - void showCursor() {printf("\e[?25h");} - void clearScreen() {printf("\e[0m\e[H\e[J");} - void clearScreenLower() {printf("\e[0m\e[J");} PIString formatString(const PIScreenTypes::Cell & c); #endif PRIVATE_DECLARATION