44#include <string.h>
55#include <stdlib.h>
66
7+ #define TAB_WIDTH 4
8+
79syntax_header_t * syntax = NULL ;
810
911
@@ -29,6 +31,14 @@ void rerender_color(edit_state_t* state) {
2931 }
3032}
3133
34+ void draw_line_number (int cur_y , int current_line ) {
35+ char buff [16 ] = { 0 };
36+ memset (buff , 0 , sizeof (buff ));
37+ sprintf (buff , "%d." , current_line );
38+ draw_string (0 , cur_y , buff , BACKGROUND_BLACK | FOREGROUND_LIGHTGRAY );
39+ }
40+
41+
3242void render_tui (edit_state_t * state ) {
3343 start_frame ();
3444
@@ -86,9 +96,7 @@ void render_tui(edit_state_t* state) {
8696 if ((j >= start_line && j < start_line + viewport_height ) && already_drawn <= viewport_height ) {
8797 if (!initial_line_drawn ) {
8898 initial_line_drawn = true;
89- memset (buff , 0 , 512 );
90- sprintf (buff , "%d." , current_line );
91- draw_string (0 , cur_y , buff , BACKGROUND_BLACK | FOREGROUND_LIGHTGRAY );
99+ draw_line_number (cur_y , current_line );
92100 }
93101
94102 if (i == state -> buffer_idx ) {
@@ -97,6 +105,24 @@ void render_tui(edit_state_t* state) {
97105 cursor_drawn = true;
98106 }
99107
108+ if (state -> input_buffer [i ] == '\t' ) {
109+ int col = cur_x - space_to_draw ;
110+ int next_tab_stop = ((col / TAB_WIDTH ) + 1 ) * TAB_WIDTH ;
111+ int spaces = next_tab_stop - col ;
112+
113+ for (int s = 0 ; s < spaces ; s ++ ) {
114+ if (cur_x >= width ) {
115+ cur_y ++ ;
116+ cur_x = space_to_draw ;
117+ already_drawn ++ ;
118+ draw_line_number (cur_y , current_line );
119+ }
120+ draw_char (cur_x , cur_y , state -> show_tab_char ? '.' : ' ' , BACKGROUND_BLACK | FOREGROUND_LIGHTGRAY );
121+ cur_x ++ ;
122+ }
123+ cur_x -- ;
124+ }
125+
100126 if (state -> input_buffer [i ] >= 0x20 && state -> input_buffer [i ] <= 0x7E ) {
101127 draw_char (cur_x , cur_y , state -> input_buffer [i ], BACKGROUND_BLACK | (color ? color_translation [color [i ]] : FOREGROUND_WHITE ));
102128 }
@@ -109,9 +135,7 @@ void render_tui(edit_state_t* state) {
109135 j ++ ;
110136 cur_x = space_to_draw ;
111137 cur_y ++ ;
112- memset (buff , 0 , 512 );
113- sprintf (buff , "%d." , current_line );
114- draw_string (0 , cur_y , buff , BACKGROUND_BLACK | FOREGROUND_LIGHTGRAY );
138+ draw_line_number (cur_y , current_line );
115139 } else if (cur_x == width - 1 ) {
116140 cur_y ++ ;
117141 cur_x = space_to_draw ;
0 commit comments