Skip to content
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
39 changes: 39 additions & 0 deletions src/curses/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,44 @@ void Window::scroll(Scroll where)
scrollok(m_window, 0);
}

bool Window::isInsideWideChar() const
{
const int y = getcury(m_window);
const int x = getcurx(m_window);
const int max_cols = getWidth();
int i = 0;
for (; (i + x) < max_cols; i++)
{
cchar_t cell{};
wchar_t characters[CCHARW_MAX]{};
attr_t attributes{};
short colorPair{};
if (mvwin_wch(m_window,y,x + i,&cell) == OK && getcchar(&cell,characters,&attributes,&colorPair,nullptr) != ERR)
{
//check if it is not 2 col wide
if (wcwidth(characters[0]) != 2)
{
//it is not a 2 col wide char, break
break;
}
}
}
wmove(m_window, y, x);
if ((i % 2) == 1) {
return true;
}
return false;
}

void Window::fixWideChar() {
if (isInsideWideChar()) {
const int y = getcury(m_window);
const int x = getcurx(m_window);
wmove(m_window, y, x - 1);
waddstr(m_window, " ");
wmove(m_window, y, x);
}
}

Window &Window::operator<<(const Color &c)
{
Expand Down Expand Up @@ -1498,6 +1536,7 @@ Window &Window::operator<<(double d)

Window &Window::operator<<(const std::string &s)
{
fixWideChar();
waddnstr(m_window, s.c_str(), s.length());
return *this;
}
Expand Down
7 changes: 7 additions & 0 deletions src/curses/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,13 @@ struct Window
/// Scrolls the window by amount of lines given in its parameter
/// @param where indicates how many lines it has to scroll
virtual void scroll(Scroll where);

/// This checks if the current position is in the middle of a wide character
/// Can be used to fix line overshoot with Japanese characters
bool isInsideWideChar() const;

/// This fixes rendering issues when printing on top of wide characters
void fixWideChar();

Window &operator<<(TermManip tm);
Window &operator<<(const Color &color);
Expand Down