Skip to content

Commit

Permalink
code reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
genivia-inc committed Apr 2, 2024
1 parent 3d0d60b commit 668a041
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Output {

protected:

static constexpr size_t SIZE = 32768; // size of each buffer in the buffers container
static constexpr size_t SIZE = 32768; // size of each output buffer in the buffers container
static constexpr size_t STOP = UNDEFINED_SIZE; // if last == STOP, cancel output
static constexpr int FLUSH = 1; // mode bit: flush each line of output
static constexpr int HOLD = 2; // mode bit: hold output
Expand Down Expand Up @@ -631,7 +631,7 @@ class Output {
{
if (!eof)
{
// if multi-threaded and lock is not owned already, then lock on master's mutex
// if multi-threaded and lock is not already owned, then lock on master's mutex
acquire();

// flush the buffers container to the designated output file, pipe, or stream
Expand Down
10 changes: 5 additions & 5 deletions src/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ void Query::redraw()
Screen::put( 2, 0, "\033[7mEsc\033[m go back / exit");
Screen::put( 3, 0, "\033[7mTab\033[m cd dir / select file");
Screen::put( 4, 0, "\033[7mS-Tab\033[m cd .. / deselect file");
Screen::put( 5, 0, "\033[7mEnter\033[m line selection mode");
Screen::put( 5, 0, "\033[7mEnter\033[m output selection mode");
Screen::put( 6, 0, "");
Screen::put( 7, 0, "\033[7mUp\033[m \033[7mDown\033[m scroll");
Screen::put( 8, 0, "\033[7mPgUp\033[m \033[7mPgDn\033[m scroll page");
Expand Down Expand Up @@ -1417,10 +1417,6 @@ void Query::query_ui()
}
else
{
#ifdef __APPLE__
Screen::put(color_qe);
Screen::put(0, 0, "MacOS Terminal Preferences/Profiles/Keyboard: enable \"Use Option as Meta key\"");
#endif
Screen::alert();
}
}
Expand Down Expand Up @@ -3125,6 +3121,10 @@ bool Query::help()
}
else
{
#ifdef __APPLE__
Screen::put(color_qe);
Screen::put(0, 0, "MacOS Terminal->Preferences->Profiles->Keyboard: enable \"Use Option as Meta key\"");
#endif
Screen::alert();
}
}
Expand Down
24 changes: 14 additions & 10 deletions src/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,23 @@ void Screen::cleanup()
// return character display width, 0 (non-spacing or invalid character), 1 (single width) or 2 (double width)
int Screen::wchar_width(uint32_t wc)
{
/* based on https://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c with full table
// ignore invisible characters, such as invalid UTF-8
if (wc == 0)
return 0;

// control characters are double width to display them e.g. as \t or ^I
if (wc < 0x20 || wc == 0x7f)
return 2;

/* Based on https://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c with full table
generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c"
from https://www.unicode.org/Public/UCD/latest/ucd/EastAsianWidth.txt
this is a compressed table of combining character ranges, stored as
range.first << 8 | (range.last - range.first) */
range.first << 8 | (range.last - range.first)
We don't use wcwidth() because it is broken on some systems, e.g. MacOS
wcwidth(0x1f600) returns -1 for the emoticon U+1F600
*/
static const uint32_t combining[] = {
0x3006f, 0x48303, 0x48801, 0x5912c, 0x5bf00, 0x5c101, 0x5c401, 0x5c700,
0x60003, 0x61005, 0x64b13, 0x67000, 0x6d60e, 0x6e701, 0x6ea03, 0x70f00,
Expand All @@ -375,14 +387,6 @@ int Screen::wchar_width(uint32_t wc)
int min = 0;
int max = sizeof(combining) / sizeof(uint32_t) - 1;

// ignore invisible characters, such as invalid UTF-8
if (wc == 0)
return 0;

// control characters are double width to display them e.g. as \t or ^I
if (wc < 0x20 || wc == 0x7f)
return 2;

// binary search in table of non-spacing characters
if (wc >= (combining[0] >> 8) && wc <= (combining[max] >> 8) + (combining[max] & 0xff))
{
Expand Down

0 comments on commit 668a041

Please sign in to comment.