refactor print in the midle function

This commit is contained in:
PoliEcho 2024-11-29 20:12:07 +01:00
parent e5c2ae6da5
commit 83c8f8a324
5 changed files with 43 additions and 47 deletions

View File

@ -1,13 +1,13 @@
#include "net.h"
#include <csignal>
#include <curses.h>
#include <dirent.h>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <string>
#include <termios.h>
#include <unistd.h>
#include <fstream>
#include "net.h"
void safe_exit(int code) {
switch (code) {
@ -38,11 +38,9 @@ void safe_exit(int code) {
exit(code);
}
std::string bool_to_string(bool bool_in) {
return bool_in ? "true" : "false";
}
std::string bool_to_string(bool bool_in) { 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");
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";
if(save){
if (save) {
std::ofstream authfile(authfile_path);
authfile << data;
authfile.close();
@ -76,16 +74,39 @@ std::string SoRAuthFile(bool save, std::string data){
}
void get_input_and_login() {
std::string username;
std::cout << "enter username: ";
std::cin >> username;
std::string password;
std::string username;
std::cout << "enter username: ";
std::cin >> username;
std::string password;
password = getpass("enter password: ");
// DEBUG
// std::cout << "\nenter password: ";
// std::cin >> password;
password = getpass("enter password: ");
// DEBUG
// std::cout << "\nenter 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();
}

View File

@ -1,5 +1,8 @@
#include <curses.h>
#include <string>
void safe_exit(int code);
std::string bool_to_string(bool bool_in);
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);

View File

@ -2,7 +2,7 @@
#include "color.h"
#include "helper_funcs.h"
#include "main_menu.h"
#include "marks/marks.h"
#include "marks.h"
#include "net.h"
#include <csignal>
#include <curl/curl.h>

View File

@ -13,8 +13,6 @@ char *choices[] = {
"login", "Grades", "shedule", "Komens",
"Homework", "Absence", "Exit", (char *)NULL,
};
void print_in_middle(WINDOW *win, int starty, int startx, int width,
char *string, chtype color);
void main_menu() {
ITEM **my_items;
@ -104,27 +102,3 @@ void main_menu() {
free_item(my_items[i]);
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();
}

View File

@ -1,4 +1,5 @@
#include "marks.h"
#include "helper_funcs.h"
#include <cstdint>
#include <cstdio>
#include <cstring>
@ -7,7 +8,6 @@
#include <menu.h>
#include <nlohmann/json.hpp>
#include <panel.h>
#include <vector>
using nlohmann::json;
@ -42,8 +42,6 @@ SOFTWARE.
void init_wins(WINDOW **wins, int n, json marks_json);
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() {