diff --git a/include/reHDD.h b/include/reHDD.h index bafaefb..d09a638 100644 --- a/include/reHDD.h +++ b/include/reHDD.h @@ -40,7 +40,6 @@ template T* iterator_to_pointer(I i) } - class reHDD { protected: @@ -58,6 +57,7 @@ private: static void filterIgnoredDrives(vector * pvecDrives); static void addSMARTData(vector * pvecDrives); static void ThreadScannDevices(); + static void ThreadUserInput(); void filterNewDrives(vector * pvecOldDrives, vector * pvecNewDrives); diff --git a/include/tui.h b/include/tui.h index 36a14dc..9216a09 100644 --- a/include/tui.h +++ b/include/tui.h @@ -22,12 +22,16 @@ protected: public: + enum UserInput { UpKey, DownKey, Abort, Shred, Delete, Enter, ESC, Undefined}; + TUI(void); static void initTUI(); void updateTUI(vector * pvecDrives); + static enum UserInput readUserInput(); + private: static string sCpuUsage; static string sRamUsage; @@ -35,12 +39,12 @@ private: WINDOW *detailview; WINDOW *overview; - vector vWinDriveEntries; static void centerTitle(WINDOW *pwin, const char * title); static WINDOW *createOverViewWindow( int iXSize, int iYSize); 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); + }; #endif // TUI_H_ \ No newline at end of file diff --git a/src/TUI/tui.cpp b/src/TUI/tui.cpp index 34d9661..dec36f0 100644 --- a/src/TUI/tui.cpp +++ b/src/TUI/tui.cpp @@ -34,31 +34,25 @@ void TUI::initTUI() } clear(); curs_set(0); + noecho(); + cbreak(); init_color(COLOR_GRAY, 173, 170, 173); - init_pair(COLOR_AREA_STDSCR,COLOR_WHITE, COLOR_BLUE); wbkgd(stdscr, COLOR_PAIR(COLOR_AREA_STDSCR)); - int stdscrX, stdscrY; - getmaxyx(stdscr, stdscrY, stdscrX); - mvprintw(0, 2, "reHDD - HDD refurbishing tool - Licensed under GPL 3.0 X:%d Y:%d",stdscrX,stdscrY); + mvprintw(0, 2, "reHDD - HDD refurbishing tool - GPL 3.0 "); } void TUI::updateTUI(vector * pvecDrives) { - - //werase(stdscr); - int stdscrX, stdscrY; getmaxyx(stdscr, stdscrY, stdscrX); init_pair(COLOR_AREA_STDSCR,COLOR_WHITE, COLOR_BLUE); 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(); overview=createOverViewWindow((int)(stdscrX/3), (stdscrY-15)); @@ -67,30 +61,48 @@ void TUI::updateTUI(vector * pvecDrives) { detailview=createDetailViewWindow(((stdscrX)-(int)(stdscrX/3)-7), (stdscrY-3), (int)(stdscrX/3)+5); wrefresh(detailview); - vWinDriveEntries.clear(); - - - // int i = 0; - vector ::iterator it; for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it) { - string sModelFamily = it->getModelFamily(); string sModelName = it->getModelName(); 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* (i) )+3, sModelFamily, sModelName, sCapacity); - - // vWinDriveEntries.push_back(tmp); + WINDOW * tmp = createEntryWindow( ((int)(stdscrX/3) - 2), 5, 3, (5* (it - pvecDrives->begin()) )+3, sModelFamily, sModelName, sCapacity); 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()); - //mvwaddstr(newWindow, 2, 3, "Drücke eine Taste"); - - //refresh(); - + keypad(newWindow, TRUE); return newWindow; } - WINDOW* TUI::createDetailViewWindow( int iXSize, int iYSize, int iXStart) { WINDOW *newWindow; 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); centerTitle(newWindow, "Selected Drive: xyz"); + keypad(newWindow, TRUE); return newWindow; } @@ -153,12 +162,12 @@ WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, box(newWindow, ACS_VLINE, ACS_HLINE); attron(COLOR_PAIR(COLOR_AREA_ENTRY)); - + mvwaddstr(newWindow,1, 1, sModelFamily.c_str()); mvwaddstr(newWindow,2, 1, sModelName.c_str()); mvwaddstr(newWindow,3, 1, sCapacity.c_str()); - // refresh(); + keypad(newWindow, TRUE); return newWindow; } diff --git a/src/reHDD.cpp b/src/reHDD.cpp index e5394de..3d75f29 100644 --- a/src/reHDD.cpp +++ b/src/reHDD.cpp @@ -54,6 +54,7 @@ void reHDD::app_logic(void) FD_SET(fdWhipe[0], &selectSet); thread thDevices(ThreadScannDevices); //start thread that scanns for drives + thread thUserInput(ThreadUserInput); //start thread that reads user input while(1) { @@ -76,6 +77,7 @@ void reHDD::app_logic(void) } } //endless loop thDevices.join(); + thUserInput.join(); } 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 * pvecOldDrives, vector * pvecNewDrives) { @@ -116,11 +154,9 @@ void reHDD::filterNewDrives(vector * pvecOldDrives, vector * pvecN } pvecOldDrives->clear(); - for (long unsigned int i=0; isize(); i++) { pvecOldDrives->push_back((*pvecNewDrives)[i]); } - } /**