Skip to content

Commit

Permalink
Improve cursor.
Browse files Browse the repository at this point in the history
Increments-minor-version-of: ttyr-tty
  • Loading branch information
dajofrey committed Jul 26, 2024
1 parent 327101e commit 26db9bd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
8 changes: 7 additions & 1 deletion src/lib/ttyr-tty/Shell/Shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -932,8 +932,14 @@ static TTYR_TTY_RESULT ttyr_tty_getShellCursor(
{
if (((ttyr_tty_Shell*)Program_p->handle_p)->scroll != 0) {return TTYR_TTY_SUCCESS;}

// MODE_HIDE is activated by for example: echo -e "\e[?25l"
if (((ttyr_tty_Shell*)Program_p->handle_p)->ST_p->windowMode & MODE_HIDE) {
*x_p = -1;
*y_p = -1;
}

// ST_p is created late during first draw, which might not have happened before this is called.
if (((ttyr_tty_Shell*)Program_p->handle_p)->ST_p) {
else if (((ttyr_tty_Shell*)Program_p->handle_p)->ST_p) {
*x_p = ((ttyr_tty_Shell*)Program_p->handle_p)->ST_p->ocx;
*y_p = ((ttyr_tty_Shell*)Program_p->handle_p)->ST_p->ocy;
}
Expand Down
5 changes: 1 addition & 4 deletions src/lib/ttyr-tty/TTY/Draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ TTYR_TTY_RESULT ttyr_tty_refreshCursor(
TTYR_CHECK(ttyr_tty_getCursorPosition(TTY_p->Window_p->Tile_p, MicroTile_p, View_p->standardIO, &x, &y))
}

if (x > -1 && y > -1) {
// Only forward cursor with valid position.
TTYR_CHECK(ttyr_tty_forwardCursor(View_p, x, y))
}
TTYR_CHECK(ttyr_tty_forwardCursor(View_p, x, y))

return TTYR_TTY_SUCCESS;
}
Expand Down
9 changes: 8 additions & 1 deletion src/lib/ttyr-tty/TTY/StandardIO.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ TTYR_TTY_RESULT ttyr_tty_writeCursorToStandardOutput(
nh_String String = nh_core_initString(255);

NH_BYTE buf[32] = {'\0'};
snprintf(buf, sizeof(buf), "\x1b[%d;%dH", y, x);
if (x > 0 && y > 0) {
snprintf(buf, sizeof(buf), "\x1b[?25h\x1b[%d;%dH", y, x);
} else {
snprintf(buf, sizeof(buf), "\x1b[?25l");
}
nh_core_appendFormatToString(&String, buf);

#ifdef __unix__
Expand Down Expand Up @@ -305,6 +309,9 @@ static TTYR_TTY_RESULT ttyr_tty_exitRawMode(
return TTYR_TTY_ERROR_BAD_STATE;
}

// Make cursor reappear just in case.
write(STDOUT_FILENO, "\033[?25h", 6);

// https://stackoverflow.com/questions/43202800/when-exiting-terminal-rawmode-my-contents-stays-on-the-screen
write(STDOUT_FILENO, "\033[2J\033[H\033[?1049l", 15);

Expand Down
10 changes: 5 additions & 5 deletions src/lib/ttyr-tty/TTY/TTY.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,19 @@ static TTYR_TTY_RESULT ttyr_tty_handleInput(
static TTYR_TTY_RESULT ttyr_tty_handleWindowResize(
ttyr_tty_TTY *TTY_p, ttyr_tty_View *View_p)
{
NH_BOOL updated = NH_FALSE;
bool updated = false;

TTYR_CHECK(ttyr_tty_getViewSize(View_p))
TTYR_CHECK(ttyr_tty_updateView(View_p, &updated, NH_TRUE))
TTYR_CHECK(ttyr_tty_updateView(View_p, &updated, true))

if (updated) {
if (TTY_p->Window_p->MouseMenu_p) {
TTY_p->Window_p->MouseMenu_p = NULL;
}

TTY_p->Window_p->refreshGrid1 = NH_TRUE;
TTY_p->Window_p->refreshGrid2 = NH_TRUE;
TTY_p->Window_p->refreshTitlebar = NH_TRUE;
TTY_p->Window_p->refreshGrid1 = true;
TTY_p->Window_p->refreshGrid2 = true;
TTY_p->Window_p->refreshTitlebar = true;
}

return TTYR_TTY_SUCCESS;
Expand Down
3 changes: 2 additions & 1 deletion src/lib/ttyr-tty/TTY/View.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ TTYR_TTY_RESULT ttyr_tty_updateView(
{
if (View_p->cols == View_p->previousCols && View_p->rows == View_p->previousRows &&
View_p->Size.width == View_p->PreviousSize.width && View_p->Size.height == View_p->PreviousSize.height) {
if (updated_p) {*updated_p = false;}
return TTYR_TTY_SUCCESS;
}

Expand Down Expand Up @@ -232,7 +233,7 @@ TTYR_TTY_RESULT ttyr_tty_forwardCursor(
Update.row = Config.Titlebar.on ? y : y - 1;
Update.col = x - 1;
Update.Glyph = Glyph;
Update.cursor = NH_TRUE;
Update.cursor = true;

nh_core_appendToArray(Array_p, &Update, 1);

Expand Down

0 comments on commit 26db9bd

Please sign in to comment.