From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18636 invoked by alias); 23 Sep 2013 19:26:59 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17991 Received: (qmail 22903 invoked from network); 23 Sep 2013 19:26:45 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at spodhuis.org designates 94.142.241.89 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=spodhuis.org; s=d201210; h=In-Reply-To:Content-Transfer-Encoding:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=F6EUlEXzRqAUlBU5LwgeYANfsqlXj2al0Kb4tR685a0=; b=Cfa1QpoRFfezh1SpdI5RuEmyFaoYaXq/K0jt59E1Rk7mC/6w/Mv92vpwj1AaHSBWbbSWfiYKC5GXWrnkaoN1F/NEze/L+t6/iN1n6CRFYUtwt8YLhLYCVM0cZx8o+k4p+G+Sor2Cwe7qM/7qSsJ/Bo0vV8wDs2OX6cRq/kwbLKI=; Date: Mon, 23 Sep 2013 12:26:33 -0700 From: Phil Pennock To: Larry Schrof Cc: "zsh-users@zsh.org" Subject: Re: Colored-character displayed on CTRL-C ? Message-ID: <20130923192633.GA47494@redoubt.spodhuis.org> Mail-Followup-To: Larry Schrof , "zsh-users@zsh.org" References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: OpenPGP: url=https://www.security.spodhuis.org/PGP/keys/0x3903637F.asc On 2013-09-23 at 17:37 +0000, Larry Schrof wrote: > Recent versions of bash have this very nifty feature where, when you hit CTRL-C to terminate a command line and get a new prompt on a new line, something like ^C with a yellow background is displayed to help remind you that the command is not actually executed. > > With my vision impairment, simply using the event number in my shell prompt is not sufficient. I'd really like ideas on the best way to tell zsh to display a character with a yellow background on CTRL-C, followed by taking me to a new prompt on the next line. > > I'm speculating this would start by setting up a trap on the right signal? Looking at the reason for the requirements, rather than the exact requirement stated, would it be helpful to instead update your prompt to show that the previous command was terminated with a signal, using a long name instead of just a number? In this sample below, the "{SIGINT}" is in red: -phil@redoubt:p1[11:55]17½(1006)~% sleep 3 ^C {SIGINT}-phil@redoubt:p1[12:07]17¼(1007)~% My prompt configuration includes: zmodload -i zsh/parameter || return 1 function prompt_pdp_precmd { local exitstatus=$? emulate -L zsh # ksh_arrays breaks us badly psvar=() # [...] psvar[1]=$exitstatus if [[ $exitstatus -ge 128 ]]; then psvar[1]=SIG${signals[$exitstatus-127]:-} [[ $psvar[1] == SIG ]] && psvar[1]=$exitstatus elif [[ $exitstatus -eq 127 ]]; then psvar[1]='127/CmdNotFound' # SUSv4 XCU 2.8.2 elif [[ $exitstatus -eq 126 ]]; then psvar[1]='126/CmdNotExecutable' # SUSv4 XCU 2.8.2 elif [[ $exitstatus -eq 125 ]]; then psvar[1]='125/GitBisectUntestable' # git fi # [... other stuff affecting psvar[2]..psvar[5]] return $exitstatus } Then part of the prompt configuration would, in more modern zsh idiom, include the string: %(?..%F{red}{%v}%f) So, if and only if the last command exited non-true, show {exitstatus} in the prompt, where that is a number if it was a non-signal exit, else a signal name, and some common special-meanings also shown. You could use psvar[2] to hold a colour name based upon the exitstatus, and embed that in the prompt; just note that %2v is not expanded inside a %F{...} so you would instead have to enable prompt_subst: setopt prompt_subst PS1='%(?..%F{$psvar[2]}%K{$psvar[3]}{%v}%k%f)%~%# ' That allows for psvar[2] holding a foreground colour and psvar[3] holding a background colour. % setopt prompt_subst % psvar=(SIGINT red yellow); false; print -P '%(?..%F{$psvar[2]}%K{$psvar[3]}{%v}%k%f)%~%# ' {SIGINT}~% (where that is showing "{SIGINT}" in red text on a yellow background). -Phil