Skip to content

Commit

Permalink
Linux console controls for underscore cursor size (mintty/wsltty#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
mintty committed Nov 29, 2019
1 parent 9a6d113 commit 1e5d3d5
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/term.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ term_reset(bool full)
term.sixel_scrolls_left = 0;

term.cursor_type = -1;
term.cursor_size = 0;
term.cursor_blinks = -1;
term.cursor_blink_interval = 0;
if (full) {
Expand Down
1 change: 1 addition & 0 deletions src/term.h
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ struct term {
// off(default): sixel scrolling moves cursor to left of graphics
bool private_color_registers;
int cursor_type;
int cursor_size;
bool cursor_blinkmode;
int cursor_blinks;
int cursor_blink_interval;
Expand Down
2 changes: 2 additions & 0 deletions src/termout.c
Original file line number Diff line number Diff line change
Expand Up @@ -2566,6 +2566,8 @@ do_csi(uchar c)
term.cursor_blink_interval = arg1;
term.cursor_invalid = true;
term_schedule_cblink();
when CPAIR('?', 'c'): /* Cursor size (Linux console) */
term.cursor_size = arg0;
when CPAIR('"', 'q'): /* DECSCA: select character protection attribute */
switch (arg0) {
when 0 or 2: term.curs.attr.attr &= ~ATTR_PROTECTED;
Expand Down
30 changes: 28 additions & 2 deletions src/wintext.c
Original file line number Diff line number Diff line change
Expand Up @@ -3906,8 +3906,34 @@ draw:;
if (lattr == LATTR_BOT)
yy += cell_height;
}
if (attr.attr & TATTR_ACTCURS)
Rectangle(dc, x, yy, x + char_width, yy + 2);
if (attr.attr & TATTR_ACTCURS) {
/* cursor size CSI ? N c
from linux console https://linuxgazette.net/137/anonymous.html
0 default
1 invisible
2 underscore
3 lower_third
4 lower_half
5 two_thirds
6 full block
*/
int up = 0;
switch (term.cursor_size) {
when 1: up = -2;
when 2: up = line_width - 1;
when 3: up = cell_height / 3 - 1;
when 4: up = cell_height / 2;
when 5: up = cell_height * 2 / 3;
when 6: up = cell_height - 2;
}
if (up) {
HBRUSH oldbrush = SelectObject(dc, CreateSolidBrush(_cc));
Rectangle(dc, x, yy - up, x + char_width, yy + 2);
DeleteObject(SelectObject(dc, oldbrush));
}
else
Rectangle(dc, x, yy - up, x + char_width, yy + 2);
}
else if (attr.attr & TATTR_PASCURS) {
for (int dx = 0; dx < char_width; dx += 2) {
SetPixel(dc, x + dx, yy, _cc);
Expand Down
3 changes: 3 additions & 0 deletions wiki/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Terminal features
* Linux console controls for underscore cursor size (mintty/wsltty#203).

### 3.1.0 (23 November 2019) ###

Terminal features
Expand Down
21 changes: 19 additions & 2 deletions wiki/CtrlSeqs.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ control sequence 8452.
## Cursor style ##

The VT510 _[DECSCUSR](http://vt100.net/docs/vt510-rm/DECSCUSR)_ sequence
can be used to control cursor shape and blinking.
can be used to control cursor type (shape) and blinking.
It takes an optional second parameter (proprietary extension) to set the
blinking interval in milliseconds.

Expand All @@ -471,4 +471,21 @@ blinking interval in milliseconds.
| **3** | underscore | yes |
| **4** | underscore | no |
| **5** | line | yes |
| **6** | line | no |
| **6** | line | no |

Furthermore, the following Linux console sequence can be used to set the
size of the active underscore cursor.
(Note that the second and third parameters from the Linux sequence are not
supported; cursor colour can be set with the OSC 12 sequence.)

> `^[[?` _arg_ `c`
| **arg** | **size** |
|:--------|:-------------|
| **0** | default |
| **1** | invisible |
| **2** | underscore |
| **3** | lower_third |
| **4** | lower_half |
| **5** | two_thirds |
| **6** | full block |

0 comments on commit 1e5d3d5

Please sign in to comment.