15.10.2012 - version 0.2.0 - PIIODevice - base of file, ethernet, serial and packets extractor. PIEthernet now support also TCP (client and server). PIConsole now can align labels in each column individually.
This commit is contained in:
44
piconsole.h
Normal file → Executable file
44
piconsole.h
Normal file → Executable file
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Console output/input
|
||||
Copyright (C) 2011 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2012 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -61,6 +61,7 @@ public:
|
||||
Hex = 0x2000000,
|
||||
Oct = 0x4000000,
|
||||
Scientific = 0x8000000};
|
||||
enum Alignment {Nothing, Left, Right};
|
||||
|
||||
void addString(const PIString & name, int column = 1, PIFlags<PIConsole::Format> format = PIConsole::Normal);
|
||||
void addVariable(const PIString & name, PIString * ptr, int column = 1, PIFlags<PIConsole::Format> format = PIConsole::Normal);
|
||||
@@ -81,7 +82,7 @@ public:
|
||||
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);
|
||||
|
||||
|
||||
PIString getString(int x, int y);
|
||||
short getShort(int x, int y) {return getString(x, y).toShort();}
|
||||
int getInt(int x, int y) {return getString(x, y).toInt();}
|
||||
@@ -92,7 +93,7 @@ public:
|
||||
int getInt(const PIString & name) {return getString(name).toInt();}
|
||||
float getFloat(const PIString & name) {return getString(name).toFloat();}
|
||||
double getDouble(const PIString & name) {return getString(name).toDouble();}
|
||||
|
||||
|
||||
uint tabsCount() const {return tabs.size();}
|
||||
PIString currentTab() const {return tabs[cur_tab].name;}
|
||||
int addTab(const PIString & name, char bind_key = 0);
|
||||
@@ -103,13 +104,17 @@ public:
|
||||
bool setTabBindKey(uint index, char bind_key);
|
||||
bool setTabBindKey(const PIString & name, char bind_key);
|
||||
void clearTabs(bool clearScreen = true) {if (clearScreen && isRunning()) {toUpperLeft(); clearScreenLower();} tabs.clear();}
|
||||
|
||||
|
||||
void addCustomStatus(const PIString & str) {tabs[cur_tab].status = str;}
|
||||
void clearCustomStatus() {tabs[cur_tab].status.clear();}
|
||||
|
||||
Alignment defaultAlignment() const {return def_align;}
|
||||
void setDefaultAlignment(Alignment align) {def_align = align;}
|
||||
void setColumnAlignment(int col, Alignment align) {if (col < 0 || col >= columns().size_s()) return; column(col).alignment = align;}
|
||||
void setColumnAlignmentToAll(Alignment align) {piForeach (Tab & i, tabs) piForeach (Column & j, i.columns) j.alignment = align; fillLabels();}
|
||||
|
||||
EVENT_HANDLER0(PIConsole, void, clearVariables) {clearVariables(true);}
|
||||
EVENT_HANDLER1(PIConsole, void, clearVariables, bool, clearScreen) {if (clearScreen && isRunning()) {toUpperLeft(); clearScreenLower();} vars().clear();}
|
||||
|
||||
EVENT_HANDLER1(PIConsole, void, clearVariables, bool, clearScreen) {if (clearScreen && isRunning()) {toUpperLeft(); clearScreenLower();} columns().clear();}
|
||||
|
||||
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();}
|
||||
@@ -156,7 +161,7 @@ private:
|
||||
void showCursor() {printf("\e[?25h");}
|
||||
#endif
|
||||
void status();
|
||||
void checkColumn(uint col) {if (vars().size() < col) {vars().resize(col);}}
|
||||
void checkColumn(uint col) {while (columns().size() < col) columns().push_back(Column(def_align));}
|
||||
int bitsValue(void * src, int offset, int count);
|
||||
inline void printLine(const PIString & str, int dx = 0, PIFlags<PIConsole::Format> format = PIConsole::Normal);
|
||||
inline int printValue(const PIString & str, PIFlags<PIConsole::Format> format = PIConsole::Normal);
|
||||
@@ -203,21 +208,33 @@ private:
|
||||
void * ptr;
|
||||
};
|
||||
void operator =(const Variable & src) {name = src.name; format = src.format; type = src.type; offset = src.offset;
|
||||
bitFrom = src.bitFrom; bitCount = src.bitCount; c = src.c; nx = src.nx; ny = src.ny;}
|
||||
bitFrom = src.bitFrom; bitCount = src.bitCount; ptr = src.ptr; nx = src.nx; ny = src.ny;}
|
||||
};
|
||||
|
||||
struct Column {
|
||||
PIVector<Variable> variables;
|
||||
Alignment alignment;
|
||||
Column(Alignment align = PIConsole::Right) { alignment = align;}
|
||||
uint size() const {return variables.size();}
|
||||
Variable & operator [](int index) {return variables[index];}
|
||||
const Variable & operator [](int index) const {return variables[index];}
|
||||
void push_back(const Variable & v) {variables.push_back(v);}
|
||||
void operator =(const Column & src) {variables = src.variables; alignment = src.alignment;}
|
||||
};
|
||||
|
||||
struct Tab {
|
||||
PIVector<PIVector<Variable> > variables;
|
||||
PIVector<Column> columns;
|
||||
PIString name;
|
||||
PIString status;
|
||||
char key;
|
||||
Tab() {;}
|
||||
Tab() {}
|
||||
Tab(PIString n, char k) {name = n; key = k;}
|
||||
~Tab() {;}
|
||||
};
|
||||
|
||||
PIVector<PIVector<Variable> > & vars() {return tabs[cur_tab].variables;}
|
||||
inline int couts(const string v);
|
||||
PIVector<Column> & columns() {return tabs[cur_tab].columns;}
|
||||
Column & column(int index) {return tabs[cur_tab].columns[index - 1];}
|
||||
inline int couts(const PIString & v);
|
||||
inline int couts(const char * v);
|
||||
inline int couts(const bool v);
|
||||
inline int couts(const char v);
|
||||
@@ -246,6 +263,7 @@ private:
|
||||
PIVector<Tab> tabs;
|
||||
Variable tv;
|
||||
PIKbdListener * listener;
|
||||
Alignment def_align;
|
||||
KBFunc ret_func;
|
||||
int width, height, pwidth, pheight, ret, col_wid, num_format;
|
||||
uint my;
|
||||
|
||||
Reference in New Issue
Block a user