# Test UTF-8, separate to avoid issues with platforms that don't support it

term.cap <- c("bright", "256", "truecolor")

lorem.cn.col.1 <- paste0(red, lorem.cn.pieces[1], inv, lorem.cn.pieces[2], 
    grn.bg, lorem.cn.pieces[3], rgb.und, lorem.cn.pieces[4], 
    end)

substr2_ctl(lor.cn.c.1.5, starts, ends, term.cap = term.cap)

lorem.cn.col.2 <- paste0(red, lorem.cn.pieces[1], "hello", inv, 
    lorem.cn.pieces[2], " there ", grn.bg, lorem.cn.pieces[3], 
    rgb.und, lorem.cn.pieces[4], end)

# These are all six chars wide, but look different due to different width
# characters

starts <- seq(1, by = 6, length.out = 5)

substr2_ctl(lor.cn.c.2.5, starts, ends, term.cap = term.cap)

substr2_sgr(lor.cn.c.2.5, starts, ends, term.cap = term.cap)

starts <- seq(1, by = 12, length.out = 5)

substr2_ctl(lor.cn.c.2.5, starts, ends, type = "width", term.cap = term.cap)

lorem.cn.col.4 <- paste0(red, lorem.cn.pieces[1], "hello", inv, 
    lorem.cn.pieces[2], " there ", grn.bg, lorem.cn.pieces[3], 
    rgb.und.256, lorem.cn.pieces[4], end)

# with colors that actually work on an OSX terminal

substr2_ctl(lor.cn.c.4.5, starts, ends, type = "width")

lorem.cn.col.3 <- paste0(red, lorem.cn.pieces[1], "helloo", inv, 
    lorem.cn.pieces[2], " world! ", grn.bg, lorem.cn.pieces[3], 
    rgb.und, lorem.cn.pieces[4], end)

# All wide characters even number of chars apart

substr2_ctl(lor.cn.c.3.5, starts, ends, type = "width", term.cap = term.cap)

# This is a bit of an accidental one, but it should be the case that the
# second line has two extra single width characters because all the others are
# losing the last character b/c we're ending in the middle, width wise

substr2_ctl(lor.cn.c.3.5, starts, ends, type = "width", round = "both", 
    term.cap = term.cap)

# and now we grab those missing chars by allowing the round to happen

starts <- seq(1, by = 7, length.out = 5)

# jagged first one leads short, second long

substr2_ctl(lor.cn.c.1.5, starts, ends, type = "width", term.cap = term.cap)

substr2_ctl(lor.cn.c.1.5, starts, ends, type = "width", round = "stop", 
    term.cap = term.cap)