mirror of
https://github.com/hashcat/hashcat.git
synced 2025-02-23 13:02:06 +00:00
Merge pull request #3230 from davidbolvansky/stdout-terminal
Do not use term colors if output is not terminal
This commit is contained in:
commit
8cf2783761
@ -46,6 +46,8 @@ int tty_break(void);
|
|||||||
int tty_getchar(void);
|
int tty_getchar(void);
|
||||||
int tty_fix(void);
|
int tty_fix(void);
|
||||||
|
|
||||||
|
bool is_stdout_terminal(void);
|
||||||
|
|
||||||
void compress_terminal_line_length (char *out_buf, const size_t keep_from_beginning, const size_t keep_from_end);
|
void compress_terminal_line_length (char *out_buf, const size_t keep_from_beginning, const size_t keep_from_end);
|
||||||
|
|
||||||
void hash_info (hashcat_ctx_t *hashcat_ctx);
|
void hash_info (hashcat_ctx_t *hashcat_ctx);
|
||||||
|
@ -30,6 +30,8 @@ int _dowildcard = -1;
|
|||||||
|
|
||||||
static void main_log_clear_line (MAYBE_UNUSED const size_t prev_len, MAYBE_UNUSED FILE *fp)
|
static void main_log_clear_line (MAYBE_UNUSED const size_t prev_len, MAYBE_UNUSED FILE *fp)
|
||||||
{
|
{
|
||||||
|
if (!is_stdout_terminal()) return;
|
||||||
|
|
||||||
#if defined (_WIN)
|
#if defined (_WIN)
|
||||||
|
|
||||||
fputc ('\r', fp);
|
fputc ('\r', fp);
|
||||||
@ -69,7 +71,7 @@ static void main_log (hashcat_ctx_t *hashcat_ctx, FILE *fp, const int loglevel)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// color stuff pre
|
// color stuff pre
|
||||||
|
if (is_stdout_terminal()) {
|
||||||
#if defined (_WIN)
|
#if defined (_WIN)
|
||||||
HANDLE hConsole = GetStdHandle (STD_OUTPUT_HANDLE);
|
HANDLE hConsole = GetStdHandle (STD_OUTPUT_HANDLE);
|
||||||
|
|
||||||
@ -100,13 +102,14 @@ static void main_log (hashcat_ctx_t *hashcat_ctx, FILE *fp, const int loglevel)
|
|||||||
case LOGLEVEL_ADVICE: fwrite ("\033[33m", 5, 1, fp); break;
|
case LOGLEVEL_ADVICE: fwrite ("\033[33m", 5, 1, fp); break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// finally, print
|
// finally, print
|
||||||
|
|
||||||
fwrite (msg_buf, msg_len, 1, fp);
|
fwrite (msg_buf, msg_len, 1, fp);
|
||||||
|
|
||||||
// color stuff post
|
// color stuff post
|
||||||
|
if (is_stdout_terminal()) {
|
||||||
#if defined (_WIN)
|
#if defined (_WIN)
|
||||||
switch (loglevel)
|
switch (loglevel)
|
||||||
{
|
{
|
||||||
@ -124,6 +127,7 @@ static void main_log (hashcat_ctx_t *hashcat_ctx, FILE *fp, const int loglevel)
|
|||||||
case LOGLEVEL_ADVICE: fwrite ("\033[0m", 4, 1, fp); break;
|
case LOGLEVEL_ADVICE: fwrite ("\033[0m", 4, 1, fp); break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// eventual newline
|
// eventual newline
|
||||||
|
|
||||||
|
@ -600,6 +600,15 @@ int tty_fix ()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool is_stdout_terminal(void)
|
||||||
|
{
|
||||||
|
#if defined(_WIN)
|
||||||
|
return _isatty(_fileno(stdout));
|
||||||
|
#else
|
||||||
|
return isatty(fileno(stdout));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void compress_terminal_line_length (char *out_buf, const size_t keep_from_beginning, const size_t keep_from_end)
|
void compress_terminal_line_length (char *out_buf, const size_t keep_from_beginning, const size_t keep_from_end)
|
||||||
{
|
{
|
||||||
const size_t target_len = TERMINAL_LINE_LENGTH - keep_from_beginning;
|
const size_t target_len = TERMINAL_LINE_LENGTH - keep_from_beginning;
|
||||||
|
Loading…
Reference in New Issue
Block a user