select drive based on arrow keys

This commit is contained in:
2020-08-07 11:38:00 +02:00
parent a92a9c2a2a
commit 1b0ea97ed1
7 changed files with 355 additions and 267 deletions

View File

@ -8,7 +8,8 @@
#include "../../include/reHDD.h"
TUI::TUI(void) {
TUI::TUI(void)
{
@ -26,12 +27,15 @@ void TUI::initTUI()
initscr();
raw();
keypad(stdscr,TRUE);
if(has_colors() == TRUE) {
start_color();
} else {
printf("Your terminal does not support color\n");
exit(1);
}
if(has_colors() == TRUE)
{
start_color();
}
else
{
printf("Your terminal does not support color\n");
exit(1);
}
clear();
curs_set(0);
noecho();
@ -41,11 +45,18 @@ void TUI::initTUI()
init_pair(COLOR_AREA_STDSCR,COLOR_WHITE, COLOR_BLUE);
wbkgd(stdscr, COLOR_PAIR(COLOR_AREA_STDSCR));
init_pair(COLOR_AREA_ENTRY, COLOR_BLACK, COLOR_GRAY);
init_pair(COLOR_AREA_ENTRY_SELECTED, COLOR_BLACK, COLOR_WHITE);
init_pair(COLOR_AREA_OVERVIEW, COLOR_BLACK, COLOR_GRAY);
init_pair(COLOR_AREA_OVERVIEW, COLOR_BLACK, COLOR_GRAY);
mvprintw(0, 2, "reHDD - HDD refurbishing tool - GPL 3.0 ");
}
void TUI::updateTUI(vector <Drive>* pvecDrives) {
void TUI::updateTUI(vector <Drive>* pvecDrives, int32_t i32SelectedEntry)
{
int stdscrX, stdscrY;
getmaxyx(stdscr, stdscrY, stdscrX);
@ -63,19 +74,27 @@ void TUI::updateTUI(vector <Drive>* pvecDrives) {
vector <Drive>::iterator it;
for (it = pvecDrives->begin(); it != pvecDrives->end(); ++it)
{
string sModelFamily = it->getModelFamily();
string sModelName = it->getModelName();
string sCapacity = it->sCapacityToText();
{
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);
wrefresh(tmp);
}
bool bSelectedEntry = false;
if(i32SelectedEntry == (it - pvecDrives->begin()))
{
bSelectedEntry = true;
}
WINDOW * tmp = createEntryWindow( ((int)(stdscrX/3) - 2), 5, 3, (5* (it - pvecDrives->begin()) )+3, sModelFamily, sModelName, sCapacity, bSelectedEntry);
wrefresh(tmp);
}
}
enum TUI::UserInput TUI::readUserInput() {
int ch = wgetch(stdscr);
switch(ch)
enum TUI::UserInput TUI::readUserInput()
{
int ch = wgetch(stdscr);
switch(ch)
{
case KEY_UP:
return TUI::UserInput::UpKey;
@ -106,7 +125,8 @@ enum TUI::UserInput TUI::readUserInput() {
}
void TUI::centerTitle(WINDOW *pwin, const char * title) {
void TUI::centerTitle(WINDOW *pwin, const char * title)
{
int x, maxX, stringSize;
getmaxyx(pwin, maxX, maxX);
stringSize = 4 + strlen(title);
@ -118,10 +138,11 @@ void TUI::centerTitle(WINDOW *pwin, const char * title) {
waddch(pwin, ACS_LTEE);
}
WINDOW* TUI::createOverViewWindow( int iXSize, int iYSize) {
WINDOW* TUI::createOverViewWindow( int iXSize, int iYSize)
{
WINDOW *newWindow;
newWindow = newwin(iYSize, iXSize, 2, 2);
init_pair(COLOR_AREA_OVERVIEW, COLOR_BLACK, COLOR_GRAY);
wbkgd(newWindow, COLOR_PAIR(COLOR_AREA_OVERVIEW));
box(newWindow, ACS_VLINE, ACS_HLINE);
@ -142,10 +163,11 @@ WINDOW* TUI::createOverViewWindow( int iXSize, int iYSize) {
return newWindow;
}
WINDOW* TUI::createDetailViewWindow( int iXSize, int iYSize, int iXStart) {
WINDOW* TUI::createDetailViewWindow( int iXSize, int iYSize, int iXStart)
{
WINDOW *newWindow;
newWindow = newwin(iYSize, iXSize, 2, iXStart);
init_pair(COLOR_AREA_OVERVIEW, COLOR_BLACK, COLOR_GRAY);
wbkgd(newWindow, COLOR_PAIR(COLOR_AREA_OVERVIEW));
box(newWindow, ACS_VLINE, ACS_HLINE);
centerTitle(newWindow, "Selected Drive: xyz");
@ -154,14 +176,27 @@ WINDOW* TUI::createDetailViewWindow( int iXSize, int iYSize, int iXStart) {
return newWindow;
}
WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, string sModelFamily, string sModelName, string sCapacity) {
WINDOW* TUI::createEntryWindow(int iXSize, int iYSize, int iXStart, int iYStart, string sModelFamily, string sModelName, string sCapacity, bool bSelected)
{
WINDOW *newWindow;
newWindow = newwin(iYSize, iXSize, iYStart, iXStart);
init_pair(COLOR_AREA_ENTRY, COLOR_BLACK, COLOR_GRAY);
wbkgd(newWindow, COLOR_PAIR(COLOR_AREA_ENTRY));
box(newWindow, ACS_VLINE, ACS_HLINE);
attron(COLOR_PAIR(COLOR_AREA_ENTRY));
if(!bSelected)
{
// entry is NOT selected
attron(COLOR_PAIR(COLOR_AREA_ENTRY));
wbkgd(newWindow, COLOR_PAIR(COLOR_AREA_ENTRY));
}
else
{
// entry IS selected
attron(COLOR_PAIR(COLOR_AREA_ENTRY));
wbkgd(newWindow, COLOR_PAIR(COLOR_AREA_ENTRY_SELECTED));
}
box(newWindow, ACS_VLINE, ACS_HLINE);
mvwaddstr(newWindow,1, 1, sModelFamily.c_str());
mvwaddstr(newWindow,2, 1, sModelName.c_str());