Unify ellipsis_str[ing] with common variable set once

This commit is contained in:
Mahmoud Al-Qudsi 2018-03-09 14:40:35 -06:00
parent 3314135cc9
commit 1fbf810946
5 changed files with 16 additions and 17 deletions

View file

@ -51,6 +51,7 @@ static pthread_t main_thread_id = 0;
static bool thread_asserts_cfg_for_testing = false; static bool thread_asserts_cfg_for_testing = false;
wchar_t ellipsis_char; wchar_t ellipsis_char;
const wchar_t *ellipsis_str = nullptr;
wchar_t omitted_newline_char; wchar_t omitted_newline_char;
wchar_t obfuscation_read_char; wchar_t obfuscation_read_char;
bool g_profiling_active = false; bool g_profiling_active = false;
@ -507,7 +508,14 @@ void fish_setlocale() {
// true/false value since the code points are in the BMP but we're going to be paranoid. This // true/false value since the code points are in the BMP but we're going to be paranoid. This
// is also technically wrong if we're not in a Unicode locale but we expect (or hope) // is also technically wrong if we're not in a Unicode locale but we expect (or hope)
// can_be_encoded() will return false in that case. // can_be_encoded() will return false in that case.
ellipsis_char = can_be_encoded(L'\u2026') ? L'\u2026' : L'$'; // "horizontal ellipsis" if (can_be_encoded(L'\u2026')) {
ellipsis_char = L'\u2026';
ellipsis_str = L"\u2026";
}
else {
ellipsis_char = L'$'; // "horizontal ellipsis"
ellipsis_str = L"...";
}
omitted_newline_char = can_be_encoded(L'\u23CE') ? L'\u23CE' : L'~'; // "return" omitted_newline_char = can_be_encoded(L'\u23CE') ? L'\u23CE' : L'~'; // "return"
obfuscation_read_char = can_be_encoded(L'\u25CF') ? L'\u25CF' : L'#'; // "black circle" obfuscation_read_char = can_be_encoded(L'\u25CF') ? L'\u25CF' : L'#'; // "black circle"
} }

View file

@ -183,6 +183,8 @@ extern struct termios shell_modes;
/// The character to use where the text has been truncated. Is an ellipsis on unicode system and a $ /// The character to use where the text has been truncated. Is an ellipsis on unicode system and a $
/// on other systems. /// on other systems.
extern wchar_t ellipsis_char; extern wchar_t ellipsis_char;
/// The character or string to use where text has been truncated (ellipsis if possible, otherwise ...)
extern const wchar_t *ellipsis_str;
/// Character representing an omitted newline at the end of text. /// Character representing an omitted newline at the end of text.
extern wchar_t omitted_newline_char; extern wchar_t omitted_newline_char;
@ -766,7 +768,7 @@ void assert_is_not_forked_child(const char *who);
/// Detect if we are Windows Subsystem for Linux by inspecting /proc/sys/kernel/osrelease /// Detect if we are Windows Subsystem for Linux by inspecting /proc/sys/kernel/osrelease
/// and checking if "Microsoft" is in the first line. /// and checking if "Microsoft" is in the first line.
/// See https://github.com/Microsoft/WSL/issues/423 and Microsoft/WSL#2997 /// See https://github.com/Microsoft/WSL/issues/423 and Microsoft/WSL#2997
constexpr bool is_windows_subsystem_for_linux() { constexpr bool is_windows_subsystem_for_linux() {
#ifdef WSL #ifdef WSL
return true; return true;

View file

@ -481,16 +481,13 @@ bool pager_t::completion_try_print(size_t cols, const wcstring &prefix, const co
assert(stop_row - start_row <= term_height); assert(stop_row - start_row <= term_height);
completion_print(cols, width_by_column, start_row, stop_row, prefix, lst, rendering); completion_print(cols, width_by_column, start_row, stop_row, prefix, lst, rendering);
// Ellipsis helper string. Either empty or containing the ellipsis char.
const wchar_t ellipsis_string[] = {ellipsis_char == L'\x2026' ? L'\x2026' : L'\0', L'\0'};
// Add the progress line. It's a "more to disclose" line if necessary, or a row listing if // Add the progress line. It's a "more to disclose" line if necessary, or a row listing if
// it's scrollable; otherwise ignore it. // it's scrollable; otherwise ignore it.
// We should never have one row remaining to disclose (else we would have just disclosed it) // We should never have one row remaining to disclose (else we would have just disclosed it)
wcstring progress_text; wcstring progress_text;
assert(rendering->remaining_to_disclose != 1); assert(rendering->remaining_to_disclose != 1);
if (rendering->remaining_to_disclose > 1) { if (rendering->remaining_to_disclose > 1) {
progress_text = format_string(_(L"%lsand %lu more rows"), ellipsis_string, progress_text = format_string(_(L"%lsand %lu more rows"), ellipsis_str,
(unsigned long)rendering->remaining_to_disclose); (unsigned long)rendering->remaining_to_disclose);
} else if (start_row > 0 || stop_row < row_count) { } else if (start_row > 0 || stop_row < row_count) {
// We have a scrollable interface. The +1 here is because we are zero indexed, but want // We have a scrollable interface. The +1 here is because we are zero indexed, but want

View file

@ -664,13 +664,10 @@ parse_execution_result_t parse_execution_context_t::handle_command_not_found(
if (!args.empty()) { if (!args.empty()) {
const wcstring argument = get_source(args.at(0)); const wcstring argument = get_source(args.at(0));
wcstring ellipsis_str = wcstring(1, ellipsis_char);
if (ellipsis_str == L"$") ellipsis_str = L"...";
// Looks like a command. // Looks like a command.
this->report_error(statement, ERROR_BAD_EQUALS_IN_COMMAND5, argument.c_str(), this->report_error(statement, ERROR_BAD_EQUALS_IN_COMMAND5, argument.c_str(),
name_str.c_str(), val_str.c_str(), argument.c_str(), name_str.c_str(), val_str.c_str(), argument.c_str(),
ellipsis_str.c_str()); ellipsis_str);
} else { } else {
wcstring assigned_val = reconstruct_orig_str(val_str); wcstring assigned_val = reconstruct_orig_str(val_str);
this->report_error(statement, ERROR_BAD_COMMAND_ASSIGN_ERR_MSG, name_str.c_str(), this->report_error(statement, ERROR_BAD_COMMAND_ASSIGN_ERR_MSG, name_str.c_str(),

View file

@ -452,8 +452,7 @@ static wcstring truncate_command(const wcstring &cmd) {
} }
// Truncation required. // Truncation required.
const bool ellipsis_is_unicode = (ellipsis_char == L'\x2026'); const size_t ellipsis_length = wcslen(ellipsis_str); //no need for wcwidth
const size_t ellipsis_length = ellipsis_is_unicode ? 1 : 3;
size_t trunc_length = max_len - ellipsis_length; size_t trunc_length = max_len - ellipsis_length;
// Eat trailing whitespace. // Eat trailing whitespace.
while (trunc_length > 0 && iswspace(cmd.at(trunc_length - 1))) { while (trunc_length > 0 && iswspace(cmd.at(trunc_length - 1))) {
@ -461,11 +460,7 @@ static wcstring truncate_command(const wcstring &cmd) {
} }
wcstring result = wcstring(cmd, 0, trunc_length); wcstring result = wcstring(cmd, 0, trunc_length);
// Append ellipsis. // Append ellipsis.
if (ellipsis_is_unicode) { result.append(ellipsis_str);
result.push_back(ellipsis_char);
} else {
result.append(L"...");
}
return result; return result;
} }