Skip to content

Commit adc823f

Browse files
authored
rip out osc 23198 and osc 9283 handlers (#2736)
1 parent a92a483 commit adc823f

5 files changed

Lines changed: 4 additions & 229 deletions

File tree

cmd/test/test-main.go

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,6 @@
33

44
package main
55

6-
import (
7-
"context"
8-
"fmt"
9-
"log"
10-
11-
"github.com/wavetermdev/waveterm/pkg/vdom"
12-
"github.com/wavetermdev/waveterm/pkg/wshutil"
13-
)
14-
15-
func Page(ctx context.Context, props map[string]any) any {
16-
clicked, setClicked := vdom.UseState(ctx, false)
17-
var clickedDiv *vdom.VDomElem
18-
if clicked {
19-
clickedDiv = vdom.Bind(`<div>clicked</div>`, nil)
20-
}
21-
clickFn := func() {
22-
log.Printf("run clickFn\n")
23-
setClicked(true)
24-
}
25-
return vdom.Bind(
26-
`
27-
<div>
28-
<h1>hello world</h1>
29-
<Button onClick="#bind:clickFn">hello</Button>
30-
<bind key="clickedDiv"/>
31-
</div>
32-
`,
33-
map[string]any{"clickFn": clickFn, "clickedDiv": clickedDiv},
34-
)
35-
}
36-
37-
func Button(ctx context.Context, props map[string]any) any {
38-
ref := vdom.UseVDomRef(ctx)
39-
clName, setClName := vdom.UseState(ctx, "button")
40-
vdom.UseEffect(ctx, func() func() {
41-
fmt.Printf("Button useEffect\n")
42-
setClName("button mounted")
43-
return nil
44-
}, nil)
45-
return vdom.Bind(`
46-
<div className="#bind:clName" ref="#bind:ref" onClick="#bind:onClick">
47-
<bind key="children"/>
48-
</div>
49-
`, map[string]any{"clName": clName, "ref": ref, "onClick": props["onClick"], "children": props["children"]})
50-
}
51-
526
func main() {
53-
wshutil.SetTermRawModeAndInstallShutdownHandlers(true)
54-
defer wshutil.RestoreTermState()
7+
558
}

cmd/wsh/cmd/wshcmd-root.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,7 @@ func OutputHelpMessage(cmd *cobra.Command) {
8484
func preRunSetupRpcClient(cmd *cobra.Command, args []string) error {
8585
jwtToken := os.Getenv(wshutil.WaveJwtTokenVarName)
8686
if jwtToken == "" {
87-
wshutil.SetTermRawModeAndInstallShutdownHandlers(true)
88-
UsingTermWshMode = true
89-
RpcClient, WrappedStdin = wshutil.SetupTerminalRpcClient(nil, "wshcmd-termclient")
90-
return nil
87+
return fmt.Errorf("wsh must be run inside a Wave-managed SSH session (WAVETERM_JWT not found)")
9188
}
9289
err := setupRpcClient(nil, jwtToken)
9390
if err != nil {

frontend/app/view/term/termwrap.ts

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -52,68 +52,6 @@ type TermWrapOptions = {
5252
nodeModel?: BlockNodeModel;
5353
};
5454

55-
function handleOscWaveCommand(data: string, blockId: string, loaded: boolean): boolean {
56-
if (!loaded) {
57-
return true;
58-
}
59-
if (!data || data.length === 0) {
60-
console.log("Invalid Wave OSC command received (empty)");
61-
return true;
62-
}
63-
64-
// Expected formats:
65-
// "setmeta;{JSONDATA}"
66-
// "setmeta;[wave-id];{JSONDATA}"
67-
const parts = data.split(";");
68-
if (parts[0] !== "setmeta") {
69-
console.log("Invalid Wave OSC command received (bad command)", data);
70-
return true;
71-
}
72-
let jsonPayload: string;
73-
let waveId: string | undefined;
74-
if (parts.length === 2) {
75-
jsonPayload = parts[1];
76-
} else if (parts.length >= 3) {
77-
waveId = parts[1];
78-
jsonPayload = parts.slice(2).join(";");
79-
} else {
80-
console.log("Invalid Wave OSC command received (1 part)", data);
81-
return true;
82-
}
83-
84-
let meta: any;
85-
try {
86-
meta = JSON.parse(jsonPayload);
87-
} catch (e) {
88-
console.error("Invalid JSON in Wave OSC command:", e);
89-
return true;
90-
}
91-
92-
if (waveId) {
93-
// Resolve the wave id to an ORef using our ResolveIdsCommand.
94-
fireAndForget(() => {
95-
return RpcApi.ResolveIdsCommand(TabRpcClient, { blockid: blockId, ids: [waveId] })
96-
.then((response: { resolvedids: { [key: string]: any } }) => {
97-
const oref = response.resolvedids[waveId];
98-
if (!oref) {
99-
console.error("Failed to resolve wave id:", waveId);
100-
return;
101-
}
102-
services.ObjectService.UpdateObjectMeta(oref, meta);
103-
})
104-
.catch((err: any) => {
105-
console.error("Error resolving wave id", waveId, err);
106-
});
107-
});
108-
} else {
109-
// No wave id provided; update using the current block id.
110-
fireAndForget(() => {
111-
return services.ObjectService.UpdateObjectMeta(WOS.makeORef("block", blockId), meta);
112-
});
113-
}
114-
return true;
115-
}
116-
11755
// for xterm OSC handlers, we return true always because we "own" the OSC number.
11856
// even if data is invalid we don't want to propagate to other handlers.
11957
function handleOsc52Command(data: string, blockId: string, loaded: boolean, termWrap: TermWrap): boolean {
@@ -538,9 +476,6 @@ export class TermWrap {
538476
this.terminal.parser.registerOscHandler(52, (data: string) => {
539477
return handleOsc52Command(data, this.blockId, this.loaded, this);
540478
});
541-
this.terminal.parser.registerOscHandler(9283, (data: string) => {
542-
return handleOscWaveCommand(data, this.blockId, this.loaded);
543-
});
544479
this.terminal.parser.registerOscHandler(16162, (data: string) => {
545480
return handleOsc16162Command(data, this.blockId, this.loaded, this);
546481
});

pkg/blockcontroller/shellcontroller.go

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -513,14 +513,6 @@ func (bc *ShellController) manageRunningShellProcess(shellProc *shellexec.ShellP
513513
shellInputCh := make(chan *BlockInputUnion, 32)
514514
bc.ShellInputCh = shellInputCh
515515

516-
// make esc sequence wshclient wshProxy
517-
// we don't need to authenticate this wshProxy since it is coming direct
518-
wshProxy := wshutil.MakeRpcProxy(fmt.Sprintf("controller:%s", bc.BlockId))
519-
controllerLinkId, err := wshutil.DefaultRouter.RegisterTrustedLeaf(wshProxy, wshutil.MakeControllerRouteId(bc.BlockId))
520-
if err != nil {
521-
return fmt.Errorf("cannot register controller route: %w", err)
522-
}
523-
ptyBuffer := wshutil.MakePtyBuffer(wshutil.WaveOSCPrefix, shellProc.Cmd, wshProxy.FromRemoteCh)
524516
go func() {
525517
// handles regular output from the pty (goes to the blockfile and xterm)
526518
defer func() {
@@ -546,7 +538,7 @@ func (bc *ShellController) manageRunningShellProcess(shellProc *shellexec.ShellP
546538
}()
547539
buf := make([]byte, 4096)
548540
for {
549-
nr, err := ptyBuffer.Read(buf)
541+
nr, err := shellProc.Cmd.Read(buf)
550542
if nr > 0 {
551543
err := HandleAppendBlockFile(bc.BlockId, wavebase.BlockFile_Term, buf[:nr])
552544
if err != nil {
@@ -577,27 +569,13 @@ func (bc *ShellController) manageRunningShellProcess(shellProc *shellexec.ShellP
577569
}
578570
}
579571
}()
580-
go func() {
581-
defer func() {
582-
panichandler.PanicHandler("blockcontroller:shellproc-output-loop", recover())
583-
}()
584-
// handles outputCh -> shellInputCh
585-
for msg := range wshProxy.ToRemoteCh {
586-
encodedMsg, err := wshutil.EncodeWaveOSCBytes(wshutil.WaveServerOSC, msg)
587-
if err != nil {
588-
log.Printf("error encoding OSC message: %v\n", err)
589-
}
590-
shellInputCh <- &BlockInputUnion{InputData: encodedMsg}
591-
}
592-
}()
593572
go func() {
594573
defer func() {
595574
panichandler.PanicHandler("blockcontroller:shellproc-wait-loop", recover())
596575
}()
597576
// wait for the shell to finish
598577
var exitCode int
599578
defer func() {
600-
wshutil.DefaultRouter.UnregisterLink(controllerLinkId)
601579
bc.UpdateControllerAndSendUpdate(func() bool {
602580
if bc.ProcStatus == Status_Running {
603581
bc.ProcStatus = Status_Done

pkg/wshutil/wshutil.go

Lines changed: 1 addition & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ import (
1111
"log"
1212
"net"
1313
"os"
14-
"os/signal"
1514
"path/filepath"
1615
"runtime"
1716
"strings"
1817
"sync"
1918
"sync/atomic"
20-
"syscall"
2119

2220
"github.com/golang-jwt/jwt/v5"
2321
"github.com/wavetermdev/waveterm/pkg/baseds"
@@ -28,7 +26,6 @@ import (
2826
"github.com/wavetermdev/waveterm/pkg/wavebase"
2927
"github.com/wavetermdev/waveterm/pkg/wavejwt"
3028
"github.com/wavetermdev/waveterm/pkg/wshrpc"
31-
"golang.org/x/term"
3229
)
3330

3431
// these should both be 5 characters
@@ -126,102 +123,17 @@ func EncodeWaveOSCMessageEx(oscNum string, msg *RpcMessage) ([]byte, error) {
126123
return EncodeWaveOSCBytes(oscNum, barr)
127124
}
128125

129-
var termModeLock = sync.Mutex{}
130-
var termIsRaw bool
131-
var origTermState *term.State
132-
var shutdownSignalHandlersInstalled bool
133126
var shutdownOnce sync.Once
134-
var extraShutdownFunc atomic.Pointer[func()]
135127

136128
func DoShutdown(reason string, exitCode int, quiet bool) {
137129
shutdownOnce.Do(func() {
138130
defer os.Exit(exitCode)
139-
RestoreTermState()
140-
extraFn := extraShutdownFunc.Load()
141-
if extraFn != nil {
142-
(*extraFn)()
143-
}
144131
if !quiet && reason != "" {
145-
log.Printf("shutting down: %s\r\n", reason)
132+
log.Printf("shutting down: %s\n", reason)
146133
}
147134
})
148135
}
149136

150-
func installShutdownSignalHandlers(quiet bool) {
151-
termModeLock.Lock()
152-
defer termModeLock.Unlock()
153-
if shutdownSignalHandlersInstalled {
154-
return
155-
}
156-
sigCh := make(chan os.Signal, 1)
157-
signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGTERM, syscall.SIGINT)
158-
go func() {
159-
defer func() {
160-
panichandler.PanicHandlerNoTelemetry("installShutdownSignalHandlers", recover())
161-
}()
162-
for sig := range sigCh {
163-
DoShutdown(fmt.Sprintf("got signal %v", sig), 1, quiet)
164-
break
165-
}
166-
}()
167-
}
168-
169-
func SetTermRawModeAndInstallShutdownHandlers(quietShutdown bool) {
170-
SetTermRawMode()
171-
installShutdownSignalHandlers(quietShutdown)
172-
}
173-
174-
func SetExtraShutdownFunc(fn func()) {
175-
extraShutdownFunc.Store(&fn)
176-
}
177-
178-
func SetTermRawMode() {
179-
termModeLock.Lock()
180-
defer termModeLock.Unlock()
181-
if termIsRaw {
182-
return
183-
}
184-
origState, err := term.MakeRaw(int(os.Stdin.Fd()))
185-
if err != nil {
186-
fmt.Fprintf(os.Stderr, "Error setting raw mode: %v\n", err)
187-
return
188-
}
189-
origTermState = origState
190-
termIsRaw = true
191-
}
192-
193-
func RestoreTermState() {
194-
termModeLock.Lock()
195-
defer termModeLock.Unlock()
196-
if !termIsRaw || origTermState == nil {
197-
return
198-
}
199-
term.Restore(int(os.Stdin.Fd()), origTermState)
200-
termIsRaw = false
201-
}
202-
203-
// returns (wshRpc, wrappedStdin)
204-
func SetupTerminalRpcClient(serverImpl ServerImpl, debugStr string) (*WshRpc, io.Reader) {
205-
messageCh := make(chan baseds.RpcInputChType, DefaultInputChSize)
206-
outputCh := make(chan []byte, DefaultOutputChSize)
207-
ptyBuf := MakePtyBuffer(WaveServerOSCPrefix, os.Stdin, messageCh)
208-
rpcClient := MakeWshRpcWithChannels(messageCh, outputCh, wshrpc.RpcContext{}, serverImpl, debugStr)
209-
go func() {
210-
defer func() {
211-
panichandler.PanicHandler("SetupTerminalRpcClient", recover())
212-
}()
213-
for msg := range outputCh {
214-
barr, err := EncodeWaveOSCBytes(WaveOSC, msg)
215-
if err != nil {
216-
fmt.Fprintf(os.Stderr, "Error encoding OSC message: %v\n", err)
217-
continue
218-
}
219-
os.Stdout.Write(barr)
220-
}
221-
}()
222-
return rpcClient, ptyBuf
223-
}
224-
225137
func SetupPacketRpcClient(input io.Reader, output io.Writer, serverImpl ServerImpl, debugStr string) (*WshRpc, chan []byte) {
226138
messageCh := make(chan baseds.RpcInputChType, DefaultInputChSize)
227139
outputCh := make(chan []byte, DefaultOutputChSize)

0 commit comments

Comments
 (0)