log interactive commands as well

This commit is contained in:
Philippe Teuwen 2019-09-09 21:30:25 +02:00
parent ba47ac36cb
commit e10085bfe8
4 changed files with 23 additions and 16 deletions

View file

@ -117,6 +117,7 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) {
// loops every time enter is pressed...
while (1) {
bool printprompt = false;
char *prompt = PROXPROMPT;
// If there is a script file
if (sf) {
@ -171,12 +172,12 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) {
rl_event_hook = check_comm;
if (session.pm3_present) {
if (conn.send_via_fpc_usart == false)
cmd = readline(PROXPROMPT_USB);
prompt = PROXPROMPT_USB;
else
cmd = readline(PROXPROMPT_FPC);
prompt = PROXPROMPT_FPC;
} else
cmd = readline(PROXPROMPT_OFFLINE);
prompt = PROXPROMPT_OFFLINE;
cmd = readline(prompt);
fflush(NULL);
}
}
@ -199,8 +200,10 @@ main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) {
cmd[strlen(cmd) - off] = '\0';
if (cmd[0] != '\0') {
if (printprompt)
PrintAndLogEx(NORMAL, PROXPROMPT"%s", cmd);
if (!printprompt)
g_printAndLog = PRINTANDLOG_LOG;
PrintAndLogEx(NORMAL, "%s%s", prompt, cmd);
g_printAndLog = PRINTANDLOG_PRINT | PRINTANDLOG_LOG;
int ret = CommandReceived(cmd);
@ -481,14 +484,14 @@ int main(int argc, char *argv[]) {
// short help
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
g_disableLogging = true;
g_printAndLog = PRINTANDLOG_PRINT;
show_help(true, exec_name);
return 0;
}
// dump help
if (strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--text") == 0) {
g_disableLogging = true;
g_printAndLog = PRINTANDLOG_PRINT;
show_help(false, exec_name);
dumpAllHelp(0);
return 0;
@ -496,7 +499,7 @@ int main(int argc, char *argv[]) {
// dump markup
if (strcmp(argv[i], "-m") == 0 || strcmp(argv[i], "--markdown") == 0) {
g_disableLogging = true;
g_printAndLog = PRINTANDLOG_PRINT;
dumpAllHelp(1);
return 0;
}

View file

@ -223,7 +223,7 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) {
// lock this section to avoid interlacing prints from different threads
pthread_mutex_lock(&print_lock);
if (!g_disableLogging && logging && !logfile) {
if ((g_printAndLog & PRINTANDLOG_LOG) && logging && !logfile) {
char *my_logfile_path = NULL;
char filename[40];
struct tm *timenow;
@ -269,9 +269,11 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) {
bool filter_ansi = !session.supports_colors;
memcpy_filter_ansi(buffer2, buffer, sizeof(buffer), filter_ansi);
fprintf(stream, "%s", buffer2);
fprintf(stream, " "); // cleaning prompt
fprintf(stream, "\n");
if (g_printAndLog & PRINTANDLOG_PRINT) {
fprintf(stream, "%s", buffer2);
fprintf(stream, " "); // cleaning prompt
fprintf(stream, "\n");
}
#ifdef RL_STATE_READCMD
// We are using GNU readline. libedit (OSX) doesn't support this flag.
@ -284,7 +286,7 @@ static void fPrintAndLog(FILE *stream, const char *fmt, ...) {
}
#endif
if (!g_disableLogging && logging && logfile) {
if ((g_printAndLog & PRINTANDLOG_LOG) && logging && logfile) {
if (filter_ansi) { // already done
fprintf(logfile, "%s\n", buffer2);
} else {

View file

@ -29,7 +29,7 @@
// global client debug variable
uint8_t g_debugMode = 0;
// global client disable logging variable
bool g_disableLogging = false;
uint8_t g_printAndLog = PRINTANDLOG_PRINT | PRINTANDLOG_LOG;
#ifdef _WIN32
#include <windows.h>

View file

@ -22,7 +22,9 @@
#endif
uint8_t g_debugMode;
bool g_disableLogging;
uint8_t g_printAndLog;
#define PRINTANDLOG_PRINT 1
#define PRINTANDLOG_LOG 2
int kbd_enter_pressed(void);
void AddLogLine(const char *fn, const char *data, const char *c);