I noticed that Fedora and OpenSUSE (likely others) add a patch to
Coreutils for 'fold --characters'. Not sure if that option has been
discussed here.
Anyways, I wrote the following patch which is much simpler than the one
they use, in my opinion. The mbfile module from Gnulib provides a
similar interface to stdio's getc. When operating on ascii characters it
does not call mbrtoc32, etc.
Here is an example of the behavior using λ which has a width of two
columns:
$ for i in $(seq 10); do printf '\uB250' >> test.txt; done
$ printf '\n' >> test.txt
$ cat test.txt
λλλλλλλλλλ
$ ./src/fold -w 5 test.txt
λλ
λλ
λλ
λλ
λλ
$ ./src/fold --characters -w 5 test.txt
λλλλλ
λλλλλ
What do you think?
It would be nice to improve unicode support and this was an easy
start. Something like 'tr' is much more difficult.
Collin