Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Interactive line wrapping



Hello

I'm working on a command-line framework for Ruby (
https://github.com/ioquatix/samovar) and I've been wondering about the best
way to implement line wrapping, and wondering how this fits in with ZSH
since that's the shell I'm using predominantly.

Ideally, if you have a block of text, e.g.

    [--option] This option does this that and the other thing and several
other things.

If the user makes the terminal narrower, it would be wrapped, e.g.

    [--option] This option does this that and the other
thing and several other things.

However, this wrapping is not ideal. The ideal wrapping output would be
something like this:

    [--option] This option does this that and the other
               thing and several other things.

I see two ways to implement this:

1/ Detect the width of the terminal before outputting anything and manually
wrap the text.
2/ Implement a curses based output mechanism which supports interactively
re-flowing the text.
3/ Expecting the terminal to implement it somehow.

I was wondering if ZSH supports any method for interactive line wrapping?

In particular, even if I support 1 or 2 above, I was thinking to use a
special token \e[0;0m which would indicate a line wrapping marker. In the
case a line would wrap, the indentation would be that until the most
recently encountered wrapping marker. This could be used both in the
interactive case or non-interactive case. The above output would therefore
look like:

    *\e[0;0m*[--option] *\e[0;0m*This option does this that and the other
thing and several other things.

Any subsequent wrapping would happen at the most recent marker which was on
the original line.

It's still not clear to me several situations though:

a/ How to wrap words that are too long, use a hyphen?
b/ How to compute the indentation of multi-byte characters? Tabs?
Potentially rather than computing an indent using spaces, perhaps replace
the text with replacement whitespace characters, so that tabs, and wide
characters have the equivalent whitespace width.

Finally, I had the crazy idea that something like this could be implemented
directly at the terminal layer so that all applications could benefit from
it. It seems like a logical thing to have w.r.t. presentation of text, in
the presence of resizable terminals. Perhaps this already exists and I
don't know about it?

Any ideas or feedback would be most appreciated.

Kind regards,
Samuel


Messages sorted by: Reverse Date, Date, Thread, Author