Skip to content

Commit

Permalink
Added blinking cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
chregu82 committed Sep 16, 2020
1 parent 8902274 commit e9f0821
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 4 deletions.
Binary file modified bin/kernel.img
Binary file not shown.
Binary file modified bin/kernel7.img
Binary file not shown.
Binary file modified bin/kernel8-32.img
Binary file not shown.
Binary file modified bin/recovery7l.img
Binary file not shown.
1 change: 1 addition & 0 deletions doc/terminal_codes.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Cursor Control

<ESC>[?25l Cursor invisible
<ESC>[?25b Cursor blinking
<ESC>[?25h Cursor visible
<ESC>[H Move to 0-0
<ESC>[f Move to 0-0
Expand Down
55 changes: 51 additions & 4 deletions src/gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ typedef struct {
unsigned int cursor_col; /// Current column position (0-based)
unsigned int saved_cursor[2]; /// Saved cursor position
char cursor_visible; /// 0 if no visible cursor
char cursor_blink; /// 0 if not blinking
unsigned int blink_timer_hnd; /// timer handle for cursor blink

scn_state state; /// Current scan state
} term;
Expand Down Expand Up @@ -1514,6 +1516,33 @@ void gfx_term_set_cursor_visibility( unsigned char visible )
ctx.term.cursor_visible = visible;
}

void gfx_term_switch_cursor_vis( __attribute__((unused)) unsigned hnd,
__attribute__((unused)) void* pParam,
__attribute__((unused)) void *pContext )
{
if (ctx.term.cursor_visible)
{
gfx_term_set_cursor_visibility(0);
gfx_restore_cursor_content();
}
else
{
gfx_term_set_cursor_visibility(1);
gfx_term_render_cursor();
}
ctx.term.blink_timer_hnd = attach_timer_handler(2, &gfx_term_switch_cursor_vis, 0, 0);
}

void gfx_term_set_cursor_blinking( unsigned char blink )
{
ctx.term.cursor_blink = blink;
remove_timer(ctx.term.blink_timer_hnd); // it's okay to be 0
if (blink)
{
ctx.term.blink_timer_hnd = attach_timer_handler(2, &gfx_term_switch_cursor_vis, 0, 0);
}
}


void gfx_term_move_cursor( unsigned int row, unsigned int col )
{
Expand Down Expand Up @@ -2029,8 +2058,22 @@ int state_fun_final_letter( char ch, scn_state *state )
state->cmd_params_size == 1 &&
state->cmd_params[0] == 25 )
{
gfx_term_set_cursor_visibility(0);
gfx_restore_cursor_content();
gfx_term_set_cursor_blinking(0);
if (ctx.term.cursor_visible)
{
gfx_term_set_cursor_visibility(0);
gfx_restore_cursor_content();
}
}
goto back_to_normal;
break;

case 'b':
if( state->private_mode_char == '?' &&
state->cmd_params_size == 1 &&
state->cmd_params[0] == 25 )
{
gfx_term_set_cursor_blinking(1);
}
goto back_to_normal;
break;
Expand All @@ -2040,8 +2083,12 @@ int state_fun_final_letter( char ch, scn_state *state )
state->cmd_params_size == 1 &&
state->cmd_params[0] == 25 )
{
gfx_term_set_cursor_visibility(1);
gfx_term_render_cursor();
gfx_term_set_cursor_blinking(0);
if (ctx.term.cursor_visible == 0)
{
gfx_term_set_cursor_visibility(1);
gfx_term_render_cursor();
}
}
goto back_to_normal;
break;
Expand Down

0 comments on commit e9f0821

Please sign in to comment.