Skip to content

Commit

Permalink
Merge pull request mobile-shell#1289 from zhaofengli/fish-wcwidth
Browse files Browse the repository at this point in the history
  • Loading branch information
jdrouhard committed Aug 20, 2023
2 parents 727784f + b3536cf commit 66d4653
Show file tree
Hide file tree
Showing 6 changed files with 1,563 additions and 3 deletions.
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

0 comments on commit 66d4653

Please sign in to comment.