Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use wcwidth implementation from fish-shell #1289

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/util/widechar_width.h
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* text=true
src/util/widechar_width.h linguist-vendored=true
5 changes: 3 additions & 2 deletions src/frontend/terminaloverlay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <typeinfo>

#include "src/frontend/terminaloverlay.h"
#include "src/util/char_utils.h"

using namespace Overlay;

Expand Down Expand Up @@ -257,7 +258,7 @@ void NotificationEngine::apply( Framebuffer& fb ) const
}

wchar_t ch = *i;
int chwidth = ch == L'\0' ? -1 : wcwidth( ch );
int chwidth = ch == L'\0' ? -1 : mosh_wcwidth( ch );
Cell* this_cell = 0;

switch ( chwidth ) {
Expand Down Expand Up @@ -709,7 +710,7 @@ void PredictionEngine::new_user_byte( char the_byte, const Framebuffer& fb )
}
}
}
} else if ( ( ch < 0x20 ) || ( wcwidth( ch ) != 1 ) ) {
} else if ( ( ch < 0x20 ) || ( mosh_wcwidth( ch ) != 1 ) ) {
/* unknown print */
become_tentative();
// fprintf( stderr, "Unknown print 0x%x\n", ch );
Expand Down
3 changes: 2 additions & 1 deletion src/terminal/terminal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <unistd.h>

#include "src/terminal/terminal.h"
#include "src/util/char_utils.h"

using namespace Terminal;

Expand Down Expand Up @@ -65,7 +66,7 @@ void Emulator::print( const Parser::Print* act )
* Check for printing ISO 8859-1 first, it's a cheap way to detect
* some common narrow characters.
*/
const int chwidth = ch == L'\0' ? -1 : ( Cell::isprint_iso8859_1( ch ) ? 1 : wcwidth( ch ) );
const int chwidth = ch == L'\0' ? -1 : ( Cell::isprint_iso8859_1( ch ) ? 1 : mosh_wcwidth( ch ) );

Cell* this_cell = fb.get_mutable_cell();

Expand Down
34 changes: 34 additions & 0 deletions src/util/char_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef CHAR_UTILS_HPP
#define CHAR_UTILS_HPP

#include "widechar_width.h"

static int mosh_wcwidth( uint32_t c )
{
int width = widechar_wcwidth( c );
if ( width >= 0 ) {
return width;
}

/* https://github.com/ridiculousfish/widecharwidth/tree/master#c-usage */
switch ( width ) {
case widechar_nonprint:
return -1;
case widechar_combining:
return 0;
case widechar_ambiguous:
return 1;
case widechar_private_use:
return 1;
case widechar_unassigned:
return -1;
case widechar_non_character:
return -1;
case widechar_widened_in_9:
return 2;
default:
return -1;
}
}

#endif
Loading