Fixed terminal output (support escape and control characters)
[src/xds/xds-server.git] / lib / xdsserver / terminal-ssh.go
index 3f4a344..9a9f5fd 100644 (file)
@@ -128,26 +128,19 @@ func (t *TermSSH) Open(sock *socketio.Socket, sessID string) (*xsapiv1.TerminalC
 
        t.sshWS = eows.New(cmd, args, sock, sessID, cmdID)
        t.sshWS.Log = t.Log
-       t.sshWS.OutSplit = eows.SplitChar
-       t.sshWS.PtsMode = true
+       t.sshWS.PtyMode = true
 
        // Define callback for input (stdin)
        t.sshWS.InputEvent = xsapiv1.TerminalInEvent
-       t.sshWS.InputCB = func(e *eows.ExecOverWS, stdin string) (string, error) {
-               t.Log.Debugf("STDIN <<%v>>", strings.Replace(stdin, "\n", "\\n", -1))
-
-               // Handle Ctrl-D
-               if len(stdin) == 1 && stdin == "\x04" {
-                       // Close stdin
-                       errMsg := fmt.Errorf("close stdin: %v", stdin)
-                       return "", errMsg
+       t.sshWS.InputCB = func(e *eows.ExecOverWS, stdin []byte) ([]byte, error) {
+               if t.LogLevelSilly {
+                       t.Log.Debugf("STDIN <<%v>> %s", stdin, string(stdin))
                }
-
                return stdin, nil
        }
 
        // Define callback for output (stdout+stderr)
-       t.sshWS.OutputCB = func(e *eows.ExecOverWS, stdout, stderr string) {
+       t.sshWS.OutputCB = func(e *eows.ExecOverWS, stdout, stderr []byte) {
                // IO socket can be nil when disconnected
                so := t.sessions.IOSocketGet(e.Sid)
                if so == nil {
@@ -159,12 +152,14 @@ func (t *TermSSH) Open(sock *socketio.Socket, sessID string) (*xsapiv1.TerminalC
                data := e.UserData
                termID := (*data)["ID"].(string)
 
-               t.Log.Debugf("%s emitted - WS sid[4:] %s - id:%s - termID:%s", xsapiv1.TerminalOutEvent, e.Sid[4:], e.CmdID, termID)
-               if stdout != "" {
-                       t.Log.Debugf("STDOUT <<%v>>", strings.Replace(stdout, "\n", "\\n", -1))
-               }
-               if stderr != "" {
-                       t.Log.Debugf("STDERR <<%v>>", strings.Replace(stderr, "\n", "\\n", -1))
+               if t.LogLevelSilly {
+                       t.Log.Debugf("%s emitted - WS sid[4:] %s - id:%s - termID:%s", xsapiv1.TerminalOutEvent, e.Sid[4:], e.CmdID, termID)
+                       if len(stdout) > 0 {
+                               t.Log.Debugf("STDOUT <<%v>>", strings.Replace(string(stdout), "\n", "\\n", -1))
+                       }
+                       if len(stderr) > 0 {
+                               t.Log.Debugf("STDERR <<%v>>", strings.Replace(string(stderr), "\n", "\\n", -1))
+                       }
                }
 
                // FIXME replace by .BroadcastTo a room