mirror of
https://github.com/palera1n/palera1n.git
synced 2026-10-23 18:49:48 +02:00
newt ui
This commit is contained in:
1 parent
ad2cb43392
commit
f22bee6870
9 files changed
+102
-287
No files matched your search
+33
-56
@@ -1,8 +1,3 @@
|
||||
#define NCURSES_WIDECHAR 1
|
||||
|
||||
#include <ncurses.h>
|
||||
#include <form.h>
|
||||
#include <menu.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
@@ -18,74 +13,56 @@
|
||||
#include <tui.h>
|
||||
|
||||
int redraw_screen() {
|
||||
erase();
|
||||
resizeterm(24, 80);
|
||||
box(stdscr, 0, 0);
|
||||
mvaddstr(0, 80 - strlen("[palera1n version " PALERAIN_VERSION "]") - 2 , "[palera1n version " PALERAIN_VERSION "]");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int destroy_window() {
|
||||
endwin();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int init_window() {
|
||||
setlocale(LC_ALL, NULL);
|
||||
initscr();
|
||||
if (has_colors() == TRUE) {
|
||||
start_color();
|
||||
init_pair(MSG_COLOR, COLOR_YELLOW, COLOR_BLACK);
|
||||
init_pair(ICON_COLOR, COLOR_WHITE, COLOR_BLACK);
|
||||
}
|
||||
int height, width;
|
||||
getmaxyx(stdscr, height, width);
|
||||
if (width < 80 || height < 24) {
|
||||
LOG(LOG_ERROR, "Terminal size must be at least 80x24");
|
||||
return -1;
|
||||
}
|
||||
if (has_colors() == FALSE) {
|
||||
LOG(LOG_VERBOSE2, "Terminal without color support detected");
|
||||
}
|
||||
cbreak();
|
||||
noecho();
|
||||
keypad(stdscr, TRUE);
|
||||
newtInit();
|
||||
newtCls();
|
||||
newtDrawRootText(0, 0, "Package Configuration");
|
||||
newtPushHelpLine(NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tui() {
|
||||
int ret = MAIN_SCREEN;
|
||||
init_window();
|
||||
int ret = MAIN_SCREEN;
|
||||
while (1) {
|
||||
redraw_screen();
|
||||
switch (ret) {
|
||||
case ERROR_SCREEN:
|
||||
goto out;
|
||||
break;
|
||||
case EXIT_SCREEN:
|
||||
goto out;
|
||||
break;
|
||||
case MAIN_SCREEN:
|
||||
ret = tui_screen_main();
|
||||
break;
|
||||
case OPTIONS_SCREEN:
|
||||
ret = tui_screen_options();
|
||||
break;
|
||||
case ENTER_RECOVERY_SCREEN:
|
||||
ret = tui_screen_enter_recovery();
|
||||
break;
|
||||
case ENTER_DFU_SCREEN:
|
||||
ret = tui_screen_enter_dfu();
|
||||
break;
|
||||
case JAILBREAKING_SCREEN:
|
||||
ret = tui_screen_jailbreak();
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
goto out;
|
||||
case ERROR_SCREEN:
|
||||
goto out;
|
||||
break;
|
||||
case EXIT_SCREEN:
|
||||
goto out;
|
||||
break;
|
||||
case MAIN_SCREEN:
|
||||
ret = tui_screen_main();
|
||||
break;
|
||||
case OPTIONS_SCREEN:
|
||||
ret = tui_screen_options();
|
||||
break;
|
||||
case ENTER_RECOVERY_SCREEN:
|
||||
ret = tui_screen_enter_recovery();
|
||||
break;
|
||||
case ENTER_DFU_SCREEN:
|
||||
ret = tui_screen_enter_dfu();
|
||||
break;
|
||||
case JAILBREAKING_SCREEN:
|
||||
ret = tui_screen_jailbreak();
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
goto out;
|
||||
}
|
||||
newtPopWindow();
|
||||
}
|
||||
out:
|
||||
destroy_window();
|
||||
return ret;
|
||||
newtFinished();
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -1,8 +1,3 @@
|
||||
#define NCURSES_WIDECHAR 1
|
||||
|
||||
#include <ncurses.h>
|
||||
#include <form.h>
|
||||
#include <menu.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
#define NCURSES_WIDECHAR 1
|
||||
|
||||
#include <ncurses.h>
|
||||
#include <form.h>
|
||||
#include <menu.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
#define NCURSES_WIDECHAR 1
|
||||
|
||||
#include <ncurses.h>
|
||||
#include <form.h>
|
||||
#include <menu.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
+21
-92
@@ -1,8 +1,3 @@
|
||||
#define NCURSES_WIDECHAR 1
|
||||
|
||||
#include <ncurses.h>
|
||||
#include <form.h>
|
||||
#include <menu.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
@@ -18,93 +13,27 @@
|
||||
#include <tui.h>
|
||||
|
||||
tui_screen_t tui_screen_main() {
|
||||
int ret = -1;
|
||||
mvaddstr(1, 2, "Welcome to palera1n!");
|
||||
move(2,1);
|
||||
whline(stdscr, ACS_HLINE, 80 - 2);
|
||||
move(5,2);
|
||||
attron(COLOR_PAIR(MSG_COLOR));
|
||||
mvaddstr(4,2, "Connect your iPhone, iPad, or iPod Touch");
|
||||
mvaddstr(5,2, "to begin.");
|
||||
attroff(COLOR_PAIR(MSG_COLOR));
|
||||
attron(COLOR_PAIR(ICON_COLOR));
|
||||
mvaddwstr(2, 43, L" MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM ");
|
||||
mvaddwstr(3, 44, L"MMMMMMMMMMMMMWNOddONWMMMMMMMMMMMMM");
|
||||
mvaddwstr(4, 44, L"MMMMMMMMMMMMWNx. .xNWMMMMMMMMMMMM");
|
||||
mvaddwstr(5, 44, L"MMMMMMMMMMMMW0;....;OWMMMMMMMMMMMM");
|
||||
mvaddwstr(6, 44, L"MMMMMMMMMMMMW0;....;OWMMMMMMMMMMMM");
|
||||
mvaddwstr(7, 44, L"MMMMMMMMMMMWXo'.....lKWMMMMMMMMMMM");
|
||||
mvaddwstr(8, 44, L"MMMMMMMMMMWNkc;'....'dNWMMMMMMMMMM");
|
||||
mvaddwstr(9, 44, L"MMMMMMMMMMN0dc:,''''.:ONWMMMMMMMMM");
|
||||
mvaddwstr(10, 44, L"MMMMMMMMMWKxllc;,'''',lKWMMMMMMMMM");
|
||||
mvaddwstr(11, 44, L"MMMMMMMMWNkoolc;,,,,;;:xXWMMMMMMMM");
|
||||
mvaddwstr(12, 44, L"MMMMMMMMW0olllc;,,,,,,,:OWMMMMMMMM");
|
||||
mvaddwstr(13, 44, L"MMMMMMMMNOollc:,'....'';xNMMMMMMMM");
|
||||
mvaddwstr(14, 44, L"MMMMMMMMW0dllc:,''''''':OWMMMMMMMM");
|
||||
mvaddwstr(15, 44, L"MMMMMMMMWN0dc::;;,,,,,cONWMMMMMMMM");
|
||||
mvaddwstr(16, 44, L"MMMMMMMMMMWXOxoc::cldkXWMMMMMMMMMM");
|
||||
mvaddwstr(17, 44, L"MMMMMMMMMMMMWWNNXXNNWWMMMMMMMMMMMM");
|
||||
mvaddwstr(18, 44, L"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM");
|
||||
mvaddstr(7, 2, "Made by: Nick Chan, Mineek, Tom, Nebula,");
|
||||
mvaddstr(8, 2, "llsc12, Nathan");
|
||||
move(9, 2);
|
||||
whline(stdscr, ACS_HLINE, 40);
|
||||
mvaddstr(10, 2, "Thanks to: nyuszika7h, Procursus Team");
|
||||
mvaddstr(11, 2, "dora2ios, m1sta, Serena, xerub, tihmstar");
|
||||
mvaddstr(12, 2, "sbingner, checkra1n team (Siguza, Axi0mx");
|
||||
mvaddstr(13, 2, "argp et al.)");
|
||||
move(14, 2);
|
||||
whline(stdscr, ACS_HLINE, 40);
|
||||
mvaddstr(19, 2, "palera1n is NOT affinated with checkra1n");
|
||||
mvaddstr(20, 2, "Note: Backup your stuff. Use at your own risk.");
|
||||
mvaddstr(19, 78 - strlen("@palera1n"), "@palera1n");
|
||||
mvaddstr(20, 78 - strlen("https://palera.in"), "https://palera.in");
|
||||
attroff(COLOR_PAIR(ICON_COLOR));
|
||||
move(21,1);
|
||||
whline(stdscr, ACS_HLINE, 80 - 2);
|
||||
move(22, 40);
|
||||
|
||||
ITEM* main_buttons[4];
|
||||
MENU* main_menu;
|
||||
|
||||
main_buttons[0] = new_item(MAIN_OPTIONS, "");
|
||||
main_buttons[1] = new_item(MAIN_START, "");
|
||||
main_buttons[2] = new_item(MAIN_EXIT, "");
|
||||
main_buttons[3] = NULL;
|
||||
main_menu = new_menu(main_buttons);
|
||||
item_opts_off(main_buttons[1], O_SELECTABLE);
|
||||
|
||||
set_menu_format(main_menu, 1, 40);
|
||||
set_menu_sub(main_menu, derwin(stdscr, 0, 0, 22, 50));
|
||||
post_menu(main_menu);
|
||||
raw();
|
||||
refresh();
|
||||
while (1) {
|
||||
int ch = getch();
|
||||
if (ch == KEY_LEFT) {
|
||||
menu_driver(main_menu, REQ_LEFT_ITEM);
|
||||
} else if (ch == KEY_RIGHT) {
|
||||
menu_driver(main_menu, REQ_RIGHT_ITEM);
|
||||
} else if (ch == 10) {
|
||||
if (!(item_opts(current_item(main_menu)) & O_SELECTABLE)) continue;
|
||||
// fprintf(stderr, "Button %s pressed\n", current_item(main_menu)->name.str);
|
||||
if (!strcmp(current_item(main_menu)->name.str, MAIN_EXIT)) {
|
||||
ret = EXIT_SCREEN;
|
||||
} else if (!strcmp(current_item(main_menu)->name.str, MAIN_START)) {
|
||||
ret = ENTER_RECOVERY_SCREEN;
|
||||
} else if (!strcmp(current_item(main_menu)->name.str, MAIN_OPTIONS)) {
|
||||
ret = OPTIONS_SCREEN;
|
||||
}
|
||||
goto end;
|
||||
}
|
||||
refresh();
|
||||
int ret = MAIN_SCREEN;
|
||||
bool can_start = false;
|
||||
newtCenteredWindow(60, 16, "palera1n version 2.0.0");
|
||||
newtComponent optionsButton = newtCompactButton(30, 14, "Options");
|
||||
newtComponent startButton = newtCompactButton(41, 14, "Start");
|
||||
newtComponent exitButton = newtCompactButton(50, 14, "Exit");
|
||||
newtComponent welcome = newtLabel(1, 0, "Welcome to palera1n!");
|
||||
newtComponent form = newtForm(NULL, NULL, 0);
|
||||
newtFormAddComponents(form, optionsButton, startButton, exitButton, welcome, NULL);
|
||||
newtRunForm(form);
|
||||
newtRefresh();
|
||||
newtComponent buttonPressed = newtFormGetCurrent(form);
|
||||
if (buttonPressed == optionsButton) {
|
||||
ret = OPTIONS_SCREEN;
|
||||
} else if (buttonPressed == startButton) {
|
||||
if (can_start)
|
||||
ret = ENTER_RECOVERY_SCREEN;
|
||||
else
|
||||
ret = MAIN_SCREEN;
|
||||
} else if (buttonPressed == exitButton) {
|
||||
ret = EXIT_SCREEN;
|
||||
}
|
||||
end:
|
||||
noraw();
|
||||
unpost_menu(main_menu);
|
||||
free_menu(main_menu);
|
||||
free_item(main_buttons[0]);
|
||||
free_item(main_buttons[1]);
|
||||
free_item(main_buttons[2]);
|
||||
return ret;
|
||||
}
|
||||
+35
-38
@@ -1,8 +1,3 @@
|
||||
#define NCURSES_WIDECHAR 1
|
||||
|
||||
#include <ncurses.h>
|
||||
#include <form.h>
|
||||
#include <menu.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
@@ -17,44 +12,46 @@
|
||||
#include <common.h>
|
||||
#include <tui.h>
|
||||
|
||||
void bitfield_check_cb(newtComponent box, void* data) {
|
||||
if (newtCheckboxGetValue(box) == ' ') {
|
||||
*((tui_bit_info_t*)data)->flags_p = *((tui_bit_info_t*)data)->flags_p &~ ((tui_bit_info_t*)data)->opt;
|
||||
} else if (newtCheckboxGetValue(box) == '*') {
|
||||
*((tui_bit_info_t*)data)->flags_p |= ((tui_bit_info_t*)data)->opt;
|
||||
} else assert(0);
|
||||
}
|
||||
|
||||
tui_screen_t tui_screen_options() {
|
||||
tui_screen_t ret = EXIT_SCREEN;
|
||||
ITEM* back_button[2];
|
||||
MENU* back_menu;
|
||||
back_button[0] = new_item("Back", "");
|
||||
back_button[1] = NULL;
|
||||
back_menu = new_menu(back_button);
|
||||
tui_bit_info_t verbose_info = { &kpf_flags, checkrain_option_verbose_boot };
|
||||
tui_bit_info_t rootful_info = { &palerain_flags, palerain_option_rootful };
|
||||
tui_bit_info_t setup_rootful_info = { &palerain_flags, palerain_option_setup_rootful };
|
||||
tui_bit_info_t force_revert_info = { &checkrain_flags, checkrain_option_force_revert };
|
||||
tui_bit_info_t safemode_info = { &checkrain_flags, checkrain_option_safemode };
|
||||
|
||||
move(21, 1);
|
||||
hline(ACS_HLINE, 80 - 2);
|
||||
int ret = MAIN_SCREEN;
|
||||
|
||||
set_menu_format(back_menu, 1, 10);
|
||||
set_menu_sub(back_menu, derwin(stdscr, 0, 0, 22, 68));
|
||||
post_menu(back_menu);
|
||||
newtCenteredWindow(60, 16, "palera1n version 2.0.0");
|
||||
newtComponent backButton = newtCompactButton(50, 14, "Back");
|
||||
|
||||
FORM* options_form;
|
||||
FIELD* options[3];
|
||||
|
||||
options[0] = new_field(2, 2, 2, 2);
|
||||
options[1] = new_field();
|
||||
options[2] = NULL;
|
||||
newtComponent verboseBootBox = newtCheckbox(1, 1, "Verbose boot", CHECKBOX_STATE(kpf_flags, checkrain_option_verbose_boot), NULL, NULL);
|
||||
newtComponent rootfulBox = newtCheckbox(1, 2, "Rootful", CHECKBOX_STATE(palerain_flags, palerain_option_rootful), NULL, NULL);
|
||||
newtComponent rootfulSetupBox = newtCheckbox(1, 3, "Setup fakefs", CHECKBOX_STATE(palerain_flags, palerain_option_setup_rootful), NULL, NULL);
|
||||
newtComponent forceRevertBox = newtCheckbox(1, 4, "Restore system", CHECKBOX_STATE(checkrain_flags, checkrain_option_force_revert), NULL, NULL);
|
||||
newtComponent safeModeBox = newtCheckbox(1, 5, "Safe mode", CHECKBOX_STATE(checkrain_flags, checkrain_option_safemode), NULL, NULL);
|
||||
|
||||
refresh();
|
||||
newtComponentAddCallback(verboseBootBox, bitfield_check_cb, &verbose_info);
|
||||
newtComponentAddCallback(rootfulBox, bitfield_check_cb, &rootful_info);
|
||||
newtComponentAddCallback(rootfulSetupBox, bitfield_check_cb, &setup_rootful_info);
|
||||
newtComponentAddCallback(forceRevertBox, bitfield_check_cb, &force_revert_info);
|
||||
newtComponentAddCallback(safeModeBox, bitfield_check_cb, &safemode_info);
|
||||
|
||||
while(1) {
|
||||
int ch = getch();
|
||||
if (ch == 10) {
|
||||
if (!(item_opts(current_item(back_menu)) & O_SELECTABLE)) continue;
|
||||
if (!strcmp(current_item(back_menu)->name.str, BACK_BUTTON)) {
|
||||
ret = MAIN_SCREEN;
|
||||
}
|
||||
goto end;
|
||||
}
|
||||
refresh();
|
||||
}
|
||||
end:
|
||||
unpost_menu(back_menu);
|
||||
free_item(back_button[0]);
|
||||
free_menu(back_menu);
|
||||
newtComponent form = newtForm(NULL, NULL, 0);
|
||||
newtFormAddComponents(form, backButton, verboseBootBox, rootfulBox,
|
||||
rootfulSetupBox, forceRevertBox, safeModeBox, NULL);
|
||||
newtRunForm(form);
|
||||
newtRefresh();
|
||||
newtComponent buttonPressed = newtFormGetCurrent(form);
|
||||
if (buttonPressed == backButton) {
|
||||
ret = MAIN_SCREEN;
|
||||
} else assert(0);
|
||||
return ret;
|
||||
}
|
||||
Reference in new issue
Block a user