On Thu, 23 Sep 2010, ZyX wrote:

Ответ на сообщение «Re: [BUG] getchar inside normal always returns an escape», присланное в 00:06:20 23 сентября 2010, Четверг, отправитель Benjamin R. Haskell:

Wrapping your file with:

redir > TESTmessages
" contents of test-normalesc.vim
redir END

the following seems to do what you want:

find ./ -maxdepth 1 -name 'TEST*' -delete
vi -u NONE -N +'so test-normalesc.vim' +'qa!' > TESTstdout 2> TESTstderr
head -n -0 TEST*

Actually no, since I want to check for contents of a buffer.

Maybe I'm misunderstanding the bug you're reporting? I thought the problem was with the string of '27's echoed. With the ':redir > TESTmessages', They end up in the file called TESTmessages. If you want to test the contents of the buffer, it can be written out, too:

# script has same ':redir' mod from before

# test command line adds 'w!' command
$ vi -u NONE -N +'so /test/sources/test-normalesc.vim' +'w! TESTbuffer' +'qa!' > 
TESTstdout 2> TESTstderr

# different output formatting
$ perl -lpwe '$_ = sprintf "%-20s%s", substr($ARGV,4), $_' TEST*
buffer          ars
err             Vim: Warning: Output is not to a terminal
messages
messages        27
messages        27
messages        27
messages        27
messages        27
messages        27
messages        27
messages        27
messages        27
messages        27
messages        10
out

That's the output I get whether running with the various redirections (vim-internal and shell) or just straight-up interactively. (Except I have to type ':messages<cr>' in order to see the 27's when just sourcing it from within vim.)

So, this is a failing test. If getchar() worked how you had expected in normal mode, the expected contents of TESTmessages would be:
99
104
97
114
115


Better solution is to use something like this (better because vim will be opened in a tty):

   #!/usr/bin/python
   # vim: set fileencoding=utf-8
   import pexpect
   vim=pexpect.spawn("vim", ["-c", "Tr3Command tof start"])
   vim.send("A$iii\x1B:call writefile(getline(1, line('$')), 'test', 'b')")
   f=open('test', 'r')
   result=f.read()
   f.close()
   if result!="∭":
       # Test failed

Right. That's a case that I was lumping under "interactive": a test that ensures that sending an exact sequence of "keystrokes" to Vim produces some defined output. Your 'getchar' example doesn't depend on the "keystrokes" from what I can tell.


But strace shows lots of EIO errors returned when vim tries to write something and I do not want to examine it now. I also failed to quickly write it using zsh/zpty module: zpty crashed for unknown reason. Maybe someone knows how to write it so that it will work.

The various bindings for 'expect' tackle part of the problem (sending and receiving data from programs designed only to deal with terminals). But for the rest, I still think there's a need for something more like Selenium-for-terminal-emulators.

Taking a look at zpty now. Zsh has been the first thing I install on systems for years, and it still constantly surprises me.

--
Best,
Ben

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Raspunde prin e-mail lui