Commits

Evan Gates  committed 7119937

even closer

  • Participants
  • Parent commits f743254
  • Branches utf8

Comments (0)

Files changed (1)

 	if (len == 0)
 		return 0;
 
-	for (; *ind > 0 && *ind < len  &&
-		(buf[*ind] & 0xc0) != 0xc0 &&
-		(buf[*ind] & 0x80); *ind += crement)
+	for (; *ind > -1 && *ind < len &&
+		(buf[*ind] & 0xc0) != 0xc0 && (buf[*ind] & 0x80);
+		*ind += crement)
 		;
+	if (*ind < 0) {
+		*ind = 0;
+		return -1;
+	}
 	// skip the first, if it's ascii we still want one byte (nb = 1)
 	for (nb = 1, mask = 0x40; buf[*ind] & mask; nb++, mask >>= 1)
 		;
 {
 	int i, n;
 
-	for (n = 0, i = width(buf, &n, len, 1); i <= cols && n < len; n++, i += width(buf, &n, len, 1))
+	for (i = n = 0; i <= cols && n < len; i += width(buf, &n, len, 1), n++)
 		;
 
 	return n;
 
 void print_usr(void)
 {
-	int cols, left_prompt_len, right_prompt_len = 0;
+	int cols, i, sb, left_prompt_len, right_prompt_len = 0;
 	struct winsize ws;
 
 	if (ioctl(STDOUT, TIOCGWINSZ, &ws) < 0)
 		err(1, "failed ioctl");
 
-	cols = ws.ws_col;
+	cols = ws.ws_col - 1;
 
 	erase_usr();
 
 	if (start > 0 || wlen > cols) {
 		left_prompt_len = strlen(scrl_prompt_left);
 		my_write(STDOUT, scrl_prompt_left, left_prompt_len);
-		cols = ws.ws_col - 1 - left_prompt_len;
+		cols = ws.ws_col -  1 - left_prompt_len;
 		start = start_pos(start, wcur, wlen, cols);
 	} else {
 		my_write(STDOUT, nrml_prompt, left_prompt_len);
 	}
 
 	//my_write(STDOUT, usrbuf + start, MIN(cols, len));
-	my_write(STDOUT, usrbuf + start, nbytes(usrbuf + start, len - start, cols));
+	for (i = sb = 0; i < start; i += width(usrbuf, &sb, len, 1), sb++)
+		;
+	width(usrbuf, &sb, len, 1);
+	my_write(STDOUT, usrbuf + sb, nbytes(usrbuf + sb, len - sb, cols));
 
 	if (start + cols < wlen)
 		my_write(STDOUT, scrl_prompt_right, right_prompt_len);