Skip to content

Commit

Permalink
fix(logs): dont show proxy connections dashboard/table when a TTY is …
Browse files Browse the repository at this point in the history
…not attached on client side

If a tty is not attached on client side, the proxy connections dashboard (a table of size of proxy
connections categorized by each domain) would not shown in log view.
ref #9.
  • Loading branch information
genshen committed May 4, 2020
1 parent 86ada78 commit 4d39558
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/genshen/wssocks/wss/term_view"
"github.com/gorilla/websocket"
log "github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh/terminal"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -178,13 +179,16 @@ func (c *client) Run() error {
}()

record := wss.NewConnRecord()
plog := term_view.NewPLog(record)
log.SetOutput(plog) // change log stdout to plog
if terminal.IsTerminal(int(os.Stdout.Fd())) {
// if it is tty, use term_view as output, and set onChange function to update output
plog := term_view.NewPLog(record)
log.SetOutput(plog) // change log stdout to plog

record.OnChange = func() {
// update log
plog.SetLogBuffer(record) // call Writer.Write() to set log data into buffer
plog.Writer.Flush(nil) // flush buffer
record.OnChange = func() {
// update log
plog.SetLogBuffer(record) // call Writer.Write() to set log data into buffer
plog.Writer.Flush(nil) // flush buffer
}
}

// http listening
Expand Down

0 comments on commit 4d39558

Please sign in to comment.