mirror of
https://github.com/palera1n/palera1n.git
synced 2026-10-24 19:19:48 +02:00
tui log
This commit is contained in:
1 parent
597280c3c6
commit
1524ed9440
4 files changed
+75
-25
No files matched your search
+22
-1
@@ -30,6 +30,11 @@
|
||||
#include <kerninfo.h>
|
||||
|
||||
pthread_mutex_t spin_mutex, found_pongo_mutex, ecid_dfu_wait_mutex;
|
||||
#ifdef DEV_BUILD
|
||||
#include <newt.h>
|
||||
pthread_mutex_t tui_log_mutex;
|
||||
newtComponent tui_log_output = NULL;
|
||||
#endif
|
||||
|
||||
bool spin, found_pongo = 0;
|
||||
uint64_t ecid_wait_for_dfu = 0;
|
||||
@@ -80,10 +85,26 @@ uint64_t get_ecid_wait_for_dfu() {
|
||||
}
|
||||
|
||||
uint64_t set_ecid_wait_for_dfu(uint64_t ecid) {
|
||||
LOG(LOG_VERBOSE5, "locking ecid wait for dfu value for set ecid_wait_for_dfu = %llu", ecid);
|
||||
LOG(LOG_VERBOSE5, "locking ecid wait for dfu mutex for set ecid_wait_for_dfu = %llu", ecid);
|
||||
pthread_mutex_lock(&ecid_dfu_wait_mutex);
|
||||
ecid_wait_for_dfu = ecid;
|
||||
LOG(LOG_VERBOSE5, "UN-locking ecid wait for dfu mutex afrer setting ecid_wait_for_dfu");
|
||||
pthread_mutex_unlock(&ecid_dfu_wait_mutex);
|
||||
return ecid;
|
||||
}
|
||||
|
||||
#ifdef DEV_BUILD
|
||||
newtComponent get_tui_log() {
|
||||
pthread_mutex_lock(&tui_log_mutex);
|
||||
newtComponent ret = tui_log_output;
|
||||
pthread_mutex_unlock(&tui_log_mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
newtComponent set_tui_log(newtComponent co) {
|
||||
pthread_mutex_lock(&tui_log_mutex);
|
||||
tui_log_output = co;
|
||||
pthread_mutex_unlock(&tui_log_mutex);
|
||||
return co;
|
||||
}
|
||||
#endif
|
||||
@@ -10,14 +10,22 @@
|
||||
|
||||
int p1_log(log_level_t loglevel, const char *fname, int lineno, const char *fxname, char *__restrict format, ...)
|
||||
{
|
||||
if (verbose >= 5) fprintf(stderr, "p1_log: loglevel %d from %s:%d:%s()\n", loglevel, fname, lineno, fxname);
|
||||
if (verbose >= 5
|
||||
#ifdef DEV_BUILD
|
||||
&& !use_tui
|
||||
#endif
|
||||
) fprintf(stderr, "p1_log: loglevel %d from %s:%d:%s()\n", loglevel, fname, lineno, fxname);
|
||||
int ret = 0;
|
||||
char type[0x10];
|
||||
char colour[0x10];
|
||||
char colour_bold[0x10];
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
if (verbose < (loglevel - 3) && loglevel > LOG_INFO) {
|
||||
if (verbose < (loglevel - 3) && loglevel > LOG_INFO
|
||||
#ifdef DEV_BUILD
|
||||
&& !use_tui
|
||||
#endif
|
||||
) {
|
||||
if (verbose >= 5) fprintf(stderr, "p1_log: hid log with high log level (%d < %d)\n", verbose, loglevel - 3);
|
||||
return 0;
|
||||
}
|
||||
@@ -49,28 +57,40 @@ int p1_log(log_level_t loglevel, const char *fname, int lineno, const char *fxna
|
||||
snprintf(colour_bold, 0x10, "%s", BWHT);
|
||||
break;
|
||||
}
|
||||
pthread_mutex_lock(&log_mutex);
|
||||
char timestring[0x80];
|
||||
time_t curtime;
|
||||
time(&curtime);
|
||||
struct tm* timeinfo = localtime(&curtime);
|
||||
snprintf(timestring, 0x80, "%s[%s%02d/%02d/%d %02d:%02d:%02d%s]", CRESET, HBLK, timeinfo->tm_mon + 1, timeinfo->tm_mday, timeinfo->tm_year - 100, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, CRESET);
|
||||
if (verbose >= 2) {
|
||||
printf("%s| - %s%s <%s> " CRESET "%s" HBLU "%s" CRESET ":" BLU "%d" CRESET ":" BMAG "%s()" CRESET ": \n%s| ----> ", colour_bold, timestring, colour_bold, type, WHT, fname, lineno, fxname, colour_bold);
|
||||
} else {
|
||||
printf(" - %s %s<%s>%s: ", timestring, colour_bold, type, CRESET);
|
||||
}
|
||||
printf("%s", colour);
|
||||
ret = vprintf(format, args);
|
||||
va_end(args);
|
||||
#ifdef DEV_BUILD
|
||||
if (use_tui) {
|
||||
newtComponent co = get_tui_log();
|
||||
if (co == NULL) {
|
||||
return 0; /* 0 bytes printed */
|
||||
}
|
||||
char printbuf[0x200];
|
||||
ret = vsnprintf(printbuf, 0x200, format, args);
|
||||
pthread_mutex_lock(&log_mutex);
|
||||
newtTextboxSetText(co, printbuf);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
pthread_mutex_lock(&log_mutex);
|
||||
char timestring[0x80];
|
||||
time_t curtime;
|
||||
time(&curtime);
|
||||
struct tm* timeinfo = localtime(&curtime);
|
||||
snprintf(timestring, 0x80, "%s[%s%02d/%02d/%d %02d:%02d:%02d%s]", CRESET, HBLK, timeinfo->tm_mon + 1, timeinfo->tm_mday, timeinfo->tm_year - 100, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, CRESET);
|
||||
if (verbose >= 2) {
|
||||
printf("%s| - %s%s <%s> " CRESET "%s" HBLU "%s" CRESET ":" BLU "%d" CRESET ":" BMAG "%s()" CRESET ": \n%s| ----> ", colour_bold, timestring, colour_bold, type, WHT, fname, lineno, fxname, colour_bold);
|
||||
} else {
|
||||
printf(" - %s %s<%s>%s: ", timestring, colour_bold, type, CRESET);
|
||||
}
|
||||
printf("%s", colour);
|
||||
ret = vprintf(format, args);
|
||||
va_end(args);
|
||||
|
||||
if (verbose < 2)
|
||||
printf(CRESET "\n");
|
||||
else {
|
||||
printf("\n%s-%s\n", colour, CRESET);
|
||||
if (verbose < 2)
|
||||
printf(CRESET "\n");
|
||||
else
|
||||
printf("\n%s-%s\n", colour, CRESET);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
pthread_mutex_unlock(&log_mutex);
|
||||
pthread_mutex_unlock(&log_mutex);
|
||||
return ret;
|
||||
}
|
||||
@@ -21,8 +21,10 @@ tui_screen_t tui_screen_main() {
|
||||
newtComponent exitButton = newtCompactButton(66, 18, "Exit");
|
||||
newtComponent welcome = newtLabel(1, 0, "Welcome to palera1n!");
|
||||
newtComponent deviceMsg = newtTextbox(1, 2, 40, 3, NEWT_FLAG_WRAP);
|
||||
newtTextboxSetText(deviceMsg, "Connect your iPhone, iPad or iPod Touch to begin.");
|
||||
set_tui_log(deviceMsg);
|
||||
LOG(LOG_INFO, "Connect your iPhone, iPad or iPod Touch to begin.");
|
||||
newtTextboxSetColors(deviceMsg, PI_LOG_COLOR, PI_LOG_COLOR);
|
||||
set_tui_log(deviceMsg);
|
||||
newtComponent form = newtForm(NULL, NULL, 0);
|
||||
newtFormAddComponents(form, optionsButton, startButton, exitButton, welcome,
|
||||
deviceMsg, NULL);
|
||||
@@ -39,6 +41,7 @@ tui_screen_t tui_screen_main() {
|
||||
} else if (buttonPressed == exitButton) {
|
||||
ret = EXIT_SCREEN;
|
||||
}
|
||||
set_tui_log(NULL);
|
||||
newtFormDestroy(form);
|
||||
return ret;
|
||||
}
|
||||
Reference in new issue
Block a user