added user input via keys

This commit is contained in:
Hendrik Schutter 2020-08-06 22:45:05 +02:00
parent c13182b77f
commit a92a9c2a2a
4 changed files with 83 additions and 34 deletions

View File

@ -40,7 +40,6 @@ template <typename T, typename I> T* iterator_to_pointer(I i)
} }
class reHDD class reHDD
{ {
protected: protected:
@ -58,6 +57,7 @@ private:
static void filterIgnoredDrives(vector <Drive>* pvecDrives); static void filterIgnoredDrives(vector <Drive>* pvecDrives);
static void addSMARTData(vector <Drive>* pvecDrives); static void addSMARTData(vector <Drive>* pvecDrives);
static void ThreadScannDevices(); static void ThreadScannDevices();
static void ThreadUserInput();
void filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecNewDrives); void filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecNewDrives);

View File

@ -22,12 +22,16 @@ protected:
public: public:
enum UserInput { UpKey, DownKey, Abort, Shred, Delete, Enter, ESC, Undefined};
TUI(void); TUI(void);
static void initTUI(); static void initTUI();
void updateTUI(vector <Drive>* pvecDrives); void updateTUI(vector <Drive>* pvecDrives);
static enum UserInput readUserInput();
private: private:
static string sCpuUsage; static string sCpuUsage;
static string sRamUsage; static string sRamUsage;
@ -35,12 +39,12 @@ private:
WINDOW *detailview; WINDOW *detailview;
WINDOW *overview; WINDOW *overview;
vector <WINDOW *> vWinDriveEntries;
static void centerTitle(WINDOW *pwin, const char * title); static void centerTitle(WINDOW *pwin, const char * title);
static WINDOW *createOverViewWindow( int iXSize, int iYSize); static WINDOW *createOverViewWindow( int iXSize, int iYSize);
static WINDOW *createDetailViewWindow( int iXSize, int iYSize, int iXStart); static WINDOW *createDetailViewWindow( int iXSize, int iYSize, int iXStart);
static WINDOW *createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart,string sModelFamily, string sModelName, string sCapacity); static WINDOW *createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart,string sModelFamily, string sModelName, string sCapacity);
}; };
#endif // TUI_H_ #endif // TUI_H_

View File

@ -34,31 +34,25 @@ void TUI::initTUI()
} }
clear(); clear();
curs_set(0); curs_set(0);
noecho();
cbreak();
init_color(COLOR_GRAY, 173, 170, 173); init_color(COLOR_GRAY, 173, 170, 173);
init_pair(COLOR_AREA_STDSCR,COLOR_WHITE, COLOR_BLUE); init_pair(COLOR_AREA_STDSCR,COLOR_WHITE, COLOR_BLUE);
wbkgd(stdscr, COLOR_PAIR(COLOR_AREA_STDSCR)); wbkgd(stdscr, COLOR_PAIR(COLOR_AREA_STDSCR));
int stdscrX, stdscrY; mvprintw(0, 2, "reHDD - HDD refurbishing tool - GPL 3.0 ");
getmaxyx(stdscr, stdscrY, stdscrX);
mvprintw(0, 2, "reHDD - HDD refurbishing tool - Licensed under GPL 3.0 X:%d Y:%d",stdscrX,stdscrY);
} }
void TUI::updateTUI(vector <Drive>* pvecDrives) { void TUI::updateTUI(vector <Drive>* pvecDrives) {
//werase(stdscr);
int stdscrX, stdscrY; int stdscrX, stdscrY;
getmaxyx(stdscr, stdscrY, stdscrX); getmaxyx(stdscr, stdscrY, stdscrX);
init_pair(COLOR_AREA_STDSCR,COLOR_WHITE, COLOR_BLUE); init_pair(COLOR_AREA_STDSCR,COLOR_WHITE, COLOR_BLUE);
wbkgd(stdscr, COLOR_PAIR(COLOR_AREA_STDSCR)); wbkgd(stdscr, COLOR_PAIR(COLOR_AREA_STDSCR));
// mvprintw(0, 2, "reHDD - HDD refurbishing tool - Licensed under GPL 3.0 X:%d Y:%d",stdscrX,stdscrY);
refresh(); refresh();
overview=createOverViewWindow((int)(stdscrX/3), (stdscrY-15)); overview=createOverViewWindow((int)(stdscrX/3), (stdscrY-15));
@ -67,30 +61,48 @@ void TUI::updateTUI(vector <Drive>* pvecDrives) {
detailview=createDetailViewWindow(((stdscrX)-(int)(stdscrX/3)-7), (stdscrY-3), (int)(stdscrX/3)+5); detailview=createDetailViewWindow(((stdscrX)-(int)(stdscrX/3)-7), (stdscrY-3), (int)(stdscrX/3)+5);
wrefresh(detailview); wrefresh(detailview);
vWinDriveEntries.clear();
// int i = 0;
vector <Drive>::iterator it; vector <Drive>::iterator it;
for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it) for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it)
{ {
string sModelFamily = it->getModelFamily(); string sModelFamily = it->getModelFamily();
string sModelName = it->getModelName(); string sModelName = it->getModelName();
string sCapacity = it->sCapacityToText(); string sCapacity = it->sCapacityToText();
WINDOW * tmp = createEntryWindow( ((int)(stdscrX/3) - 2), 5, 3, (5* (it - pvecDrives->begin()) )+3, sModelFamily, sModelName, sCapacity); WINDOW * tmp = createEntryWindow( ((int)(stdscrX/3) - 2), 5, 3, (5* (it - pvecDrives->begin()) )+3, sModelFamily, sModelName, sCapacity);
// WINDOW * tmp = createEntryWindow( ((int)(stdscrX/3) - 2), 5, 3, (5* (i) )+3, sModelFamily, sModelName, sCapacity);
// vWinDriveEntries.push_back(tmp);
wrefresh(tmp); wrefresh(tmp);
// i++;
} }
}
enum TUI::UserInput TUI::readUserInput() {
int ch = wgetch(stdscr);
switch(ch)
{
case KEY_UP:
return TUI::UserInput::UpKey;
break;
case KEY_DOWN:
return TUI::UserInput::DownKey;
break;
case 10:
return TUI::UserInput::Enter;
break;
case 27:
return TUI::UserInput::ESC;
break;
case 'a':
return TUI::UserInput::Abort;
break;
case 'd':
return TUI::UserInput::Delete;
break;
case 's':
return TUI::UserInput::Shred;
break;
default:
return TUI::UserInput::Undefined;
break;
}
return TUI::UserInput::Undefined;
} }
@ -126,14 +138,10 @@ WINDOW* TUI::createOverViewWindow( int iXSize, int iYSize) {
centerTitle(newWindow, str.c_str()); centerTitle(newWindow, str.c_str());
//mvwaddstr(newWindow, 2, 3, "Drücke eine Taste"); keypad(newWindow, TRUE);
//refresh();
return newWindow; return newWindow;
} }
WINDOW* TUI::createDetailViewWindow( int iXSize, int iYSize, int iXStart) { WINDOW* TUI::createDetailViewWindow( int iXSize, int iYSize, int iXStart) {
WINDOW *newWindow; WINDOW *newWindow;
newWindow = newwin(iYSize, iXSize, 2, iXStart); newWindow = newwin(iYSize, iXSize, 2, iXStart);
@ -142,6 +150,7 @@ WINDOW* TUI::createDetailViewWindow( int iXSize, int iYSize, int iXStart) {
box(newWindow, ACS_VLINE, ACS_HLINE); box(newWindow, ACS_VLINE, ACS_HLINE);
centerTitle(newWindow, "Selected Drive: xyz"); centerTitle(newWindow, "Selected Drive: xyz");
keypad(newWindow, TRUE);
return newWindow; return newWindow;
} }
@ -153,12 +162,12 @@ WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart,
box(newWindow, ACS_VLINE, ACS_HLINE); box(newWindow, ACS_VLINE, ACS_HLINE);
attron(COLOR_PAIR(COLOR_AREA_ENTRY)); attron(COLOR_PAIR(COLOR_AREA_ENTRY));
mvwaddstr(newWindow,1, 1, sModelFamily.c_str()); mvwaddstr(newWindow,1, 1, sModelFamily.c_str());
mvwaddstr(newWindow,2, 1, sModelName.c_str()); mvwaddstr(newWindow,2, 1, sModelName.c_str());
mvwaddstr(newWindow,3, 1, sCapacity.c_str()); mvwaddstr(newWindow,3, 1, sCapacity.c_str());
// refresh(); keypad(newWindow, TRUE);
return newWindow; return newWindow;
} }

View File

@ -54,6 +54,7 @@ void reHDD::app_logic(void)
FD_SET(fdWhipe[0], &selectSet); FD_SET(fdWhipe[0], &selectSet);
thread thDevices(ThreadScannDevices); //start thread that scanns for drives thread thDevices(ThreadScannDevices); //start thread that scanns for drives
thread thUserInput(ThreadUserInput); //start thread that reads user input
while(1) { while(1) {
@ -76,6 +77,7 @@ void reHDD::app_logic(void)
} }
} //endless loop } //endless loop
thDevices.join(); thDevices.join();
thUserInput.join();
} }
void reHDD::ThreadScannDevices() { void reHDD::ThreadScannDevices() {
@ -92,6 +94,42 @@ void reHDD::ThreadScannDevices() {
} }
} }
void reHDD::ThreadUserInput() {
while(true) {
// cout << TUI::readUserInput() << endl;
switch (TUI::readUserInput())
{
case TUI::UserInput::DownKey:
/* code */
//cout << "Down" << endl;
break;
case TUI::UserInput::UpKey:
//cout << "Up" << endl;
break;
case TUI::UserInput::Undefined:
//cout << "Undefined" << endl;
break;
case TUI::UserInput::Abort:
//cout << "Abort" << endl;
break;
case TUI::UserInput::Delete:
//cout << "Delete" << endl;
break;
case TUI::UserInput::Shred:
//cout << "Shred" << endl;
break;
case TUI::UserInput::Enter:
//cout << "Enter" << endl;
break;
case TUI::UserInput::ESC:
//cout << "ESC" << endl;
break;
default:
break;
}
}
}
void reHDD::filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecNewDrives) { void reHDD::filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecNewDrives) {
@ -116,11 +154,9 @@ void reHDD::filterNewDrives(vector <Drive>* pvecOldDrives, vector <Drive>* pvecN
} }
pvecOldDrives->clear(); pvecOldDrives->clear();
for (long unsigned int i=0; i<pvecNewDrives->size(); i++) { for (long unsigned int i=0; i<pvecNewDrives->size(); i++) {
pvecOldDrives->push_back((*pvecNewDrives)[i]); pvecOldDrives->push_back((*pvecNewDrives)[i]);
} }
} }
/** /**