From ccdf66dcd6bde87bc42ebdf7efb48ebe596cabe7 Mon Sep 17 00:00:00 2001 From: Indra Gunawan <1284811+coderbuzz@users.noreply.github.com> Date: Wed, 1 Jul 2026 17:16:24 +0700 Subject: [PATCH] fix: console blank terminal + raw JSON echo in mock mode --- internal/http/console.go | 13 +++++++++---- internal/http/templates/layout.html | 9 +++++++-- internal/ssh/client.go | 6 ++++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/internal/http/console.go b/internal/http/console.go index 6ba3cf4..911b842 100644 --- a/internal/http/console.go +++ b/internal/http/console.go @@ -99,11 +99,16 @@ func (h *ConsoleHandler) ServeWS(w http.ResponseWriter, r *http.Request) { errCh <- err return } - var input ssh.Input - if json.Unmarshal(msg, &input) == nil && input.Resize != nil { - inCh <- input - continue + if json.Unmarshal(msg, &input) == nil { + if input.Resize != nil { + inCh <- input + continue + } + if len(input.Data) > 0 { + inCh <- input + continue + } } inCh <- ssh.Input{Data: msg} diff --git a/internal/http/templates/layout.html b/internal/http/templates/layout.html index 88aa93c..fef415b 100644 --- a/internal/http/templates/layout.html +++ b/internal/http/templates/layout.html @@ -409,6 +409,7 @@ setTimeout(function() { fitAddon.fit(); }, 50); ws = new WebSocket(proto + '//' + host + base + 'api/servers/' + serverId + '/console'); + ws.binaryType = 'arraybuffer'; ws.onopen = function() { document.getElementById('console-status').textContent = 'Connected'; @@ -421,9 +422,13 @@ }; ws.onmessage = function(evt) { - term.write(evt.data); + var data = evt.data; + if (data instanceof ArrayBuffer) { + term.write(new Uint8Array(data)); + } else { + term.write(data); + } }; - ws.onclose = function() { document.getElementById('console-status').textContent = 'Disconnected'; document.getElementById('console-status').className = 'badge badge-offline'; diff --git a/internal/ssh/client.go b/internal/ssh/client.go index fed6d00..db19b82 100644 --- a/internal/ssh/client.go +++ b/internal/ssh/client.go @@ -94,8 +94,10 @@ func (c *Client) Shell(ctx context.Context, rows, cols int) (<-chan Output, chan } if err := session.RequestPty("xterm-256color", rows, cols, gossh.TerminalModes{ - gossh.ECHO: 1, - gossh.OCRNL: 1, + gossh.ECHO: 1, + gossh.OCRNL: 1, + gossh.TTY_OP_ISPEED: 14400, + gossh.TTY_OP_OSPEED: 14400, }); err != nil { session.Close() return nil, nil, fmt.Errorf("request pty: %w", err)