First attempt at appending a "missing new line" character

https://github.com/fish-shell/fish-shell/issues/397
This commit is contained in:
ridiculousfish 2012-12-01 15:44:09 -08:00
parent 17e7860700
commit a122d2eb50
3 changed files with 38 additions and 8 deletions

View file

@ -89,6 +89,7 @@ static pthread_t main_thread_id = 0;
static bool thread_assertions_configured_for_testing = false;
wchar_t ellipsis_char;
wchar_t omitted_newline_char;
char *profile=0;
@ -521,8 +522,13 @@ wcstring wsetlocale(int category, const wchar_t *locale)
Use ellipsis if on known unicode system, otherwise use $
*/
char *ctype = setlocale(LC_CTYPE, NULL);
ellipsis_char = (strstr(ctype, ".UTF")||strstr(ctype, ".utf"))?L'\x2026':L'$';
bool unicode = (strstr(ctype, ".UTF") || strstr(ctype, ".utf"));
ellipsis_char = unicode ? L'\x2026' : L'$';
// U+23CE is the "return" character
omitted_newline_char = unicode ? L'\x23CE' : L'~';
if (!res)
return wcstring();
else

View file

@ -96,6 +96,9 @@ extern struct termios shell_modes;
*/
extern wchar_t ellipsis_char;
/* Character representing an omitted newline at the end of text */
extern wchar_t omitted_newline_char;
/**
The verbosity level of fish. If a call to debug has a severity
level higher than \c debug_level, it will not be printed.

View file

@ -456,7 +456,7 @@ static void s_check_status(screen_t *s)
*/
int prev_line = s->actual.cursor.y;
write_loop(1, "\r", 1);
write_loop(STDOUT_FILENO, "\r", 1);
s_reset(s, screen_reset_current_line_and_prompt);
s->actual.cursor.y = prev_line;
}
@ -762,7 +762,7 @@ static bool test_stuff(screen_t *scr)
if (! output.empty())
{
write_loop(1, &output.at(0), output.size());
write_loop(STDOUT_FILENO, &output.at(0), output.size());
output.clear();
}
@ -1208,9 +1208,9 @@ void s_write(screen_t *s,
const std::string prompt_narrow = wcs2string(left_prompt);
const std::string command_line_narrow = wcs2string(explicit_command_line);
write_loop(1, "\r", 1);
write_loop(1, prompt_narrow.c_str(), prompt_narrow.size());
write_loop(1, command_line_narrow.c_str(), command_line_narrow.size());
write_loop(STDOUT_FILENO, "\r", 1);
write_loop(STDOUT_FILENO, prompt_narrow.c_str(), prompt_narrow.size());
write_loop(STDOUT_FILENO, command_line_narrow.c_str(), command_line_narrow.size());
return;
}
@ -1330,10 +1330,31 @@ void s_reset(screen_t *s, screen_reset_mode_t mode)
s->need_clear_lines = true;
s->need_clear_screen = s->need_clear_screen || clear_to_eos;
if (abandon_line)
{
/* Do the PROMPT_SP hack */
int screen_width = common_get_width();
wcstring abandon_line_string;
abandon_line_string.reserve(screen_width);
int non_space_width = wcwidth(omitted_newline_char);
if (screen_width > non_space_width)
{
abandon_line_string.append(L"\x1b[7m"); //invert text ANSI escape sequence
abandon_line_string.push_back(omitted_newline_char);
abandon_line_string.append(L"\x1b[0m"); //normal text ANSI escape sequence
abandon_line_string.append(screen_width - non_space_width - 1, L' ');
}
abandon_line_string.push_back(L'\r');
const std::string narrow_abandon_line_string = wcs2string(abandon_line_string);
write_loop(STDOUT_FILENO, narrow_abandon_line_string.c_str(), narrow_abandon_line_string.size());
s->actual.cursor.x = 0;
}
if (! abandon_line)
{
/* This should prevent resetting the cursor position during the next repaint. */
write_loop(1, "\r", 1);
write_loop(STDOUT_FILENO, "\r", 1);
s->actual.cursor.x = 0;
}