05.11.2011 - stable version, 0.1.0, self-test program, work at GCC 2.95 - 4.5, VC 2010, MinGW, Linux, Windows, QNX
This commit is contained in:
81
piconsole.h
81
piconsole.h
@@ -2,10 +2,11 @@
|
||||
#define PICONSOLE_H
|
||||
|
||||
#include "pikbdlistener.h"
|
||||
#include "pistring.h"
|
||||
#include "piprotocol.h"
|
||||
#include "pisystemmonitor.h"
|
||||
#ifndef WINDOWS
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
# include <sys/ioctl.h>
|
||||
# include <fcntl.h>
|
||||
#endif
|
||||
|
||||
class PIConsole: public PIThread
|
||||
@@ -57,6 +58,8 @@ public:
|
||||
void addVariable(const PIString & name, ullong * ptr, int column = 1, PIFlags<PIConsole::Format> format = PIConsole::Normal);
|
||||
void addVariable(const PIString & name, float * ptr, int column = 1, PIFlags<PIConsole::Format> format = PIConsole::Normal);
|
||||
void addVariable(const PIString & name, double * ptr, int column = 1, PIFlags<PIConsole::Format> format = PIConsole::Normal);
|
||||
void addVariable(const PIString & name, PIProtocol * ptr, int column = 1, PIFlags<PIConsole::Format> format = PIConsole::Normal);
|
||||
void addVariable(const PIString & name, PISystemMonitor * ptr, int column = 1, PIFlags<PIConsole::Format> format = PIConsole::Normal);
|
||||
void addBitVariable(const PIString & name, void * ptr, int fromBit, int bitCount, int column = 1, PIFlags<PIConsole::Format> format = PIConsole::Normal);
|
||||
void addEmptyLine(int column = 1, uint count = 1);
|
||||
|
||||
@@ -85,17 +88,20 @@ public:
|
||||
void addCustomStatus(const PIString & str) {tabs[cur_tab].status = str;}
|
||||
void clearCustomStatus() {tabs[cur_tab].status.clear();}
|
||||
|
||||
void clearVariables(bool clearScreen = true) {if (clearScreen && isRunning()) {toUpperLeft(); clearScreenLower();} vars().clear();}
|
||||
EVENT_HANDLER0(PIConsole, void, clearVariables) {clearVariables(true);}
|
||||
EVENT_HANDLER1(PIConsole, void, clearVariables, bool, clearScreen) {if (clearScreen && isRunning()) {toUpperLeft(); clearScreenLower();} vars().clear();}
|
||||
|
||||
inline void waitForFinish() {WAIT_FOR_EXIT}
|
||||
inline void start(bool wait = false) {PIThread::start(40); if (wait) waitForFinish();}
|
||||
void stop(bool clear = false);
|
||||
EVENT_HANDLER0(PIConsole, void, waitForFinish) {WAIT_FOR_EXIT}
|
||||
EVENT_HANDLER0(PIConsole, void, start) {start(false);}
|
||||
EVENT_HANDLER1(PIConsole, void, start, bool, wait) {PIThread::start(40); if (wait) waitForFinish();}
|
||||
EVENT_HANDLER0(PIConsole, void, stop) {stop(false);}
|
||||
EVENT_HANDLER1(PIConsole, void, stop, bool, clear);
|
||||
PIString fstr(PIFlags<PIConsole::Format> f);
|
||||
|
||||
inline void enableExitCapture(char key = 'Q') {listener->enableExitCapture(key);}
|
||||
inline void disableExitCapture() {listener->disableExitCapture();}
|
||||
inline bool exitCaptured() const {return listener->exitCaptured();}
|
||||
inline char exitKey() const {return listener->exitKey();}
|
||||
void enableExitCapture(char key = 'Q') {listener->enableExitCapture(key);}
|
||||
void disableExitCapture() {listener->disableExitCapture();}
|
||||
bool exitCaptured() const {return listener->exitCaptured();}
|
||||
char exitKey() const {return listener->exitKey();}
|
||||
|
||||
private:
|
||||
void begin();
|
||||
@@ -103,32 +109,32 @@ private:
|
||||
void fillLabels();
|
||||
|
||||
#ifdef WINDOWS
|
||||
inline void getWinCurCoord() {GetConsoleScreenBufferInfo(hOut, &csbi); ccoord = csbi.dwCursorPosition;}
|
||||
inline COORD & getWinCoord(int dx = 0, int dy = 0) {getWinCurCoord(); ccoord.X += dx; ccoord.Y += dy; return ccoord;}
|
||||
inline void toUpperLeft() {SetConsoleCursorPosition(hOut, ulcoord);}
|
||||
inline void moveRight(int n = 1) {SetConsoleCursorPosition(hOut, getWinCoord(n));}
|
||||
inline void moveLeft(int n = 1) {SetConsoleCursorPosition(hOut, getWinCoord(-n));}
|
||||
inline void moveTo(int x = 0, int y = 0) {ccoord.X = x; ccoord.Y = y; SetConsoleCursorPosition(hOut, ccoord);}
|
||||
inline void clearScreen() {FillConsoleOutputAttribute(hOut, dattr, width * (height + 1), ulcoord, &written);
|
||||
FillConsoleOutputCharacter(hOut, ' ', width * (height + 1), ulcoord, &written);}
|
||||
inline void clearScreenLower() {getWinCurCoord(); FillConsoleOutputAttribute(hOut, dattr, width * height - width * ccoord.Y + ccoord.X, ccoord, &written);
|
||||
FillConsoleOutputCharacter(hOut, ' ', width * height - width * ccoord.Y + ccoord.X, ccoord, &written);}
|
||||
inline void clearLine() {getWinCurCoord(); FillConsoleOutputAttribute(hOut, dattr, width - ccoord.X, ccoord, &written);
|
||||
FillConsoleOutputCharacter(hOut, ' ', width - ccoord.X, ccoord, &written);}
|
||||
inline void newLine() {getWinCurCoord(); ccoord.X = 0; ccoord.Y++; SetConsoleCursorPosition(hOut, ccoord);}
|
||||
inline void hideCursor() {curinfo.bVisible = false; SetConsoleCursorInfo(hOut, &curinfo);}
|
||||
inline void showCursor() {curinfo.bVisible = true; SetConsoleCursorInfo(hOut, &curinfo);}
|
||||
void getWinCurCoord() {GetConsoleScreenBufferInfo(hOut, &csbi); ccoord = csbi.dwCursorPosition;}
|
||||
COORD & getWinCoord(int dx = 0, int dy = 0) {getWinCurCoord(); ccoord.X += dx; ccoord.Y += dy; return ccoord;}
|
||||
void toUpperLeft() {SetConsoleCursorPosition(hOut, ulcoord);}
|
||||
void moveRight(int n = 1) {SetConsoleCursorPosition(hOut, getWinCoord(n));}
|
||||
void moveLeft(int n = 1) {SetConsoleCursorPosition(hOut, getWinCoord(-n));}
|
||||
void moveTo(int x = 0, int y = 0) {ccoord.X = x; ccoord.Y = y; SetConsoleCursorPosition(hOut, ccoord);}
|
||||
void clearScreen() {FillConsoleOutputAttribute(hOut, dattr, width * (height + 1), ulcoord, &written);
|
||||
FillConsoleOutputCharacter(hOut, ' ', width * (height + 1), ulcoord, &written);}
|
||||
void clearScreenLower() {getWinCurCoord(); FillConsoleOutputAttribute(hOut, dattr, width * height - width * ccoord.Y + ccoord.X, ccoord, &written);
|
||||
FillConsoleOutputCharacter(hOut, ' ', width * height - width * ccoord.Y + ccoord.X, ccoord, &written);}
|
||||
void clearLine() {getWinCurCoord(); FillConsoleOutputAttribute(hOut, dattr, width - ccoord.X, ccoord, &written);
|
||||
FillConsoleOutputCharacter(hOut, ' ', width - ccoord.X, ccoord, &written);}
|
||||
void newLine() {getWinCurCoord(); ccoord.X = 0; ccoord.Y++; SetConsoleCursorPosition(hOut, ccoord);}
|
||||
void hideCursor() {curinfo.bVisible = false; SetConsoleCursorInfo(hOut, &curinfo);}
|
||||
void showCursor() {curinfo.bVisible = true; SetConsoleCursorInfo(hOut, &curinfo);}
|
||||
#else
|
||||
inline void toUpperLeft() {printf("\e[H");}
|
||||
inline void moveRight(int n = 1) {if (n > 0) printf("\e[%dC", n);}
|
||||
inline void moveLeft(int n = 1) {if (n > 0) printf("\e[%dD", n);}
|
||||
inline void moveTo(int x = 0, int y = 0) {printf("\e[%d;%dH", y, x);}
|
||||
inline void clearScreen() {printf("\e[H\e[J");}
|
||||
inline void clearScreenLower() {printf("\e[J");}
|
||||
inline void clearLine() {printf("\e[K");}
|
||||
inline void newLine() {printf("\eE");}
|
||||
inline void hideCursor() {printf("\e[?25l");}
|
||||
inline void showCursor() {printf("\e[?25h");}
|
||||
void toUpperLeft() {printf("\e[H");}
|
||||
void moveRight(int n = 1) {if (n > 0) printf("\e[%dC", n);}
|
||||
void moveLeft(int n = 1) {if (n > 0) printf("\e[%dD", n);}
|
||||
void moveTo(int x = 0, int y = 0) {printf("\e[%d;%dH", y, x);}
|
||||
void clearScreen() {printf("\e[H\e[J");}
|
||||
void clearScreenLower() {printf("\e[J");}
|
||||
void clearLine() {printf("\e[K");}
|
||||
void newLine() {printf("\eE");}
|
||||
void hideCursor() {printf("\e[?25l");}
|
||||
void showCursor() {printf("\e[?25h");}
|
||||
#endif
|
||||
void status();
|
||||
void checkColumn(uint col) {if (vars().size() < col) {vars().resize(col);}}
|
||||
@@ -188,9 +194,10 @@ private:
|
||||
char key;
|
||||
Tab() {;}
|
||||
Tab(PIString n, char k) {name = n; key = k;}
|
||||
~Tab() {;}
|
||||
};
|
||||
|
||||
inline PIVector<PIVector<Variable> > & vars() {return tabs[cur_tab].variables;}
|
||||
PIVector<PIVector<Variable> > & vars() {return tabs[cur_tab].variables;}
|
||||
inline int couts(const string v);
|
||||
inline int couts(const char * v);
|
||||
inline int couts(const bool v);
|
||||
|
||||
Reference in New Issue
Block a user