Bring back ellipsis

This commit is contained in:
ridiculousfish 2012-11-05 00:05:42 -08:00
parent 5ba1261285
commit 21e83a881e
7 changed files with 78 additions and 1 deletions

View file

@ -88,6 +88,8 @@ 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;
@ -502,6 +504,12 @@ 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
@ -753,6 +761,7 @@ 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();

View file

@ -89,6 +89,12 @@ 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.
@ -564,7 +570,9 @@ 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. the C function setlocale, except that it will also try to detect if
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 );

View file

@ -377,6 +377,8 @@ 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;
} }

View file

@ -489,6 +489,43 @@ 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 )
{ {
@ -509,6 +546,8 @@ 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++ )
{ {

View file

@ -116,6 +116,12 @@ 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
*/ */

View file

@ -1532,6 +1532,7 @@ 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);
} }

View file

@ -968,6 +968,7 @@ 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++ )
@ -1002,6 +1003,17 @@ 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 )
{ {