Skip to content
This repository was archived by the owner on Jan 12, 2022. It is now read-only.

Commit cdecdfa

Browse files
committed
Handle mode-dependent cursor shape
1 parent 9303b4b commit cdecdfa

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@ Turns out, it's quite easy to code after experiments with [SpyUI](https://github
1111
- [x] Improve redrawing by combining adjacent cells with the same hl_id
1212
- [x] Test MinGW build
1313
- [x] Setup GitHub actions to build for Win32
14+
- [x] Cursor shapes
1415
- [ ] Automatic testing
15-
- [ ] Cursor shapes
1616
- [ ] Properly close the editor when the window is about to be closed
1717
- [ ] Make redrawing atomic with flush
1818
- [ ] Handle special keys like arrows, functional keys
1919
- [ ] Handle the rest of highlight attributes
2020
- [ ] Handle errors and failures
2121
- [ ] Use pango for text layout
2222
- [ ] Allow selecting GUI font
23+
- [ ] Fast zoom with mouse wheel
2324
- [ ] Consider externalizing popup menus to add scrollbars
2425
- [ ] Configuration of fonts and behaviour tweaking (consider using lua)
2526
- [ ] Mouse support
2627
- [ ] Change mouse pointer on busy_start/busy_stop notifications
2728
- [ ] Create window after neovim has been launched and initialized to avoid white flash during startup
2829
- [ ] Setup automatic releases (win32, appimage)
30+
- [ ] Track mode_info

grid.vala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,17 @@ class Grid {
122122
if (cursor.row >= top && cursor.row < bot &&
123123
cursor.col >= left && cursor.col < right) {
124124
ctx.save ();
125-
ctx.set_line_width (w * 0.1);
126125
ctx.set_tolerance (0.1);
126+
ctx.set_line_width (w * 0.1);
127127
ctx.set_source_rgba (1.0, 1.0, 1.0, 0.5);
128-
ctx.rectangle (cursor.col * w, cursor.row * h, w, h);
128+
ctx.translate (cursor.col * w, cursor.row * h);
129+
if (renderer.mode == "insert") {
130+
ctx.rectangle (0, 0, 0.2 * w, h);
131+
} else if (renderer.mode == "replace" || renderer.mode == "operator") {
132+
ctx.rectangle (0, 0.75 * h, w, 0.25 * h);
133+
} else {
134+
ctx.rectangle (0, 0, w, h);
135+
}
129136
ctx.fill ();
130137
ctx.restore ();
131138
}

hacks.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <msgpack/object.h>
2+
3+
void my_print (msgpack_object o, FILE* out)
4+
{
5+
return msgpack_object_print(out, o);
6+
}

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dependencies = [
1616
]
1717

1818
sources = files(
19+
'hacks.c',
1920
'main.vala',
2021
'msgpack-rpc.vala',
2122
'renderer.vala',

renderer.vala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11

2+
// MessagePack.Object.print () is broken, and I can't fix the order of arguments
3+
//extern void my_print (MessagePack.Object o, GLib.FileStream out);
4+
25
class Renderer : GLib.Object {
36

47
private unowned MsgpackRpc _rpc;
@@ -105,6 +108,10 @@ class Renderer : GLib.Object {
105108
handler = grid_scroll;
106109
} else if (memEqual (subtype, "win_viewport".data)) {
107110
// just info to display, can skip
111+
} else if (memEqual (subtype, "mode_info_set".data)) {
112+
//my_print (event[1], GLib.stdout);
113+
} else if (memEqual (subtype, "mode_change".data)) {
114+
handler = mode_change;
108115
} else {
109116
print ("Ignoring redraw %.*s\n", subtype.length, subtype);
110117
continue;
@@ -351,4 +358,12 @@ class Renderer : GLib.Object {
351358
}
352359
});
353360
}
361+
362+
public string mode { get; private set; }
363+
364+
private void mode_change (MessagePack.Object[] event) {
365+
unowned var m = event[0].str.str;
366+
mode = "%.*s".printf (m.length, m);
367+
changed (_cursor.row, _cursor.row + 1, _cursor.col, _cursor.col + 1);
368+
}
354369
}

0 commit comments

Comments
 (0)