1
0
mirror of https://gitlab.com/comunic/comunicterm synced 2024-12-26 13:38:55 +00:00

Basic input of email & password

This commit is contained in:
Pierre HUBERT 2020-01-08 20:33:16 +01:00
parent d190a7ecce
commit 5f9654d3b4
2 changed files with 117 additions and 35 deletions

View File

@ -2,6 +2,7 @@
#include <string.h> #include <string.h>
#include <string> #include <string>
#include <iostream>
#include "loginscreen.h" #include "loginscreen.h"
@ -12,14 +13,42 @@ LoginScreen::LoginScreen()
} }
enum CursorPos {
EMAIL = 0,
PASSWORD = 1,
SUBMIT = 2
};
bool LoginScreen::exec() bool LoginScreen::exec()
{ {
initscr(); /* Start curses mode */ initscr(); /* Start curses mode */
keypad(stdscr, TRUE); // Listen to function keys keypad(stdscr, TRUE); // Listen to function keys
noecho();
cbreak(); /* Line buffering disabled. pass on everything */
string email, password;
getCredentials(email, password);
mvprintw(3,0, "Done!");
getch(); /* Wait for user input */
endwin(); /* End curses mode */
}
void LoginScreen::getCredentials(string &email, string &pass)
{
int currPos = 0;
int currX = 0, currY = 0;
bool stop = false;
do {
erase();
printw("ComunicTerm"); /* Print Hello World */ printw("ComunicTerm"); /* Print Hello World */
refresh(); /* Print it on to the real screen */
// Get screen size // Get screen size
@ -37,25 +66,73 @@ bool LoginScreen::exec()
mvprintw(startX, startY, "Please login to your Comunic account:"); mvprintw(startX, startY, "Please login to your Comunic account:");
// Ask for email // Ask for email
wattron(stdscr, A_REVERSE); if(currPos == EMAIL) wattron(stdscr, A_REVERSE);
mvprintw(startX+2, startY, "Email address:"); mvprintw(startX+2, startY, "Email address:");
wattroff(stdscr, A_REVERSE); wattroff(stdscr, A_REVERSE);
printw(" ");
printw(email.c_str());
if(currPos == EMAIL) getyx(stdscr, currY, currX);
// Ask for password // Ask for password
wattron(stdscr, A_REVERSE); if(currPos == PASSWORD) wattron(stdscr, A_REVERSE);
mvprintw(startX+4, startY, "Password:"); mvprintw(startX+4, startY, "Password:");
wattroff(stdscr, A_REVERSE); wattroff(stdscr, A_REVERSE);
printw(" ");
printw(pass.c_str());
if(currPos == PASSWORD) getyx(stdscr, currY, currX);
// Validate button // Validate button
wattron(stdscr, A_REVERSE); if(currPos == SUBMIT) wattron(stdscr, A_REVERSE);
mvprintw(startX+6, startY, "Login"); mvprintw(startX+6, startY, "Login");
wattroff(stdscr, A_REVERSE); wattroff(stdscr, A_REVERSE);
if(currPos == SUBMIT) {curs_set(0);} else {curs_set(2);}
move(currY, currX);
refresh(); refresh();
int c = wgetch(stdscr);
getch(); /* Wait for user input */ switch(c) {
endwin(); /* End curses mode */ case KEY_UP:
currPos--;
if(currPos < 0) currPos = 0;
break;
case KEY_DOWN:
currPos++;
if(currPos > 2) currPos = 0;
break;
case 10: // ENTER
if(currPos == EMAIL)
currPos++;
else
stop = true;
break;
case 263: // Erase
if(currPos == EMAIL && email.length() > 0)
email.pop_back();
else if(currPos == PASSWORD && pass.length() > 0)
pass.pop_back();
break;
default:
if(c > 126) break; // We can not process this value
if(currPos == EMAIL)
email += static_cast<char>(c);
else if(currPos == PASSWORD)
pass += static_cast<char>(c);
}
} while(!stop);
} }

View File

@ -4,10 +4,15 @@
* @author Pierre HUBERT * @author Pierre HUBERT
*/ */
#include <string>
class LoginScreen class LoginScreen
{ {
public: public:
LoginScreen(); LoginScreen();
bool exec(); bool exec();
private:
void getCredentials(std::string &email, std::string &pass);
}; };