aboutsummaryrefslogtreecommitdiff
path: root/src/vterm
diff options
context:
space:
mode:
authordundargoc <gocdundar@gmail.com>2024-08-14 15:52:51 +0200
committerdundargoc <33953936+dundargoc@users.noreply.github.com>2024-09-05 14:28:12 +0200
commitf9108378b7a7e08b48685f0a3ff4f7a3a14b56d6 (patch)
treec347ffd91ee7e05a981f313aa4c15d8a2354fbf7 /src/vterm
parent975aeee537375a14c0e16916e1ef312aae90b85f (diff)
downloadrneovim-f9108378b7a7e08b48685f0a3ff4f7a3a14b56d6.tar.gz
rneovim-f9108378b7a7e08b48685f0a3ff4f7a3a14b56d6.tar.bz2
rneovim-f9108378b7a7e08b48685f0a3ff4f7a3a14b56d6.zip
refactor: adopt termkey and eliminate duplicate code
Termkey is abandoned and it's now our code, so there's no reason not to treat it as such. An alternative approach could be to have a proper repo that we maintain such as with unibilium, although with this approach we can make a few assumptions that will allow us to remove more code. Also eliminate duplicate code from both termkey and libvterm.
Diffstat (limited to 'src/vterm')
-rw-r--r--src/vterm/keyboard.c3
-rw-r--r--src/vterm/mouse.c2
-rw-r--r--src/vterm/screen.c5
-rw-r--r--src/vterm/utf8.h39
4 files changed, 5 insertions, 44 deletions
diff --git a/src/vterm/keyboard.c b/src/vterm/keyboard.c
index d31c8be12d..7e062c8c02 100644
--- a/src/vterm/keyboard.c
+++ b/src/vterm/keyboard.c
@@ -1,8 +1,7 @@
#include "vterm_internal.h"
-
#include <stdio.h>
-#include "utf8.h"
+#include "nvim/tui/termkey/termkey.h"
void vterm_keyboard_unichar(VTerm *vt, uint32_t c, VTermModifier mod)
{
diff --git a/src/vterm/mouse.c b/src/vterm/mouse.c
index f74abc3d9d..a9d3fe4ca9 100644
--- a/src/vterm/mouse.c
+++ b/src/vterm/mouse.c
@@ -1,6 +1,6 @@
#include "vterm_internal.h"
-#include "utf8.h"
+#include "nvim/tui/termkey/termkey.h"
static void output_mouse(VTermState *state, int code, int pressed, int modifiers, int col, int row)
{
diff --git a/src/vterm/screen.c b/src/vterm/screen.c
index bd3cbd6bd0..e63db483f9 100644
--- a/src/vterm/screen.c
+++ b/src/vterm/screen.c
@@ -2,9 +2,10 @@
#include <stdio.h>
#include <string.h>
+#include "nvim/mbyte.h"
+#include "nvim/tui/termkey/termkey.h"
#include "rect.h"
-#include "utf8.h"
#define UNICODE_SPACE 0x20
#define UNICODE_LINEFEED 0x0a
@@ -922,7 +923,7 @@ static size_t _get_chars(const VTermScreen *screen, const int utf8, void *buffer
#define PUT(c) \
if(utf8) { \
- size_t thislen = utf8_seqlen(c); \
+ size_t thislen = utf_char2len(c); \
if(buffer && outpos + thislen <= len) \
outpos += fill_utf8((c), (char *)buffer + outpos); \
else \
diff --git a/src/vterm/utf8.h b/src/vterm/utf8.h
deleted file mode 100644
index 9a336d357f..0000000000
--- a/src/vterm/utf8.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/* The following functions copied and adapted from libtermkey
- *
- * http://www.leonerd.org.uk/code/libtermkey/
- */
-static inline unsigned int utf8_seqlen(long codepoint)
-{
- if(codepoint < 0x0000080) return 1;
- if(codepoint < 0x0000800) return 2;
- if(codepoint < 0x0010000) return 3;
- if(codepoint < 0x0200000) return 4;
- if(codepoint < 0x4000000) return 5;
- return 6;
-}
-
-/* Does NOT NUL-terminate the buffer */
-static int fill_utf8(long codepoint, char *str)
-{
- int nbytes = utf8_seqlen(codepoint);
-
- // This is easier done backwards
- int b = nbytes;
- while(b > 1) {
- b--;
- str[b] = 0x80 | (codepoint & 0x3f);
- codepoint >>= 6;
- }
-
- switch(nbytes) {
- case 1: str[0] = (codepoint & 0x7f); break;
- case 2: str[0] = 0xc0 | (codepoint & 0x1f); break;
- case 3: str[0] = 0xe0 | (codepoint & 0x0f); break;
- case 4: str[0] = 0xf0 | (codepoint & 0x07); break;
- case 5: str[0] = 0xf8 | (codepoint & 0x03); break;
- case 6: str[0] = 0xfc | (codepoint & 0x01); break;
- }
-
- return nbytes;
-}
-/* end copy */