## Copyright (C) 2022 Brodie Gaslam
##
## This file is part of "fansi - ANSI Control Sequence Aware String Functions"
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 2 or 3 of the License.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## Go to <https://www.r-project.org/Licenses> for copies of the licenses.

str01 <- sprintf("hello %sworld%s how", red, inv)

str02 <- sprintf("%shello world %sit's a %scrazy world%s out there %sisn't it%s%s right?", 
    grn.bg, red, end, rgb.und, inv, end, rgb.256)

[42mhello world [31mit's a [0mcrazy world[4;38;2;0;120;200m out there [7misn't it[0m[48;5;141m right?

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

# enable truecolor as not enabled by default

substr_ctl(str02, 15, 40, term.cap = term.cap)

substr_ctl(str02, 35, 60, term.cap = term.cap)

str03 <- sprintf("hello %sworld", rgb.und)

substr_ctl(str03, 1, 12, term.cap = term.cap)

str04 <- sprintf("hello%s%s world%s%s yowza", red, inv, grn.bg, 
    rgb.und)

substr_ctl(str04, 5, 7, term.cap = term.cap)

substr_ctl(str04, 5, 13, term.cap = term.cap)

str.m.0 <- paste0("\033[44m", c("hello world", rep("goodbye \033[45mmoon", 
    2), "yowza bombastic"), "\033[m")

substr2_ctl("yo\tworld", 1, 8, tabs.as.spaces = TRUE)

substr_ctl(list("hello", list("goodbye", "there")), 1, 2)

substr_ctl(structure(list(list("goodbye", "there")), class = "foo"), 
    1, 2)

substr_ctl(str.2, 3, 4, terminate = FALSE)

substr_ctl(str.2, 3, 5, terminate = FALSE)

substr_ctl(str.2, 4, 1, terminate = FALSE)

substr_ctl(str.2, 4, 1, carry = "\033[44m", terminate = FALSE)

Warning in substr2_ctl(x = x, start = start, stop = stop, warn = warn, term.cap = term.cap,  :
  NAs introduced by coercion
Warning in substr2_ctl(x = x, start = start, stop = stop, warn = warn, term.cap = term.cap,  :
  NAs introduced by coercion