docopt.R icon indicating copy to clipboard operation
docopt.R copied to clipboard

ANSI control sequences not compatible with docopt parsing

Open madsheilskov opened this issue 4 years ago • 0 comments

It would be very neat if docopt::docopt parsing of the "doc"( "help") string would allow for formating using ANSI control sequences. docopt seems to be confused when it matches the square ( [ and ] ) parentheses around the expected "Usage" and "Options" patterns. This works fine (giving me a boldface and underlined header when I issue ./test.R --help in the command ubuntu command prompt):

` #!/usr/bin/env Rscript " \033[1;4mTest ANSI in R scripts using docopt.\033[0m

Usage:

test.R [--par=PAR] test.R -h | --help

Options: --par=PAR The parameter. -h --help Show help. " -> doc

suppressWarnings(suppressMessages(require(docopt))) opt <- docopt(doc) `

However, now I would like to boldface, say, both "Usage:" and "Options:" like this: ` #!/usr/bin/env Rscript " \033[1;4mTest ANSI in R scripts using docopt.\033[0m \033[1m Usage: \033[0m test.R [--par=PAR] test.R -h | --help \033[1m Options: \033[0m --par=PAR The parameter. -h --help Show help. " -> doc

suppressWarnings(suppressMessages(require(docopt))) opt <- docopt(doc) `

Then I get the error Unmatched [ (from docopt parsing)

It works fine when only either "Usage:" or "Options:" are embedded in ANSI.

madsheilskov avatar Jun 29 '21 12:06 madsheilskov