Sunday, January 8, 2017

Re: Issue with using gvim system() and fzy

2017-01-09 0:18 GMT+03:00 Gary Johnson <garyjohn@spocom.com>:
> On 2017-01-08, justrajdeep wrote:
>> On Saturday, January 7, 2017 at 1:20:14 PM UTC-5, Gary Johnson wrote:
>> > On 2017-01-07, Justin M. Keyes wrote:
>> >
>> > > On Jan 6, 2017 17:09, "justrajdeep" wrote:
>> >
>> > >> Having an issue while doing a system() call with fzy(https://github.com/
>> > >> Dkendal/fzy-vim)from inside gvim
>> > >>
>> > >> Code snippet
>> > >>
>> > >> silent let output = system("ag -l -g '' --nocolor | fzy")
>> > >>
>> > >> Decho(1)
>> > >> Decho (output)
>> > >> Decho(2)
>> > >> Decho(3)
>> > >>
>> > >>
>> > >> The output is
>> > >>
>> > >> 1
>> > >> Failed to open /dev/tty^J
>> > >> 2
>> > >> 3
>> > >>
>> > >>
>> > >> If i remove fzy from the command the result is fine. Can someone please
>> > >> help me debugging the issue?
>> >
>> > > Most likely, fzy wants to write to a tty, not a file.
>> >
>> > Looking at the web page https://github.com/jhawthorn/fzy, it's
>> > pretty clear that fzy writes directly to a terminal, separately from
>> > its stdout, which vim running in a termina provides, but which gvim
>> > doesn't.
>> >
>> > Regards,
>> > Gary
>>
>>
>> Thanks Gary,
>>
>> Can you please point me to the details of this in vim help or
>> somewhere? Sorry I am new to vim programming and would like to
>> understand the difference and try to see if I can somehow get it
>> working.
>
> Hi Rajdeep,
>
> I couldn't find a very detailed explanation in the Vim help. There
> is a little bit here.
>
> :help gui-pty
>
> I originally thought the problem was just that the terminal
> emulation provided by gvim lacked some of the capabilities needed by
> fzy, but that's not what fzy is complaining about when it says it
> "Failed to open /dev/tty".
>
> fzy assumes that it is running in a terminal and that this terminal
> can be accessed by the device name /dev/tty. That is true when fzy
> is run from the shell executed by a terminal emulator or by vim's or
> gvim's :sh command, and it is true when fzy is run from the shell
> executed by vim's system() function, but it is not true when fzy is
> run from the shell executed by gvim's system() function.
>
> You can see that by running "tty < /dev/tty" in those environments.
> In all cases but one the command prints "/dev/tty". When run in
> a system() function from within gvim, the results are different:
>
> :echo system("tty < /dev/tty")
> /bin/bash: /dev/tty: No such device or address
>
> But you _can_ send output from a system() command to the pty that
> gvim creates for shell commands.
>
> :!tty
> /dev/pts/16
> :call system("ls > /dev/pts/16")
>
> So, if one could coerce gvim or the shell into creating a /dev/tty
> for programs run from system() in a GUI environment, as is done now
> for :! and :sh, then your fzy command should work.
>
> I don't know why gvim's system() doesn't do that already.

This is too much work: basically you need to reimplement terminal
emulator and somehow integrate it with the rest of the UI. You should
rather ask why Vim does not follow Neovim way which intentionally
disallows access to /dev/tty from system() or :! so a set of dirty,
unportable hacks do not work (hacks require both terminal Vim and
*nix).

Note that GVim does not provide fully featured terminal emulator. Do
not try to write just `ls` output there, try using something which
emits control sequences which change color or move cursor: both are
required for fzy to work and "terminal emulator" attached to the
pseudo-terminal created by GVim will fail interpreting them correctly.

>
> Regards,
> Gary
>
> --
> --
> You received this message from the "vim_use" 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
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
--
You received this message from the "vim_use" 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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: