cr: replace non-ascii characters with a configurable character #211

Although sngrep has Unicode support for ncurses, the SIP message payload
is printed character by character using mvwaddch

This commit adds a new configurable setting cr.nonascii that defaults to .
to replace not printable characters.
This commit is contained in:
Kaian 2018-04-05 12:13:43 +02:00
parent 61f5dbd421
commit 731b15eb15
3 changed files with 8 additions and 1 deletions

View File

@ -349,6 +349,7 @@ draw_message_pos(WINDOW *win, sip_msg_t *msg, int starting)
int height, width, line, column, i;
const char *cur_line, *payload, *method = NULL;
int syntax = setting_enabled(SETTING_SYNTAX);
const char *nonascii = setting_get_value(SETTING_CR_NON_ASCII);
// Default text format
int attrs = A_NORMAL | COLOR_PAIR(CP_DEFAULT);
@ -451,7 +452,11 @@ draw_message_pos(WINDOW *win, sip_msg_t *msg, int starting)
}
// Put next character in position
mvwaddch(win, line, column++, payload[i]);
if (isascii(payload[i])) {
mvwaddch(win, line, column++, payload[i]);
} else {
mvwaddch(win, line, column++, *nonascii);
}
// Stop if we've reached the bottom of the window
if (line == height)

View File

@ -74,6 +74,7 @@ setting_t settings[SETTING_COUNT] = {
{ SETTING_CF_ONLYMEDIA, "cf.onlymedia", SETTING_FMT_ENUM, SETTING_OFF, SETTING_ENUM_ONOFF },
{ SETTING_CF_DELTA, "cf.deltatime", SETTING_FMT_ENUM, SETTING_ON, SETTING_ENUM_ONOFF },
{ SETTING_CR_SCROLLSTEP, "cr.scrollstep", SETTING_FMT_NUMBER, "10", NULL },
{ SETTING_CR_NON_ASCII, "cr.nonascii", SETTING_FMT_STRING, ".", NULL },
{ SETTING_FILTER_PAYLOAD, "filter.payload", SETTING_FMT_STRING, "", NULL },
{ SETTING_FILTER_METHODS, "filter.methods", SETTING_FMT_STRING, "", NULL },
#ifdef USE_EEP

View File

@ -110,6 +110,7 @@ enum setting_id {
SETTING_CF_ONLYMEDIA,
SETTING_CF_DELTA,
SETTING_CR_SCROLLSTEP,
SETTING_CR_NON_ASCII,
SETTING_FILTER_PAYLOAD,
SETTING_FILTER_METHODS,
#ifdef USE_EEP