On Fri, Jun 19, 2020 at 7:02 PM Marc Nieper-Wißkirchen <xxxxxx@nieper-wisskirchen.de> wrote:
Am Do., 18. Juni 2020 um 15:38 Uhr schrieb Alex Shinn <xxxxxx@gmail.com>:
On Tue, Jun 16, 2020 at 6:14 PM Marc Nieper-Wißkirchen <xxxxxx@nieper-wisskirchen.de> wrote:

Can't we just repair this? The mechanism we have to use to repair this may also be of interest to other (user-provided) formatters. Wouldn't it help to make the underlying splitters (and trimmers) parameters (state variables) parameterizable and provide special (slower) versions that split/trim escapes/unicode strings correctly and which can be installed by the user?

Sure, patches accepted, I may fix this if I have time, but given how marginal it is it's not a high priority.

I don't necessarily think an underlying state variable is the right solution, so I don't think this affects the spec.

Splitting and trimming procedures have to be compatible to string-width.  String-width is a state variable (we have a simple version and a Unicode and ANSI-aware version).  Thus we need to be able to set the splitting and trimming primitives according to how we set the string-width state variable.  I don't see how to do this without exposing these state variables, which is anyway not a bad thing.

The problem is I'm not sure what the correct specification is, and don't
want to delay the SRFI further to over-specify something that can only
be achieved by bypassing the API and manually encoding ANSI escapes.

Trimming is a separate issue, and not necessarily solved in the same manner.
Your proposal from before was to provide a `string-trim` state variable, which doesn't
help here.

Getting back to that issue, what is the correct behavior of `trimmed` in the presence of ANSI escapes?

Stripping everything except ANSI escapes should leave the terminal in the
correct state (at least the same state as if no trimming took place), but it's
expensive and not applicable to `trimmed/lazy`.  This underlying trim
procedure is already a utility so we would just need to export it as a state
variable.  This could be useful for other things, e.g. for trimming by word.

`trimmed/lazy` could preserve and restore the terminal colors, only if it
knows about them.  This would imply ANSI escape handling is builtin,
which I'm not a fan of.  I would suggest just noting that ANSI escapes
may not be restored cleanly (though they will always be handled as a unit)
in the docs for `trimmed/lazy`.

--
Alex