Exemple #1
0
int
esc_print_line(const char line[], WINDOW *win, int col, int row, int max_width,
               int dry_run, esc_state *state, int *printed)
{
    int offset;
    const char *curr = line;
    size_t pos = 0U;
    checked_wmove(win, row, col);
    while(pos <= (size_t)max_width && *curr != '\0')
    {
        size_t screen_width;
        const char *const char_str = strchar2str(curr, pos, &screen_width);
        pos += screen_width;
        if(pos <= (size_t)max_width)
        {
            if(!dry_run || screen_width == 0)
            {
                print_char_esc(win, char_str, state);
            }

            if(*curr == '\b')
            {
                if(!dry_run)
                {
                    int y, x;
                    getyx(win, y, x);
                    if(x > 0)
                    {
                        checked_wmove(win, y, x - 1);
                    }
                }

                if(pos > 0)
                {
                    pos--;
                }
            }

            curr += get_char_width_esc(curr);
        }
    }
    *printed = pos;
    offset = curr - line;

    /* Always process all escape sequences of the line in order to preserve all
     * elements of highlighting even when lines are not fully drawn. */
    curr--;
    while((curr = strchr(curr + 1, '\033')) != NULL)
    {
        size_t screen_width;
        const char *const char_str = strchar2str(curr, 0, &screen_width);
        print_char_esc(win, char_str, state);
    }

    return offset;
}
Exemple #2
0
TEST(cyrillic_character_width_is_determined_correctly, IF(locale_works))
{
	size_t screen_width;
	const char *const str = strchar2str("йклм", 0, &screen_width);
	assert_string_equal("й", str);
	assert_int_equal(1, screen_width);
}
Exemple #3
0
TEST(chinese_character_width_is_determined_correctly, IF(locale_works))
{
	size_t screen_width;
	const char *const str = strchar2str("师从刀", 0, &screen_width);
	assert_string_equal("师", str);
	assert_int_equal(2, screen_width);
}