diff options
author | Haoran S. Diao (刁浩然) <0@hairydiode.xyz> | 2025-09-06 14:20:34 -0700 |
---|---|---|
committer | Haoran S. Diao (刁浩然) <0@hairydiode.xyz> | 2025-09-06 14:20:34 -0700 |
commit | 3e4e3f17a8bd10ed510fbdd31c71af4d98508981 (patch) | |
tree | 0a4ffb3ab15c4ee9204ff31a0b3ab8a916e088a0 /im.h | |
parent | 8fe3f476f0d443ea21fb5f3986156fbd31bcdff3 (diff) |
Made input method fully encoding agnostic
Diffstat (limited to 'im.h')
-rw-r--r-- | im.h | 20 |
1 files changed, 14 insertions, 6 deletions
@@ -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); |