## Copyright (C) 2021  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.

local({
    tc <- getOption("fansi.term.cap")
    col <- Sys.getenv("COLORTERM", unset = NA)
    on.exit({
        options(fansi.term.cap = tc)
        if (is.na(col)) suppressWarnings(Sys.unsetenv("COLORTERM")) else Sys.setenv(COLORTERM = col)
    })
    options(fansi.term.cap = NULL)
    suppressWarnings(Sys.unsetenv("COLORTERM"))
    string <- "a\033[38;2;50;50;50m"
    substr_ctl(c(string, ""), 1, 10)
    Sys.setenv(COLORTERM = "truecolor")
    substr_ctl(c("", string), 1, 10)
})

Argument `x` contains a CSI SGR sequence with color codes not supported by terminal at index [1], see `?unhandled_ctl`; you can use `warn=FALSE` to turn off these warnings.

Warning in substr_ctl_internal(x, start = start, stop = stop, type.int = TYPE.INT,  :
  Argument `x` contains a CSI SGR sequence with color codes not supported by terminal at index [1], see `?unhandled_ctl`; you can use `warn=FALSE` to turn off these warnings.

Integer overflow in file utils.c at line 99; contact maintainer.

Error in fansi:::add_int(2^31 - 1, 1) : 
  Integer overflow in file utils.c at line 99; contact maintainer.

Error in fansi:::add_int(-2^31 + 1, -1) : 
  Integer overflow in file utils.c at line 99; contact maintainer.

index start stop             error translated        esc
1     2     4    9    invalid-substr      FALSE  \033[22>m
2     3     1    6    invalid-substr      FALSE  \033[999m
3     4     5   11    invalid-substr      FALSE \033[31#3m
4     5     2    6 non-SGR/hyperlink      FALSE   \033[31k
5     6     6    7       non-CSI/OSC      FALSE      \033m