gottyclient

package module
v1.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2021 License: MIT Imports: 20 Imported by: 16

README

gotty-client

🔧 Terminal client for GoTTY.

Build Status GoDoc FOSSA Status Sourcegraph

                                                              +----------------+
               +--------------+                +---------+--->|   /bin/bash    |
               |              |                |         |    +----------------+
           +-->|   Browser    |--+             |         |
+-------+  |   |              |  |             |         |
|       |  |   +--------------+  |             |         |    +----------------+
|  Bob  |--+                     +-websocket-->|  Gotty  |--->| emacs /var/www |
|       |  |    XXXXXXXXXXXXXX   |             |         |    +----------------+
+-------+  |   X              X  |             |         |
           +-->X gotty-client X--+             |         |
               X              X                |         |    +----------------+
                XXXXXXXXXXXXXX                 +---------+--->|  tmux attach   |
                                                              +----------------+

Example

Server side (GoTTY)

$ gotty -p 9191 sh -c 'while true; do date; sleep 1; done'
2015/08/24 18:54:31 Server is starting with command: sh -c while true; do date; sleep 1; done
2015/08/24 18:54:31 URL: http://[::1]:9191/
2015/08/24 18:54:34 GET /ws
2015/08/24 18:54:34 New client connected: 127.0.0.1:61811
2015/08/24 18:54:34 Command is running for client 127.0.0.1:61811 with PID 64834
2015/08/24 18:54:39 Command exited for: 127.0.0.1:61811
2015/08/24 18:54:39 Connection closed: 127.0.0.1:61811
...

Client side

$ gotty-client http://localhost:9191/
INFO[0000] New title: GoTTY - sh -c while true; do date; sleep 1; done (jean-michel-van-damme.local)
WARN[0000] Unhandled protocol message: json pref: 2{}
Mon Aug 24 18:54:34 CEST 2015
Mon Aug 24 18:54:35 CEST 2015
Mon Aug 24 18:54:36 CEST 2015
Mon Aug 24 18:54:37 CEST 2015
Mon Aug 24 18:54:38 CEST 2015
^C

Usage

$ gotty-client -h
NAME:
   gotty-client - GoTTY client for your terminal

USAGE:
   gotty-client [global options] command [command options] GOTTY_URL

AUTHOR:
   Manfred Touron <https://github.com/moul/gotty-client>

COMMANDS:
     help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --debug, -D                  Enable debug mode [$GOTTY_CLIENT_DEBUG]
   --skip-tls-verify            Skip TLS verify [$SKIP_TLS_VERIFY]
   --use-proxy-from-env         Use Proxy from environment [$USE_PROXY_FROM_ENV]
   --detach-keys value          Key sequence for detaching gotty-client (default: "ctrl-p,ctrl-q")
   --v2                         For Gotty 2.0 [$GOTTY_CLIENT_GOTTY2]
   --ws-origin value, -w value  WebSocket Origin URL [$GOTTY_CLIENT_WS_ORIGIN]
   --help, -h                   show help
   --version, -v                print the version

Install

Install latest version using Golang (recommended):

git clone https://github.com/moul/gotty-client
cd gotty-client
make install # or `go install ./cmd/gotty-client`

PS: I don't know why, but go get github.com/moul/gotty-client/cmd/gotty-client is not stable everywhere


Install latest version using Homebrew (Mac OS X)

$ brew install https://raw.githubusercontent.com/moul/gotty-client/master/contrib/homebrew/gotty-client.rb --HEAD

or the latest released version

$ brew install https://raw.githubusercontent.com/moul/gotty-client/master/contrib/homebrew/gotty-client.rb

Changelog

See https://github.com/moul/gotty-client/releases

License

MIT

Documentation

Index

Constants

View Source
const (
	OutputV1         = '0'
	PongV1           = '1'
	SetWindowTitleV1 = '2'
	SetPreferencesV1 = '3'
	SetReconnectV1   = '4'

	InputV1          = '0'
	PingV1           = '1'
	ResizeTerminalV1 = '2'
)

message types for gotty

View Source
const (
	// Unknown message type, maybe set by a bug
	UnknownOutput = '0'
	// Normal output to the terminal
	Output = '1'
	// Pong to the browser
	Pong = '2'
	// Set window title of the terminal
	SetWindowTitle = '3'
	// Set terminal preference
	SetPreferences = '4'
	// Make terminal to reconnect
	SetReconnect = '5'

	// Unknown message type, maybe sent by a bug
	UnknownInput = '0'
	// User input typically from a keyboard
	Input = '1'
	// Ping to the server
	Ping = '2'
	// Notify that the browser size has been changed
	ResizeTerminal = '3'
)

message types for gotty v2.0

Variables

View Source
var ASCII = []string{
	"ctrl-@",
	"ctrl-a",
	"ctrl-b",
	"ctrl-c",
	"ctrl-d",
	"ctrl-e",
	"ctrl-f",
	"ctrl-g",
	"ctrl-h",
	"ctrl-i",
	"ctrl-j",
	"ctrl-k",
	"ctrl-l",
	"ctrl-m",
	"ctrl-n",
	"ctrl-o",
	"ctrl-p",
	"ctrl-q",
	"ctrl-r",
	"ctrl-s",
	"ctrl-t",
	"ctrl-u",
	"ctrl-v",
	"ctrl-w",
	"ctrl-x",
	"ctrl-y",
	"ctrl-z",
	"ctrl-[",
	"ctrl-\\",
	"ctrl-]",
	"ctrl-^",
	"ctrl-_",
}

ASCII list the possible supported ASCII key sequence

Functions

func GetAuthTokenURL

func GetAuthTokenURL(httpURL string) (*url.URL, *http.Header, error)

GetAuthTokenURL transforms a GoTTY http URL to its AuthToken file URL

func GetURLQuery added in v1.1.0

func GetURLQuery(rawURL string) (url.Values, error)

GetURLQuery returns url.query

func GetWebsocketURL

func GetWebsocketURL(httpURL string) (*url.URL, *http.Header, error)

GetWebsocketURL transforms a GoTTY http URL to its WebSocket URL

func NewEscapeProxy added in v1.7.0

func NewEscapeProxy(r io.Reader, escapeKeys []byte) io.Reader

NewEscapeProxy returns a new TTY proxy reader which wraps the given reader and detects when the specified escape keys are read, in which case the Read method will return an error of type EscapeError.

func ParseURL added in v1.4.0

func ParseURL(input string) (string, error)

ParseURL parses an URL which may be incomplete and tries to standardize it

func ToBytes added in v1.8.0

func ToBytes(keys string) ([]byte, error)

ToBytes converts a string representing a suite of key-sequence to the corresponding ASCII code.

Types

type Client

type Client struct {
	Dialer     *websocket.Dialer
	Conn       *websocket.Conn
	URL        string
	WriteMutex *sync.Mutex
	Output     io.Writer

	SkipTLSVerify   bool
	UseProxyFromEnv bool
	Connected       bool
	EscapeKeys      []byte
	V2              bool

	WSOrigin string
	User     string
	Password string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(inputURL string) (*Client, error)

NewClient returns a GoTTY client object

func (*Client) Close

func (c *Client) Close() error

Close will nicely close the dialer

func (*Client) Connect

func (c *Client) Connect() error

Connect tries to dial a websocket server

func (*Client) ExitLoop added in v1.3.0

func (c *Client) ExitLoop()

ExitLoop will kill all goroutines launched by c.Loop() ExitLoop() -> wait Loop() -> Close()

func (*Client) GetAuthToken

func (c *Client) GetAuthToken() (string, error)

GetAuthToken retrieves an Auth Token from dynamic auth_token.js file

func (*Client) Loop

func (c *Client) Loop() error

Loop will look indefinitely for new messages

func (*Client) SetOutput added in v1.2.0

func (c *Client) SetOutput(w io.Writer)

SetOutput changes the output stream

type EscapeError added in v1.7.0

type EscapeError struct{}

EscapeError is special error which returned by a TTY proxy reader's Read() method in case its detach escape sequence is read.

func (EscapeError) Error added in v1.7.0

func (EscapeError) Error() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL