From 3e4e3f17a8bd10ed510fbdd31c71af4d98508981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haoran=20S=2E=20Diao=20=28=E5=88=81=E6=B5=A9=E7=84=B6=29?= <0@hairydiode.xyz> Date: Sat, 6 Sep 2025 14:20:34 -0700 Subject: Made input method fully encoding agnostic --- boshiamy.h | 12 ++++++++++++ im.h | 20 ++++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/boshiamy.h b/boshiamy.h index d2cc0e5..63251e8 100644 --- a/boshiamy.h +++ b/boshiamy.h @@ -1,5 +1,17 @@ +//indicators for turning the im on and off +#define IM_ON_INDICATOR "嘸" +//string length in bytes +#define IM_ON_INDICATOR_LEN 3 +#define IM_OFF_INDICATOR "英" +#define IM_OFF_INDICATOR_LEN 3 +//width of the indicator as displayed on the terminal +#define IM_INDICATOR_WIDTH 2 +//length of input method table #define IM_TABLE_LEN 47976 +//length of entry fields in bytes #define IM_TABLE_ENTRY_LEN 8 +//maximum entry width as displayed on terminal +#define IM_TABLE_ENTRY_WIDTH 2 char im_table[][3][IM_TABLE_ENTRY_LEN] = { {"'' ", "“", 0}, {"''' ", "”", 0}, diff --git a/im.h b/im.h index 47d0511..f029fb1 100644 --- a/im.h +++ b/im.h @@ -1,10 +1,16 @@ //Input Method Functions and Variables //#include "imtable.h" -#include "boshiamy.h" #define IM_BUFFER_LEN 32 #define IM_PREVIEW 1 #define IM_PREVIEW_ENTRIES 6 -#define IM_PREVIEW_WIDTH 4*IM_PREVIEW_ENTRIES +#define IM_PREVIEW_WIDTH (IM_TABLE_ENTRY_WIDTH+2)*IM_PREVIEW_ENTRIES +#define IM_ON_INDICATOR "CN" +#define IM_ON_INDICATOR_LEN 2 +#define IM_OFF_INDICATOR "EN" +#define IM_OFF_INDICATOR_LEN 2 +#define IM_INDICATOR_WIDTH 2 +#include "boshiamy.h" + #define ENTER_KEY 0x0D #define BACKSPACE_KEY 0x7F //setting it to the actual escape character interferes with arrow keys and @@ -14,6 +20,7 @@ //Vertical Tab Ctrl+K #define TOGGLE_KEY 0x0B #define IM_KEY_RANGE_LEN 7 + //Array of Input method key ranges(inclusive) seperate from the above char im_key_ranges[IM_KEY_RANGE_LEN][2] = { {'a','z'}, @@ -192,8 +199,8 @@ void im_preview(int fd, int trows, int tcols) { //rows and columns on the terminal descibed by fd void disp_im(int fd, int trows, int tcols) { //generates the position escape sequence for the bottom left corner - //4 spaces for the im indicator +1 for automargin - int im_col = tcols - IM_TABLE_ENTRY_LEN - 4 - 1; + //2 spaces for the im indicator, 2 for buffer brackets, +1 for automargin + int im_col = tcols - IM_TABLE_ENTRY_LEN - IM_INDICATOR_WIDTH - 2 - 1; if (IM_PREVIEW) { im_col = im_col - IM_PREVIEW_WIDTH; } @@ -213,10 +220,11 @@ void disp_im(int fd, int trows, int tcols) { write(fd, pos_str,l); //im mode indicator if (im_on) { - write(fd,"漢[",4); + write(fd,IM_ON_INDICATOR,IM_ON_INDICATOR_LEN); } else { - write(fd,"英[",4); + write(fd,IM_OFF_INDICATOR,IM_OFF_INDICATOR_LEN); } + write(fd,"[",1); //actual buffer write(fd,im_buffer,im_buffer_pos); write(fd,"]",1); -- cgit v1.1