vsh icon indicating copy to clipboard operation
vsh copied to clipboard

trying to execute a second command in vsh fails

Open Ccode-lang opened this issue 3 years ago • 34 comments

Ccode-lang avatar Jun 13 '21 16:06 Ccode-lang

Do you have any more details to replicate? It seems to work for me

jacobsalmela avatar Jun 14 '21 13:06 jacobsalmela

Type any command and then type any command again. It will not record the second command or any command after it.

Ccode-lang avatar Jun 14 '21 14:06 Ccode-lang

Example

v# echo hi hi v# echo hi

Ccode-lang avatar Jun 14 '21 14:06 Ccode-lang

After this example is executed it will not run "echo hi" the second time, it just goes to the next line and does not show "v#" prompt. Any commands given to the broken prompt doesn't run.

Ccode-lang avatar Jun 14 '21 14:06 Ccode-lang

It might also be that I am on macOS.

Ccode-lang avatar Jun 14 '21 14:06 Ccode-lang

I'm on Mac, too, but I also haven't updated V for some time.. maybe something broke there. I'll check and let you know.

jacobsalmela avatar Jun 14 '21 17:06 jacobsalmela

Ok 👍

Ccode-lang avatar Jun 14 '21 18:06 Ccode-lang

Tell me when you find the problem.

Ccode-lang avatar Jun 14 '21 19:06 Ccode-lang

Confirmed this works for me with: V 0.2.2 8547762. My HEAD is at 8547762ab.

Welcome to v shell!
v# echo hi
hi
v# echo it works
it works
v# echo something else
something else
v# jacobsalmela:~/vsh (main)$

Time for some bisecting...

jacobsalmela avatar Jun 19 '21 12:06 jacobsalmela

jacobsalmela:~/vlang ((no branch, bisect started on master))$ git bisect good
453fb1b08b7bcce8ef86c175aa3b1179f4a01c2e is the first bad commit
commit 453fb1b08b7bcce8ef86c175aa3b1179f4a01c2e
Author: Delyan Angelov <[email protected]>
Date:   Tue May 18 11:59:57 2021 +0300

    term.ui: use os.signal_opt instead of os.signal

 vlib/os/signal.c.v                  | 66 ++++++++++++++++++++-----------------
 vlib/term/ui/consoleapi_windows.c.v |  2 --
 vlib/term/ui/input.v                |  6 ++--
 vlib/term/ui/input_windows.c.v      |  4 +--
 vlib/term/ui/termios_nix.c.v        | 18 ++++++----
 5 files changed, 53 insertions(+), 43 deletions(-)

@spytheman has helped me out before on this repo...maybe he knows quickly what broke it?

jacobsalmela avatar Jun 19 '21 12:06 jacobsalmela

Still trying to look at this.

jacobsalmela avatar Jun 24 '21 11:06 jacobsalmela

@Ccode-lang that PR above works for this issue if you need an immediate workaround. Otherwise, I'm sure there's an error in my code somewhere.

jacobsalmela avatar Jun 28 '21 01:06 jacobsalmela

Ok thank you. 👍

Ccode-lang avatar Jun 28 '21 12:06 Ccode-lang

using this only gives an error message that says:

vsh.v:18:8: warning: module 'io' is imported but never used
   16 | import os { input, exec, user_os, join_path home_dir }
   17 | import term.ui as tui
   18 | import io
      |        ~~
   19 | 
   20 | struct Vsh {
vsh.v:275:5: warning: unused variable: `cmd_args`
  273 |                 is_builtin := cmd.split(' ')[0]
  274 |                 // get the rest of the string which will be the args
  275 |                 cmd_args := cmd.split(' ')[1..]
      |                 ~~~~~~~~
  276 |                 match is_builtin {
  277 |                     // only use the first arg since you can't be in two dirs at once
vsh.v:16:20: error: module `os` has no constant or function `exec`
   14 | */
   15 | 
   16 | import os { input, exec, user_os, join_path home_dir }
      |                    ~~~~
   17 | import term.ui as tui
   18 | import io
vsh.v:285:19: error: unknown function: os.exec
  283 |                     // run the command the user entered
  284 |                     // TODO: move this all to a function and make it more resilient
  285 |                     output := os.exec(cmd) or {
      |                                  ~~~~~~~~~
  286 |                         buffer.put('\n$err')
  287 |                         buffer.put('v# ')
vsh.v:299:28: error: `void` type has no fields
  297 | 
  298 |                     // display it's output
  299 |                     buffer.put('\n$output.output')
      |                                           ~~~~~~
  300 | 
  301 |                     // return the prompt so another command can be entered

Ccode-lang avatar Jun 28 '21 15:06 Ccode-lang

i'll open pull to fix this

Ccode-lang avatar Jun 28 '21 15:06 Ccode-lang

Using your version of v still opens the broken prompt it must be an error in the code somewhere.

Ccode-lang avatar Jun 28 '21 15:06 Ccode-lang

It seems like the event() function is not getting executed in a loop.

Ccode-lang avatar Jun 28 '21 15:06 Ccode-lang

Yes, I just tried your PR, #25 and the issue still exists. Let me play with what you've put together and I'll see if I can track down the issue.

jacobsalmela avatar Jun 29 '21 11:06 jacobsalmela

Ok 👍

Ccode-lang avatar Jun 29 '21 16:06 Ccode-lang

It seems like the event() function is not getting executed in a loop.

Well, some of the other events in the loop work. If you press down a bunch of times, it works fine. I think the issue is related term.ui and/or os modules. I have workarounds but not a permanent fix. I'll push what I have for some unrelated parts though to simply updating the code for the recent v changes.

jacobsalmela avatar Jul 07 '21 00:07 jacobsalmela

Ok, I will try it now

Ccode-lang avatar Jul 07 '21 01:07 Ccode-lang

the issue is still there but you said there were workarounds. what are they exactly?

Ccode-lang avatar Jul 17 '21 17:07 Ccode-lang

Yeah, I know. I haven't been able to crack it yet.

Workarounds are here:

https://github.com/vlang/v/pull/10569#issuecomment-881912000

jacobsalmela avatar Jul 17 '21 18:07 jacobsalmela

You can also use os.system but it's not useful since it only returns a return code...Though this may be the place to look to see why os.execute hangs up

jacobsalmela avatar Jul 18 '21 00:07 jacobsalmela

ok thanks!

Ccode-lang avatar Jul 18 '21 20:07 Ccode-lang

I found also running v -o vsh.c vsh.v && gcc -o vsh vsh.c worked better than building with v.

Ccode-lang avatar Jul 20 '21 17:07 Ccode-lang

how do you kill the run thou. It keeps trying to track my mouse after running

Ccode-lang avatar Jul 20 '21 17:07 Ccode-lang

nevermind found it out

Ccode-lang avatar Jul 20 '21 17:07 Ccode-lang

found using this file with modified v worked vsh.txt

Ccode-lang avatar Jul 20 '21 17:07 Ccode-lang

I'll open a pull with it to make a temporary fix

Ccode-lang avatar Jul 20 '21 17:07 Ccode-lang