From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28473 invoked by alias); 19 May 2016 21:21:11 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 38518 Received: (qmail 27162 invoked from network); 19 May 2016 21:21:10 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 Date: Thu, 19 May 2016 21:14:27 +0000 From: Daniel Shahaf To: Hong Xu Cc: Zsh hackers list Subject: Re: Feature request: readline's completion-prefix-display-length option Message-ID: <20160519211427.GA11264@tarsus.local2> References: <5738124C.7020705@topbug.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Bart Schaefer wrote on Sun, May 15, 2016 at 04:50:50 -0700: > On Sat, May 14, 2016 at 11:08 PM, Hong Xu wrote: > > > > I believe that readline's completion-prefix-display-length is a great > > option to have for zle. This option enables the common part of long > > completions to be represented by ellipsis, so the options in the > > completion list would not be too long in many cases. > > There might be a deviously clever way to do this with the list-colors > style, similar to the way that show-ambiguity is implemented. Like this? [[[ $ zsh -f % autoload compinit && compinit % zstyle -e ':completion:*' list-colors $'reply=( "=(#b)(${(b)PREFIX})(?)([^ ]#)*=0=33=${#PREFIX}D…\e[34=33" )' % rsync --no- …D -- turn off --devices and --specials …blocking-io -- turn off --blocking-io …detach -- do not detach from the parent …devices -- turn off --devices …dirs …d -- turn off --dirs …group …g -- turn off --group …hard-links …H -- turn off --hard-links ]]] This is simply a bobby tables solution: - The xterm control sequence for coloring is «\e[42m». - The xterm control sequence for "move left" is «\e[42D». - Setting the part between the two '=' signs to «42Dfoobar\e[43» causes the cursor to move left 42 spaces (over the common prefix already output), insert "foobar", and switch to color number 43. (reference: http://invisible-island.net/xterm/ctlseqs/ctlseqs.html) This solution breaks alignment¹ since zle doesn't account for the cursor movement; a workaround for that is to add padding: [[[ % zstyle -e ':completion:*' list-colors $'reply=( "=(#b)(${(b)PREFIX})(?)([^ ]#)*=0=33=${#PREFIX}D${(r:$#PREFIX-1:: :):-}…\e[34=33" )' % rsync --delete --delete -- delete files that do not exist on the sending side …-before -- receiver deletes before transfer …-delay …-after -- receiver deletes after transfer …-during -- receiver deletes during transfer …-excluded -- also delete excluded files on the receiving side …-missing-args -- delete missing source args from destination ]]] However, this workaround doesn't make the listing occupy less columns, which was the original request. Cheers, Daniel ¹ Alignment is broken in two cases: (a) when both ${PREFIX} and ${PREFIX}foo are possible completions; (b) when some completions have the same description as each other and are shown together. If ${PREFIX} is a proper prefix of all possible completions and all descriptions are unique, the listing will be aligned, but descriptions will not use the full terminal width.