zsh-workers
 help / color / mirror / code / Atom feed
* RE: (m)-flag for boundary cases
@ 2017-03-21 13:02 Sebastian Gniazdowski
  2017-04-02 22:57 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Sebastian Gniazdowski @ 2017-03-21 13:02 UTC (permalink / raw)
  To: zsh-workers

> Try this?  Works for characters that are 2 columns wide.  If you have
> a mix of character widths, probably a custom math function to use in the
> subscript ...
> 
> dw=3    # Desired width
> echo ${(mr:dw::_:)a[1,${(m)#a[1,dw-1]}>dw?dw/2:dw]}

Mixed character widths are possibile. Following cases can occur:

1. a="測試a句"; echo ${(mr:7:)a},
測試a句,

2. a="測試a句"; echo ${(mr:6:)a},
測試a句,

3. a="測試a句"; echo ${(mr:5:)a},
測試a,

4. a="測試a句"; echo ${(mr:4:)a},
測試,

Now a try with minus-one:
------------------------

1. a="測試a句"; echo ${(mr:7-1:)a},
測試a句,

2. a="測試a句"; echo ${(mr:6-1:)a},
測試a,

3. a="測試a句"; echo ${(mr:5-1:)a},
測試, # problem

4. a="測試a句"; echo ${(mr:4-1:)a},
測試,

So if one could fix the trailing-a absence, it seems it would work. Did following:

dw=5; a="測試a句"; echo ${(mr,${(m)#${(mr:dw:)a}[-1]} > 1 ? dw-1 : dw,)a}
測試a
dw=3; a="測試a句"; echo ${(mr,${(m)#${(mr:dw:)a}[-1]} > 1 ? dw-1 : dw,)a}
測

But not sure if I will commit this.

--
Sebastian Gniazdowski
psprint@zdharma.org


^ permalink raw reply	[flat|nested] 5+ messages in thread
* (m)-flag for boundary cases
@ 2017-03-20 14:33 Sebastian Gniazdowski
  2017-03-20 16:00 ` Sebastian Gniazdowski
  2017-03-20 16:43 ` Bart Schaefer
  0 siblings, 2 replies; 5+ messages in thread
From: Sebastian Gniazdowski @ 2017-03-20 14:33 UTC (permalink / raw)
  To: zsh-workers

Hello,

% a="漢字"
% echo ${(mr:3::_:)a}
漢字
% echo ${(mr:2::_:)a}
漢

I think it would be better to trim first case down to single Asian
character, and display: 漢_. The point is that it gives predictable
width. Current version is occasionally 1 character too long.

I wonder how many people use (m)-flag. Never seen it mentioned here. I
think that nobody wants the off-by-1 behavior, and fixing it will not
break things, but make them automatically better, like for me – the flag
turned out to be a necessity and a solution, with acceptable off-by-1
problem, which will be automatically fixed by Zsh update. I've added
Asian characters support to ZUI via the flag, most important use case is
the (r) padding, but also good cooperation with (P) flag.

-- 
  Sebastian Gniazdowski
  psprint3@fastmail.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-04-02 22:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-21 13:02 (m)-flag for boundary cases Sebastian Gniazdowski
2017-04-02 22:57 ` Bart Schaefer
  -- strict thread matches above, loose matches on Subject: below --
2017-03-20 14:33 Sebastian Gniazdowski
2017-03-20 16:00 ` Sebastian Gniazdowski
2017-03-20 16:43 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).