refactor print in the midle function
This commit is contained in:
parent
e5c2ae6da5
commit
83c8f8a324
@ -1,13 +1,13 @@
|
|||||||
|
#include "net.h"
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fstream>
|
|
||||||
#include "net.h"
|
|
||||||
|
|
||||||
void safe_exit(int code) {
|
void safe_exit(int code) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
@ -38,11 +38,9 @@ void safe_exit(int code) {
|
|||||||
exit(code);
|
exit(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string bool_to_string(bool bool_in) {
|
std::string bool_to_string(bool bool_in) { return bool_in ? "true" : "false"; }
|
||||||
return bool_in ? "true" : "false";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string SoRAuthFile(bool save, std::string data){
|
std::string SoRAuthFile(bool save, std::string data) {
|
||||||
|
|
||||||
std::string savedir_path = std::getenv("HOME");
|
std::string savedir_path = std::getenv("HOME");
|
||||||
savedir_path.append("/.local/share/bakatui");
|
savedir_path.append("/.local/share/bakatui");
|
||||||
@ -62,7 +60,7 @@ std::string SoRAuthFile(bool save, std::string data){
|
|||||||
|
|
||||||
std::string authfile_path = std::string(savedir_path) + "/auth";
|
std::string authfile_path = std::string(savedir_path) + "/auth";
|
||||||
|
|
||||||
if(save){
|
if (save) {
|
||||||
std::ofstream authfile(authfile_path);
|
std::ofstream authfile(authfile_path);
|
||||||
authfile << data;
|
authfile << data;
|
||||||
authfile.close();
|
authfile.close();
|
||||||
@ -76,16 +74,39 @@ std::string SoRAuthFile(bool save, std::string data){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void get_input_and_login() {
|
void get_input_and_login() {
|
||||||
std::string username;
|
std::string username;
|
||||||
std::cout << "enter username: ";
|
std::cout << "enter username: ";
|
||||||
std::cin >> username;
|
std::cin >> username;
|
||||||
std::string password;
|
std::string password;
|
||||||
|
|
||||||
password = getpass("enter password: ");
|
password = getpass("enter password: ");
|
||||||
// DEBUG
|
// DEBUG
|
||||||
// std::cout << "\nenter password: ";
|
// std::cout << "\nenter password: ";
|
||||||
// std::cin >> password;
|
// std::cin >> password;
|
||||||
|
|
||||||
bakaapi::login(username, password);
|
bakaapi::login(username, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print_in_middle(WINDOW *win, int starty, int startx, int width,
|
||||||
|
char *string, chtype color) {
|
||||||
|
int length, x, y;
|
||||||
|
float temp;
|
||||||
|
|
||||||
|
if (win == NULL)
|
||||||
|
win = stdscr;
|
||||||
|
getyx(win, y, x);
|
||||||
|
if (startx != 0)
|
||||||
|
x = startx;
|
||||||
|
if (starty != 0)
|
||||||
|
y = starty;
|
||||||
|
if (width == 0)
|
||||||
|
width = 80;
|
||||||
|
|
||||||
|
length = strlen(string);
|
||||||
|
temp = (width - length) / 2;
|
||||||
|
x = startx + (int)temp;
|
||||||
|
wattron(win, color);
|
||||||
|
mvwprintw(win, y, x, "%s", string);
|
||||||
|
wattroff(win, color);
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
@ -1,5 +1,8 @@
|
|||||||
|
#include <curses.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
void safe_exit(int code);
|
void safe_exit(int code);
|
||||||
std::string bool_to_string(bool bool_in);
|
std::string bool_to_string(bool bool_in);
|
||||||
std::string SoRAuthFile(bool save, std::string data);
|
std::string SoRAuthFile(bool save, std::string data);
|
||||||
void get_input_and_login();
|
void get_input_and_login();
|
||||||
|
void print_in_middle(WINDOW *win, int starty, int startx, int width,
|
||||||
|
char *string, chtype color);
|
||||||
@ -2,7 +2,7 @@
|
|||||||
#include "color.h"
|
#include "color.h"
|
||||||
#include "helper_funcs.h"
|
#include "helper_funcs.h"
|
||||||
#include "main_menu.h"
|
#include "main_menu.h"
|
||||||
#include "marks/marks.h"
|
#include "marks.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
|
|||||||
@ -13,8 +13,6 @@ char *choices[] = {
|
|||||||
"login", "Grades", "shedule", "Komens",
|
"login", "Grades", "shedule", "Komens",
|
||||||
"Homework", "Absence", "Exit", (char *)NULL,
|
"Homework", "Absence", "Exit", (char *)NULL,
|
||||||
};
|
};
|
||||||
void print_in_middle(WINDOW *win, int starty, int startx, int width,
|
|
||||||
char *string, chtype color);
|
|
||||||
|
|
||||||
void main_menu() {
|
void main_menu() {
|
||||||
ITEM **my_items;
|
ITEM **my_items;
|
||||||
@ -104,27 +102,3 @@ void main_menu() {
|
|||||||
free_item(my_items[i]);
|
free_item(my_items[i]);
|
||||||
endwin();
|
endwin();
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_in_middle(WINDOW *win, int starty, int startx, int width,
|
|
||||||
char *string, chtype color) {
|
|
||||||
int length, x, y;
|
|
||||||
float temp;
|
|
||||||
|
|
||||||
if (win == NULL)
|
|
||||||
win = stdscr;
|
|
||||||
getyx(win, y, x);
|
|
||||||
if (startx != 0)
|
|
||||||
x = startx;
|
|
||||||
if (starty != 0)
|
|
||||||
y = starty;
|
|
||||||
if (width == 0)
|
|
||||||
width = 80;
|
|
||||||
|
|
||||||
length = strlen(string);
|
|
||||||
temp = (width - length) / 2;
|
|
||||||
x = startx + (int)temp;
|
|
||||||
wattron(win, color);
|
|
||||||
mvwprintw(win, y, x, "%s", string);
|
|
||||||
wattroff(win, color);
|
|
||||||
refresh();
|
|
||||||
}
|
|
||||||
@ -1,4 +1,5 @@
|
|||||||
#include "marks.h"
|
#include "marks.h"
|
||||||
|
#include "helper_funcs.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@ -7,7 +8,6 @@
|
|||||||
#include <menu.h>
|
#include <menu.h>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <panel.h>
|
#include <panel.h>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
@ -42,8 +42,6 @@ SOFTWARE.
|
|||||||
|
|
||||||
void init_wins(WINDOW **wins, int n, json marks_json);
|
void init_wins(WINDOW **wins, int n, json marks_json);
|
||||||
void win_show(WINDOW *win, char *label, int label_color);
|
void win_show(WINDOW *win, char *label, int label_color);
|
||||||
void print_in_middle(WINDOW *win, int starty, int startx, int width,
|
|
||||||
char *string, chtype color);
|
|
||||||
|
|
||||||
void marks_page() {
|
void marks_page() {
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user