mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-20 01:02:45 +08:00
Remove ellipsis and newlines from long lines
Fix for issue https://github.com/fish-shell/fish-shell/issues/300
This commit is contained in:
parent
86a978d9ee
commit
16f2ffc29d
|
@ -88,8 +88,6 @@ struct termios shell_modes;
|
||||||
static pthread_t main_thread_id = 0;
|
static pthread_t main_thread_id = 0;
|
||||||
static bool thread_assertions_configured_for_testing = false;
|
static bool thread_assertions_configured_for_testing = false;
|
||||||
|
|
||||||
wchar_t ellipsis_char;
|
|
||||||
|
|
||||||
char *profile=0;
|
char *profile=0;
|
||||||
|
|
||||||
const wchar_t *program_name;
|
const wchar_t *program_name;
|
||||||
|
@ -504,12 +502,6 @@ wcstring wsetlocale(int category, const wchar_t *locale)
|
||||||
char * res = setlocale(category,lang);
|
char * res = setlocale(category,lang);
|
||||||
free( lang );
|
free( lang );
|
||||||
|
|
||||||
/*
|
|
||||||
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'$';
|
|
||||||
|
|
||||||
if( !res )
|
if( !res )
|
||||||
return wcstring();
|
return wcstring();
|
||||||
else
|
else
|
||||||
|
@ -761,7 +753,6 @@ void write_screen( const wcstring &msg, wcstring &buff )
|
||||||
int line_width = 0;
|
int line_width = 0;
|
||||||
int tok_width = 0;
|
int tok_width = 0;
|
||||||
int screen_width = common_get_width();
|
int screen_width = common_get_width();
|
||||||
|
|
||||||
if( screen_width )
|
if( screen_width )
|
||||||
{
|
{
|
||||||
start = pos = msg.c_str();
|
start = pos = msg.c_str();
|
||||||
|
|
10
common.h
10
common.h
|
@ -89,12 +89,6 @@ void exit_without_destructors(int code) __attribute__ ((noreturn));
|
||||||
*/
|
*/
|
||||||
extern struct termios shell_modes;
|
extern struct termios shell_modes;
|
||||||
|
|
||||||
/**
|
|
||||||
The character to use where the text has been truncated. Is an
|
|
||||||
ellipsis on unicode system and a $ on other systems.
|
|
||||||
*/
|
|
||||||
extern wchar_t ellipsis_char;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The verbosity level of fish. If a call to debug has a severity
|
The verbosity level of fish. If a call to debug has a severity
|
||||||
level higher than \c debug_level, it will not be printed.
|
level higher than \c debug_level, it will not be printed.
|
||||||
|
@ -570,9 +564,7 @@ void error_reset();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This function behaves exactly like a wide character equivalent of
|
This function behaves exactly like a wide character equivalent of
|
||||||
the C function setlocale, except that it will also try to detect if
|
the C function setlocale.
|
||||||
the user is using a Unicode character set, and if so, use the
|
|
||||||
unicode ellipsis character as ellipsis, instead of '$'.
|
|
||||||
*/
|
*/
|
||||||
wcstring wsetlocale( int category, const wchar_t *locale );
|
wcstring wsetlocale( int category, const wchar_t *locale );
|
||||||
|
|
||||||
|
|
|
@ -377,8 +377,6 @@ static int print_max( const wchar_t *str, int max, int has_more )
|
||||||
break;
|
break;
|
||||||
if( ( written + wcwidth(str[i]) == max) && (has_more || str[i+1]) )
|
if( ( written + wcwidth(str[i]) == max) && (has_more || str[i+1]) )
|
||||||
{
|
{
|
||||||
writech( ellipsis_char );
|
|
||||||
written += wcwidth(ellipsis_char );
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
39
output.cpp
39
output.cpp
|
@ -489,43 +489,6 @@ void writestr( const wchar_t *str )
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void writestr_ellipsis( const wchar_t *str, int max_width )
|
|
||||||
{
|
|
||||||
int written=0;
|
|
||||||
int tot;
|
|
||||||
|
|
||||||
CHECK( str, );
|
|
||||||
|
|
||||||
tot = my_wcswidth(str);
|
|
||||||
|
|
||||||
if( tot <= max_width )
|
|
||||||
{
|
|
||||||
writestr( str );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
while( *str != 0 )
|
|
||||||
{
|
|
||||||
int w = fish_wcwidth( *str );
|
|
||||||
if( written+w+fish_wcwidth( ellipsis_char )>max_width )
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
written+=w;
|
|
||||||
writech( *(str++) );
|
|
||||||
}
|
|
||||||
|
|
||||||
written += fish_wcwidth( ellipsis_char );
|
|
||||||
writech( ellipsis_char );
|
|
||||||
|
|
||||||
while( written < max_width )
|
|
||||||
{
|
|
||||||
written++;
|
|
||||||
writestr( L" " );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int write_escaped_str( const wchar_t *str, int max_len )
|
int write_escaped_str( const wchar_t *str, int max_len )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -546,8 +509,6 @@ int write_escaped_str( const wchar_t *str, int max_len )
|
||||||
writech( out[i] );
|
writech( out[i] );
|
||||||
written += fish_wcwidth( out[i] );
|
written += fish_wcwidth( out[i] );
|
||||||
}
|
}
|
||||||
writech( ellipsis_char );
|
|
||||||
written += fish_wcwidth( ellipsis_char );
|
|
||||||
|
|
||||||
for( i=written; i<max_len; i++ )
|
for( i=written; i<max_len; i++ )
|
||||||
{
|
{
|
||||||
|
|
6
output.h
6
output.h
|
@ -116,12 +116,6 @@ int writech( wint_t ch );
|
||||||
*/
|
*/
|
||||||
void writestr( const wchar_t *str );
|
void writestr( const wchar_t *str );
|
||||||
|
|
||||||
/**
|
|
||||||
Write a wide character string to FD 1. If the string is wider than
|
|
||||||
the specified maximum, truncate and ellipsize it.
|
|
||||||
*/
|
|
||||||
void writestr_ellipsis( const wchar_t *str, int max_width );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Escape and write a string to fd 1
|
Escape and write a string to fd 1
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -660,7 +660,6 @@ static void exec_prompt()
|
||||||
|
|
||||||
for( i = 0; i < prompt_list.size(); i++ )
|
for( i = 0; i < prompt_list.size(); i++ )
|
||||||
{
|
{
|
||||||
if (i > 0) data->prompt_buff += L'\n';
|
|
||||||
data->prompt_buff += prompt_list.at(i);
|
data->prompt_buff += prompt_list.at(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1522,7 +1521,6 @@ static bool handle_completions( const std::vector<completion_t> &comp )
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// append just the end of the string
|
// append just the end of the string
|
||||||
prefix = wcstring(&ellipsis_char, 1);
|
|
||||||
prefix.append(data->command_line, prefix_start + len - PREFIX_MAX_LEN, wcstring::npos);
|
prefix.append(data->command_line, prefix_start + len - PREFIX_MAX_LEN, wcstring::npos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
25
screen.cpp
25
screen.cpp
|
@ -445,29 +445,22 @@ static void s_desired_append_char( screen_t *s,
|
||||||
{
|
{
|
||||||
int screen_width = common_get_width();
|
int screen_width = common_get_width();
|
||||||
int cw = fish_wcwidth(b);
|
int cw = fish_wcwidth(b);
|
||||||
int ew = fish_wcwidth( ellipsis_char );
|
|
||||||
|
|
||||||
s->desired.create_line(line_no);
|
s->desired.create_line(line_no);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Check if we are at the end of the line. If so, print an
|
Check if we are at the end of the line. If so, continue on the next line.
|
||||||
ellipsis character and continue on the next line.
|
|
||||||
*/
|
*/
|
||||||
if( s->desired.cursor.x + cw + ew > screen_width )
|
if( (s->desired.cursor.x + cw) > screen_width )
|
||||||
{
|
{
|
||||||
s->desired.line(line_no).append(ellipsis_char, HIGHLIGHT_COMMENT);
|
|
||||||
|
|
||||||
line_no = (int)s->desired.line_count();
|
line_no = (int)s->desired.line_count();
|
||||||
s->desired.add_line();
|
s->desired.add_line();
|
||||||
s->desired.cursor.y++;
|
s->desired.cursor.y++;
|
||||||
s->desired.cursor.x=0;
|
s->desired.cursor.x=0;
|
||||||
if (prompt_width > ew) {
|
for( size_t i=0; i < prompt_width; i++ )
|
||||||
for( size_t i=0; i < (prompt_width-ew); i++ )
|
|
||||||
{
|
{
|
||||||
s_desired_append_char( s, L' ', 0, indent, prompt_width );
|
s_desired_append_char( s, L' ', 0, indent, prompt_width );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
s_desired_append_char( s, ellipsis_char, HIGHLIGHT_COMMENT, indent, prompt_width );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
line_t &line = s->desired.line(line_no);
|
line_t &line = s->desired.line(line_no);
|
||||||
|
@ -871,7 +864,6 @@ void s_write( screen_t *s,
|
||||||
assert(screen_width - prompt_width >= 1);
|
assert(screen_width - prompt_width >= 1);
|
||||||
max_line_width = screen_width - prompt_width - 1;
|
max_line_width = screen_width - prompt_width - 1;
|
||||||
truncated_autosuggestion_line = wcstring(commandline, 0, last_char_that_fits);
|
truncated_autosuggestion_line = wcstring(commandline, 0, last_char_that_fits);
|
||||||
truncated_autosuggestion_line.push_back(ellipsis_char);
|
|
||||||
commandline = truncated_autosuggestion_line.c_str();
|
commandline = truncated_autosuggestion_line.c_str();
|
||||||
}
|
}
|
||||||
for( size_t i=0; i<prompt_width; i++ )
|
for( size_t i=0; i<prompt_width; i++ )
|
||||||
|
@ -906,17 +898,6 @@ void s_write( screen_t *s,
|
||||||
|
|
||||||
s_desired_append_char( s, commandline[i], col, indent[i], prompt_width );
|
s_desired_append_char( s, commandline[i], col, indent[i], prompt_width );
|
||||||
|
|
||||||
if( i== cursor_pos && s->desired.cursor.y != cursor_arr.y && commandline[i] != L'\n' )
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
Ugh. We are placed exactly at the wrapping point of a
|
|
||||||
wrapped line, move cursor to the line below so the
|
|
||||||
cursor won't be on the ellipsis which looks
|
|
||||||
unintuitive.
|
|
||||||
*/
|
|
||||||
cursor_arr.x = s->desired.cursor.x - fish_wcwidth(commandline[i]);
|
|
||||||
cursor_arr.y = s->desired.cursor.y;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if( i == cursor_pos )
|
if( i == cursor_pos )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user