mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 00:56:10 +00:00 
			
		
		
		
	Try to reduce the UTF-8 mess.
Get rid of passing around u_char[4]s and define a struct utf8_data which has character data, size (sequence length) and width. Move UTF-8 character collection into two functions utf8_open/utf8_append in utf8.c which fill in this struct and use these functions from input.c and the various functions in screen-write.c. Space for rather more data than is necessary for one UTF-8 sequence is in the utf8_data struct because screen_write_copy is still nasty and needs to reinject the character (after combining) into screen_write_cell.
This commit is contained in:
		
							
								
								
									
										40
									
								
								input.c
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								input.c
									
									
									
									
									
								
							@@ -572,15 +572,14 @@ input_state_string_escape(u_char ch, struct input_ctx *ictx)
 | 
			
		||||
void
 | 
			
		||||
input_state_utf8(u_char ch, struct input_ctx *ictx)
 | 
			
		||||
{
 | 
			
		||||
	log_debug2("-- un %zu: %hhu (%c)", ictx->off, ch, ch);
 | 
			
		||||
	log_debug2("-- utf8 next: %zu: %hhu (%c)", ictx->off, ch, ch);
 | 
			
		||||
 | 
			
		||||
	ictx->utf8_buf[ictx->utf8_off++] = ch;
 | 
			
		||||
	if (--ictx->utf8_len != 0)
 | 
			
		||||
		return;
 | 
			
		||||
	if (utf8_append(&ictx->utf8data, ch))
 | 
			
		||||
		return;		/* more to come */
 | 
			
		||||
	input_state(ictx, input_state_first);
 | 
			
		||||
 | 
			
		||||
	ictx->cell.flags |= GRID_FLAG_UTF8;
 | 
			
		||||
	screen_write_cell(&ictx->ctx, &ictx->cell, ictx->utf8_buf);
 | 
			
		||||
	screen_write_cell(&ictx->ctx, &ictx->cell, &ictx->utf8data);
 | 
			
		||||
	ictx->cell.flags &= ~GRID_FLAG_UTF8;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -590,40 +589,17 @@ input_handle_character(u_char ch, struct input_ctx *ictx)
 | 
			
		||||
	struct window_pane	*wp = ictx->wp;
 | 
			
		||||
 | 
			
		||||
	if (ch > 0x7f && options_get_number(&wp->window->options, "utf8")) {
 | 
			
		||||
		/*
 | 
			
		||||
		 * UTF-8 sequence.
 | 
			
		||||
		 *
 | 
			
		||||
		 * 11000010-11011111 C2-DF start of 2-byte sequence
 | 
			
		||||
		 * 11100000-11101111 E0-EF start of 3-byte sequence
 | 
			
		||||
		 * 11110000-11110100 F0-F4 start of 4-byte sequence
 | 
			
		||||
		 */
 | 
			
		||||
		memset(ictx->utf8_buf, 0xff, sizeof ictx->utf8_buf);
 | 
			
		||||
		ictx->utf8_buf[0] = ch;
 | 
			
		||||
		ictx->utf8_off = 1;
 | 
			
		||||
 | 
			
		||||
		if (ch >= 0xc2 && ch <= 0xdf) {
 | 
			
		||||
			log_debug2("-- u2 %zu: %hhu (%c)", ictx->off, ch, ch);
 | 
			
		||||
		if (utf8_open(&ictx->utf8data, ch)) {
 | 
			
		||||
			log_debug2("-- utf8 size %u: %zu: %hhu (%c)", 
 | 
			
		||||
			    ictx->utf8data.size, ictx->off, ch, ch);
 | 
			
		||||
			input_state(ictx, input_state_utf8);
 | 
			
		||||
			ictx->utf8_len = 1;
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		if (ch >= 0xe0 && ch <= 0xef) {
 | 
			
		||||
			log_debug2("-- u3 %zu: %hhu (%c)", ictx->off, ch, ch);
 | 
			
		||||
			input_state(ictx, input_state_utf8);
 | 
			
		||||
			ictx->utf8_len = 2;
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		if (ch >= 0xf0 && ch <= 0xf4) {
 | 
			
		||||
			log_debug2("-- u4 %zu: %hhu (%c)", ictx->off, ch, ch);
 | 
			
		||||
			input_state(ictx, input_state_utf8);
 | 
			
		||||
			ictx->utf8_len = 3;
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	log_debug2("-- ch %zu: %hhu (%c)", ictx->off, ch, ch);
 | 
			
		||||
 | 
			
		||||
	ictx->cell.data = ch;
 | 
			
		||||
	screen_write_cell(&ictx->ctx, &ictx->cell, ictx->utf8_buf);
 | 
			
		||||
	screen_write_cell(&ictx->ctx, &ictx->cell, NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user