wtfutil / wtf

The personal information dashboard for your terminal
http://wtfutil.com
Mozilla Public License 2.0
15.71k stars 799 forks source link

WTF doesn't seem to read data from SSH connection #1286

Open ReneFroger opened 2 years ago

ReneFroger commented 2 years ago

First, I would like to say how I appreciate your tool, it's awesome! However, I ran into a problem.

What's broken?

In any terminal, when you try ssh devzat.hackclub.com (from this nice package), it works fine.

But when you try to wrap that command into WTF task, you get a strange error:


panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/wtfutil/wtf/app.NewDisplay(0x327e1c0, 0x0, 0x0, 0xc0004554a0, 0x0)
    /Users/ccummer/go/src/github.com/wtfutil/wtf/app/display.go:23 +0x225
github.com/wtfutil/wtf/app.NewWtfApp(0xc0005eea00, 0xc0004554a0, 0x7ffdb04a2715, 0x31, 0x1)
    /Users/ccummer/go/src/github.com/wtfutil/wtf/app/wtf_app.go:46 +0x2ac
main.main()
    /Users/ccummer/go/src/github.com/wtfutil/wtf/main.go:70 +0x360

Sample of configuration where you can replicate this error:

wtf: 
    task:
      #term: "xterm-256color"
      #term: "aterm"
      type: cmdrunner
      cmd: "ssh"
      args: ["devzat.hackclub.com"]
      enabled: true
      refreshInterval: 25

The author of devzat thinks I should report it here, which I'm doing now. And frankly, I think it's related with wtfutil, because in all other terminals you will not see this kind of error. What could be causing this error, and how could we display such tools via SSH via wtfutil?

senorprogrammer commented 2 years ago

That's a cool use, and definitely looks like a bug reading the input. Thanks for reporting it!

Seanstoppable commented 2 years ago

I think this is to be expected. What is happening here is that you are starting up an interactive app, and WTFUtil is probably not getting any output to render. CmdRunner is really running a script every interval and is not an embedded terminal. If the command does not exist and/or the output can not be piped to another command, then I would not expect CmdRunner to work.

If you could somehow send the SIGINT as part of the SSH command to connect and disconnect, it MIGHT work as expected.

But if you want interactivity, you probably want to make this a window using an actual terminal window manager like tmux, screen or the various alternatives.

I am minimally going to replicate this behavior with a few other things and try to catch and display a more relevant description

ReneFroger commented 2 years ago

I appreciate that you're trying to replicate this behavior.

I have looked around how to send a SIGINT as part of SSH command. Based on this answer], I tried to replicate with:


      cmd: "ssh"
      args: ["devzat.hackclub", "\"sleep 99 < <(cat; kill -INT 0)\" <&1"]

But I got only error code 255 with it. I don't need interactivity, but only watching if some messages appear in the chat of WTFutil dashboard.

Seanstoppable commented 2 years ago

Yeah, partly likely due to the fact that you are connecting to the chat and not an expected ssh terminal.

I will call out that if this worked, what other people would see is that you've connected to the chat for a bit, then disconnected and reconnected.

senorprogrammer commented 2 years ago

@Seanstoppable's comment has reminded me that this has come up before, in other use-cases, for the very same reasons. CmdRunner is unlikely to solve the problem for you.

IMO WTF needs two new modules:

  1. A terminal. It would be very cool to have a functional terminal as a widget
  2. A CmdRunner-like module that doesn't run on a timer, but rather can accept streamed output data
Seanstoppable commented 2 years ago

I believe we actually have a 'tail mode', which might be 2?

But yeah, an actual terminal would be interesting.

I actually can't seem to replicate the crash mentioned in your original post @ReneFroger . I just realized I think part of the problem is a bad config. Should look more like:

wtf:
  mods:
    task:
      #term: "xterm-256color"
      #term: "aterm"
      type: cmdrunner
      cmd: "ssh"
      args: ["devzat.hackclub.com"]
      enabled: true
      refreshInterval: 25

If you add pty: true, you get some sort of output, which means that doing this might actually be possible.

I am going to have a fix for the bug you actually uncovered (we blow up if no modules defined).

ReneFroger commented 1 year ago

With the following setup:

    test:
      #term: "xterm-256color"
      #term: "aterm"
      type: cmdrunner
      cmd: "ssh"
      args: ["devzat.hackclub.com"]
      enabled: true
      pty: true
      position:
        top: 2
        left: 2
        height: 4
        width: 2
      refreshInterval: 25

I see this:

image

But when I do ssh devzat.hackclub.com in same terminal, I actually see the output:

image

Any suggestion where I might went wrong?

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.