Allow the omitted new line character to be more than one char

The code already allowed for variable width (multicell) *display* of the
newline omitted character, but there was no way to define it as being
more than one `wchar_t`.

This lets us use a string on console sessions (^J aka newline feed)
instead of an ambiguous character like `@` (used in some versions of
vim for ^M) or `~` (what we were using).
This commit is contained in:
Mahmoud Al-Qudsi
2019-01-30 15:42:59 -06:00
parent 753d489376
commit c50cce298d
3 changed files with 19 additions and 9 deletions

View File

@@ -70,7 +70,8 @@ static bool thread_asserts_cfg_for_testing = false;
wchar_t ellipsis_char;
const wchar_t *ellipsis_str = nullptr;
wchar_t omitted_newline_char;
const wchar_t *omitted_newline_str;
int omitted_newline_width;
wchar_t obfuscation_read_char;
bool g_profiling_active = false;
const wchar_t *program_name;
@@ -580,13 +581,21 @@ void fish_setlocale() {
if (is_windows_subsystem_for_linux()) {
// neither of \u23CE and \u25CF can be displayed in the default fonts on Windows, though
// they can be *encoded* just fine. Use alternative glyphs.
omitted_newline_char = can_be_encoded(L'\u00b6') ? L'\u00b6' : L'~'; // "pilcrow"
obfuscation_read_char = can_be_encoded(L'\u2022') ? L'\u2022' : L'*'; // "bullet"
omitted_newline_str = L"\u00b6"; // "pilcrow"
omitted_newline_width = 1;
obfuscation_read_char = L'\u2022'; // "bullet"
} else if (is_console_session()) {
omitted_newline_char = L'@';
omitted_newline_str = L"^J";
omitted_newline_width = 2;
obfuscation_read_char = L'*';
} else {
omitted_newline_char = can_be_encoded(L'\u23CE') ? L'\u23CE' : L'~'; // "return"
if (can_be_encoded(L'\u23CE')) {
omitted_newline_str = L"\u23CE";
omitted_newline_width = 1;
} else {
omitted_newline_str = L"^J";
omitted_newline_width = 2;
}
obfuscation_read_char = can_be_encoded(L'\u25CF') ? L'\u25CF' : L'#'; // "black circle"
}
}

View File

@@ -201,7 +201,8 @@ extern wchar_t ellipsis_char;
extern const wchar_t *ellipsis_str;
/// Character representing an omitted newline at the end of text.
extern wchar_t omitted_newline_char;
extern const wchar_t *omitted_newline_str;
extern int omitted_newline_width;
/// Character used for the silent mode of the read command
extern wchar_t obfuscation_read_char;

View File

@@ -1102,7 +1102,7 @@ void s_reset(screen_t *s, screen_reset_mode_t mode) {
// Don't need to check for fish_wcwidth errors; this is done when setting up
// omitted_newline_char in common.cpp.
int non_space_width = fish_wcwidth(omitted_newline_char);
int non_space_width = omitted_newline_width;
// We do `>` rather than `>=` because the code below might require one extra space.
if (screen_width > non_space_width) {
bool justgrey = true;
@@ -1129,7 +1129,7 @@ void s_reset(screen_t *s, screen_reset_mode_t mode) {
}
}
abandon_line_string.push_back(omitted_newline_char);
abandon_line_string.append(omitted_newline_str);
if (cur_term && exit_attribute_mode) {
abandon_line_string.append(
@@ -1141,7 +1141,7 @@ void s_reset(screen_t *s, screen_reset_mode_t mode) {
}
abandon_line_string.push_back(L'\r');
abandon_line_string.push_back(omitted_newline_char);
abandon_line_string.append(omitted_newline_str);
// Now we are certainly on a new line. But we may have dropped the omitted newline char on
// it. So append enough spaces to overwrite the omitted newline char, and then clear all the
// spaces from the new line.