src/ui-event.c
void keypress_to_text(char *buf, size_t len, const struct keypress *src,
	bool expand_backslash)
{
	size_t cur = 0;
	size_t end = 0;

	while (src[cur].type == EVT_KBRD) {
		keycode_t i = src[cur].code;
		int mods = src[cur].mods;
		const char *desc = keycode_find_desc(i);

		/* un-ktrl control characters if they don't have a description */
		/* this is so that Tab (^I) doesn't get turned into ^I but gets
		 * displayed as [Tab] */
		if (i < 0x20 && !desc) {
			mods |= KC_MOD_CONTROL;
			i = UN_KTRL(i);
		}

		if (mods) {
			if (mods & KC_MOD_CONTROL && !(mods & ~KC_MOD_CONTROL)) {
				strnfcat(buf, len, &end, "^");			
			} else {
				strnfcat(buf, len, &end, "{");
				if (mods & KC_MOD_CONTROL) strnfcat(buf, len, &end, "^");
				if (mods & KC_MOD_SHIFT) strnfcat(buf, len, &end, "S");
				if (mods & KC_MOD_ALT) strnfcat(buf, len, &end, "A");
				if (mods & KC_MOD_META) strnfcat(buf, len, &end, "M");
				if (mods & KC_MOD_KEYPAD) strnfcat(buf, len, &end, "K");
				strnfcat(buf, len, &end, "}");
			}
		}

		if (desc) {
			strnfcat(buf, len, &end, "[%s]", desc);
		} else {
			switch (i) {
				case '\a': strnfcat(buf, len, &end, "\a"); break;
				case '\\': {
					if (expand_backslash)
						strnfcat(buf, len, &end, "\\\\");
					else
						strnfcat(buf, len, &end, "\\");
					break;
				}
				case '^': strnfcat(buf, len, &end, "\\^"); break;
				case '[': strnfcat(buf, len, &end, "\\["); break;
				default: {
					if (i < 127)
						strnfcat(buf, len, &end, "%c", i);
					else
						strnfcat(buf, len, &end, "\\x%02x", (int)i);
					break;
				}
			}
		}

		cur++;
	}

	/* Terminate */
	buf[end] = '\0';
}
/**
 * Convert a string of keypresses into their textual equivalent.
 */
Convert a string of keypresses into their textual equivalent.
Convert a string of keypresses into their textual equivalent .
void keypress_to_text(char *buf, size_t len, const struct keypress *src,
	bool expand_backslash)
{
	size_t cur = 0;
	size_t end = 0;
	while (src[cur].type == EVT_KBRD) {
		keycode_t i = src[cur].code;
		int mods = src[cur].mods;
		const char *desc = keycode_find_desc(i);
		if (i < 0x20 && !desc) {
			mods |= KC_MOD_CONTROL;
			i = UN_KTRL(i);
		}
		if (mods) {
			if (mods & KC_MOD_CONTROL && !(mods & ~KC_MOD_CONTROL)) {
				strnfcat(buf, len, &end, "^");			
			} else {
				strnfcat(buf, len, &end, "{");
				if (mods & KC_MOD_CONTROL) strnfcat(buf, len, &end, "^");
				if (mods & KC_MOD_SHIFT) strnfcat(buf, len, &end, "S");
				if (mods & KC_MOD_ALT) strnfcat(buf, len, &end, "A");
				if (mods & KC_MOD_META) strnfcat(buf, len, &end, "M");
				if (mods & KC_MOD_KEYPAD) strnfcat(buf, len, &end, "K");
				strnfcat(buf, len, &end, "}");
			}
		}
		if (desc) {
			strnfcat(buf, len, &end, "[%s]", desc);
		} else {
			switch (i) {
				case '\a': strnfcat(buf, len, &end, "\a"); break;
				case '\\': {
					if (expand_backslash)
						strnfcat(buf, len, &end, "\\\\");
					else
						strnfcat(buf, len, &end, "\\");
					break;
				}
				case '^': strnfcat(buf, len, &end, "\\^"); break;
				case '[': strnfcat(buf, len, &end, "\\["); break;
				default: {
					if (i < 127)
						strnfcat(buf, len, &end, "%c", i);
					else
						strnfcat(buf, len, &end, "\\x%02x", (int)i);
					break;
				}
			}
		}
		cur++;
	}
	buf[end] = '\0';
}
void keypress_to_text ( char * buf , size_t len , const struct keypress * src , bool expand_backslash ) { size_t cur = 0 ; size_t end = 0 ; while ( src [ cur ] . type == EVT_KBRD ) { keycode_t i = src [ cur ] . code ; int mods = src [ cur ] . mods ; const char * desc = keycode_find_desc ( i ) ; if ( i < 0x20 && ! desc ) { mods |= KC_MOD_CONTROL ; i = UN_KTRL ( i ) ; } if ( mods ) { if ( mods & KC_MOD_CONTROL && ! ( mods & ~ KC_MOD_CONTROL ) ) { strnfcat ( buf , len , & end , " " ) ; } else { strnfcat ( buf , len , & end , " " ) ; if ( mods & KC_MOD_CONTROL ) strnfcat ( buf , len , & end , " " ) ; if ( mods & KC_MOD_SHIFT ) strnfcat ( buf , len , & end , " " ) ; if ( mods & KC_MOD_ALT ) strnfcat ( buf , len , & end , " " ) ; if ( mods & KC_MOD_META ) strnfcat ( buf , len , & end , " " ) ; if ( mods & KC_MOD_KEYPAD ) strnfcat ( buf , len , & end , " " ) ; strnfcat ( buf , len , & end , " " ) ; } } if ( desc ) { strnfcat ( buf , len , & end , " " , desc ) ; } else { switch ( i ) { case ' \a ' : strnfcat ( buf , len , & end , " \a " ) ; break ; case ' \\ ' : { if ( expand_backslash ) strnfcat ( buf , len , & end , " \\ \\ " ) ; else strnfcat ( buf , len , & end , " \\ " ) ; break ; } case ' ' : strnfcat ( buf , len , & end , " \\ " ) ; break ; case ' ' : strnfcat ( buf , len , & end , " \\ " ) ; break ; default : { if ( i < 127 ) strnfcat ( buf , len , & end , " " , i ) ; else strnfcat ( buf , len , & end , " \\ " , ( int ) i ) ; break ; } } } cur ++ ; } buf [ end ] = ' \0 ' ; }
Convert a string of keypresses into their textual equivalent.
Convert a string of keypresses into their textual equivalent .
/* un-ktrl control characters if they don't have a description */ /* this is so that Tab (^I) doesn't get turned into ^I but gets
		 * displayed as [Tab] */ /* Terminate */