@@ -11,6 +11,9 @@ static WINDOW *divider;
1111static WINDOW * hex ;
1212static WINDOW * lines ;
1313
14+ static int characters_drawn ;
15+ static int hex_per_line ;
16+
1417void gui_init () {
1518
1619 int maxx ;
@@ -76,8 +79,10 @@ void gui_draw_title(char *format, ...) {
7679
7780void gui_draw_hex (byte * file , unsigned int file_current_offset ) {
7881
82+ wclrtobot (hex );
83+ characters_drawn = 0 ;
7984 file += file_current_offset ;
80- unsigned int hex_per_line = getmaxx (hex ) / 3 ;
85+ hex_per_line = getmaxx (hex ) / 3 ;
8186 unsigned int file_max_drawable = hex_per_line * getmaxy (hex );
8287 unsigned int file_size = strlen (file );
8388 unsigned int file_draw_size = (file_max_drawable < file_size ) ? file_max_drawable : file_size ;
@@ -86,8 +91,9 @@ void gui_draw_hex(byte *file, unsigned int file_current_offset) {
8691 wmove (hex , 0 , 0 );
8792 wmove (text , 0 , 0 );
8893 for (i = 0 ; i < file_draw_size ; i += hex_per_line , ++ line ) {
89- for (unsigned int j = 0 ; (j < hex_per_line ) && (i + j < file_draw_size ); ++ j ) {
94+ for (int j = 0 ; (j < hex_per_line ) && (i + j < file_draw_size ); ++ j ) {
9095 wprintw (hex , "%02x " , file [i + j ]);
96+ ++ characters_drawn ;
9197 switch (file [i + j ]) {
9298 case '\n' :
9399 wprintw (text , "\\n" );
@@ -122,11 +128,10 @@ void draw_cursor_up(unsigned int *file_current_offset, byte *file) {
122128 unsigned int maxy = getmaxy (hex );
123129 unsigned int cur_y = getcury (hex );
124130 unsigned int cur_x = getcurx (hex );
125- unsigned int hex_per_line = getmaxx (hex ) / 3 ;
126131 if (0 == cur_y && * file_current_offset > 0 ) {
127132 * file_current_offset -= hex_per_line ;
128133 gui_draw_hex (file , * file_current_offset );
129- wmove (hex , cur_y + 1 , cur_x );
134+ wmove (hex , cur_y , cur_x );
130135 } else {
131136 wmove (hex , cur_y - 1 , cur_x );
132137 }
@@ -135,26 +140,38 @@ void draw_cursor_up(unsigned int *file_current_offset, byte *file) {
135140
136141void draw_cursor_down (unsigned int * file_current_offset , byte * file ) {
137142
143+ int last_row_caracter_count = (characters_drawn % hex_per_line );
144+ int row_count = characters_drawn / hex_per_line ;
138145 int maxy = getmaxy (hex );
139146 int cur_y = getcury (hex );
140147 int cur_x = getcurx (hex );
141- int hex_per_line = getmaxx (hex ) / 3 ;
142148
143- int down_max_count = strlen (file ) / hex_per_line - ((int ) * file_current_offset ) / hex_per_line - getmaxy ( hex ) ;
149+ int down_max_count = strlen (file ) / hex_per_line - ((int ) * file_current_offset ) / hex_per_line - maxy ;
144150
145- if (maxy - 1 == cur_y && down_max_count >= 0 ) {
151+ if (cur_x >= last_row_caracter_count * 3 && cur_y == row_count - 1 ) {
152+ wmove (hex , cur_y + 1 , last_row_caracter_count * 3 - 1 );
153+ } else if (maxy - 1 == cur_y && down_max_count >= 0 ) {
146154 * file_current_offset += hex_per_line ;
147155 gui_draw_hex (file , * file_current_offset );
148- wmove (hex , cur_y - 1 , cur_x );
149- } else {
156+ wmove (hex , cur_y , cur_x );
157+ } else if (cur_y < characters_drawn / hex_per_line ) {
158+
150159 wmove (hex , cur_y + 1 , cur_x );
151160 }
152161 REFRESH_WINDOW (hex )
153162}
154163void draw_cursor_right (unsigned int * file_current_offset , byte * file ) {
155164
156- wmove (hex , getcury (hex ), getcurx (hex ) + 1 );
157- REFRESH_WINDOW (hex )
165+ int last_row_caracter_count = (characters_drawn % hex_per_line );
166+ int row_count = characters_drawn / hex_per_line ;
167+ last_row_caracter_count = (last_row_caracter_count == 0 ) ? hex_per_line : last_row_caracter_count ;
168+ int cur_y = getcury (hex );
169+ int cur_x = getcurx (hex );
170+
171+ if (cur_x <= last_row_caracter_count * 3 - 2 || cur_y < row_count ) {
172+ wmove (hex , cur_y , cur_x + 1 );
173+ REFRESH_WINDOW (hex )
174+ }
158175}
159176void draw_cursor_left (unsigned int * file_current_offset , byte * file ) {
160177
0 commit comments