zsh-users
 help / color / mirror / code / Atom feed
* Automate keypresses
@ 2019-03-30 16:47 Christian K
  2019-03-30 17:55 ` Daniel Shahaf
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Christian K @ 2019-03-30 16:47 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 311 bytes --]

Hey,

I'm trying to automate a benchmark for prompt render times with
https://github.com/romkatv/zsh-prompt-benchmark. This requires a pressed
Enter key to work.

Is there a way so simulate key presses without using something like expect?
Ideally this would also work in something like travis.

Best,
Christian

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

* Re: Automate keypresses
  2019-03-30 16:47 Automate keypresses Christian K
@ 2019-03-30 17:55 ` Daniel Shahaf
  2019-03-30 20:09   ` Ben Klein
  2019-03-30 20:15 ` Bart Schaefer
  2019-03-30 21:59 ` scowles ckhb.org
  2 siblings, 1 reply; 6+ messages in thread
From: Daniel Shahaf @ 2019-03-30 17:55 UTC (permalink / raw)
  To: Christian K, zsh-users

Christian K wrote on Sat, 30 Mar 2019 16:49 +00:00:
> I'm trying to automate a benchmark for prompt render times with
> https://github.com/romkatv/zsh-prompt-benchmark. This requires a pressed
> Enter key to work.
> 
> Is there a way so simulate key presses without using something like expect?
> Ideally this would also work in something like travis.

Do you mean this? —

$ { echo PS1=foo; echo exit } | zsh -ifs
bar% %
foo %
$ 

(Those percent signs are from the PROMPT_SP option)

Cheers,

Daniel

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

* Re: Automate keypresses
  2019-03-30 17:55 ` Daniel Shahaf
@ 2019-03-30 20:09   ` Ben Klein
  2019-03-30 22:07     ` Ben Klein
  0 siblings, 1 reply; 6+ messages in thread
From: Ben Klein @ 2019-03-30 20:09 UTC (permalink / raw)
  To: Daniel Shahaf, Christian K, Zsh Users

[-- Attachment #1: Type: text/plain, Size: 957 bytes --]

I think the real issue here is that such input would need to also execute
the precmd and other shell hooks as if a human were physically pressing
enter.

*\Ben Klein*
About: https://unhexium.net/about/
Other places online: https://unhexium.net/ll/
Contact me securely: https://keybase.io/robobenklein


On Sat, Mar 30, 2019 at 1:56 PM Daniel Shahaf <d.s@daniel.shahaf.name>
wrote:

> Christian K wrote on Sat, 30 Mar 2019 16:49 +00:00:
> > I'm trying to automate a benchmark for prompt render times with
> > https://github.com/romkatv/zsh-prompt-benchmark. This requires a pressed
> > Enter key to work.
> >
> > Is there a way so simulate key presses without using something like
> expect?
> > Ideally this would also work in something like travis.
>
> Do you mean this? —
>
> $ { echo PS1=foo; echo exit } | zsh -ifs
> bar% %
> foo %
> $
>
> (Those percent signs are from the PROMPT_SP option)
>
> Cheers,
>
> Daniel
>

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

* Re: Automate keypresses
  2019-03-30 16:47 Automate keypresses Christian K
  2019-03-30 17:55 ` Daniel Shahaf
@ 2019-03-30 20:15 ` Bart Schaefer
  2019-03-30 21:59 ` scowles ckhb.org
  2 siblings, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2019-03-30 20:15 UTC (permalink / raw)
  To: Christian K; +Cc: Zsh Users

On Sat, Mar 30, 2019 at 9:49 AM Christian K <syphdias@gmail.com> wrote:
>
> I'm trying to automate a benchmark for prompt render times with
> https://github.com/romkatv/zsh-prompt-benchmark. This requires a pressed
> Enter key to work.
>
> Is there a way so simulate key presses without using something like expect?

Since this is expected to run in an interactive shell, you probably
want something like this:

benchmark-prompt() {
  # adjust number of repeats as necessary
  repeat 100 zle -U $'\n'
  zle -U $'zsh-prompt-benchmark 5 0\n'
}
zle -N benchmark-prompt

Then invoke with M-x benchmark-prompt RET

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

* Re: Automate keypresses
  2019-03-30 16:47 Automate keypresses Christian K
  2019-03-30 17:55 ` Daniel Shahaf
  2019-03-30 20:15 ` Bart Schaefer
@ 2019-03-30 21:59 ` scowles ckhb.org
  2 siblings, 0 replies; 6+ messages in thread
From: scowles ckhb.org @ 2019-03-30 21:59 UTC (permalink / raw)
  To: Christian K, zsh-users

[-- Attachment #1: Type: text/plain, Size: 1014 bytes --]


>     On March 30, 2019 at 9:47 AM Christian K < syphdias@gmail.com mailto:syphdias@gmail.com > wrote:
> 
> 
>     Hey,
> 
>     I'm trying to automate a benchmark for prompt render times with
>     https://github.com/romkatv/zsh-prompt-benchmark. This requires a pressed
>     Enter key to work.
> 
>     Is there a way so simulate key presses without using something like expect?
>     Ideally this would also work in something like travis.
> 
>     Best,
>     Christian
> 

i believe pcmd may be the kind of utility you are looking for.  this is the header info citing attribution:

* pcmd: Push characters into tty input buffer.
*
* 1988-09 John H. DuBois III (john@armory.com)
* 1989-03-13 Last BSD version
* 2002-03-18 UnixWare port. Use getopt.
* 2004-05-10 Linux & MacOS X port. Use termios.

i routinely use this on linux, bsd, macos.  if you have trouble finding a source repository for it, pm me.


s. cowles
scowles at ckhb dot org
Key fingerprint = A156 277B 875A D6E3 A00C 23D9 869E 72BE 1FD3 5B80

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

* Re: Automate keypresses
  2019-03-30 20:09   ` Ben Klein
@ 2019-03-30 22:07     ` Ben Klein
  0 siblings, 0 replies; 6+ messages in thread
From: Ben Klein @ 2019-03-30 22:07 UTC (permalink / raw)
  To: Daniel Shahaf, Christian K, Zsh Users

[-- Attachment #1: Type: text/plain, Size: 1561 bytes --]

My bad - precmd does indeed get executed, but it seems that I am not
getting $RPROMPT rendered when using `zsh -is`.

Also, why do we get PROMPT_SP behaviour there and not in real interactive
use? Is there any option to echo the stdin input when it's being used? (vs
all at once before any prompts are rendered?)

*\Ben Klein*
About: https://unhexium.net/about/
Other places online: https://unhexium.net/ll/
Contact me securely: https://keybase.io/robobenklein


On Sat, Mar 30, 2019 at 4:09 PM Ben Klein <robobenklein@gmail.com> wrote:

> I think the real issue here is that such input would need to also execute
> the precmd and other shell hooks as if a human were physically pressing
> enter.
>
> *\Ben Klein*
> About: https://unhexium.net/about/
> Other places online: https://unhexium.net/ll/
> Contact me securely: https://keybase.io/robobenklein
>
>
> On Sat, Mar 30, 2019 at 1:56 PM Daniel Shahaf <d.s@daniel.shahaf.name>
> wrote:
>
>> Christian K wrote on Sat, 30 Mar 2019 16:49 +00:00:
>> > I'm trying to automate a benchmark for prompt render times with
>> > https://github.com/romkatv/zsh-prompt-benchmark. This requires a
>> pressed
>> > Enter key to work.
>> >
>> > Is there a way so simulate key presses without using something like
>> expect?
>> > Ideally this would also work in something like travis.
>>
>> Do you mean this? —
>>
>> $ { echo PS1=foo; echo exit } | zsh -ifs
>> bar% %
>> foo %
>> $
>>
>> (Those percent signs are from the PROMPT_SP option)
>>
>> Cheers,
>>
>> Daniel
>>
>

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

end of thread, other threads:[~2019-03-30 22:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-30 16:47 Automate keypresses Christian K
2019-03-30 17:55 ` Daniel Shahaf
2019-03-30 20:09   ` Ben Klein
2019-03-30 22:07     ` Ben Klein
2019-03-30 20:15 ` Bart Schaefer
2019-03-30 21:59 ` scowles ckhb.org

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).