diff --git a/frontend/app/store/services.ts b/frontend/app/store/services.ts index 738629f78..19d762189 100644 --- a/frontend/app/store/services.ts +++ b/frontend/app/store/services.ts @@ -10,7 +10,9 @@ class BlockServiceType { GetControllerStatus(arg2: string): Promise { return WOS.callBackendService("block", "GetControllerStatus", Array.from(arguments)) } - SaveTerminalState(arg2: string, arg3: string, arg4: string, arg5: number): Promise { + + // save the terminal state to a blockfile + SaveTerminalState(blockId: string, state: string, stateType: string, ptyOffset: number, termSize: TermSize): Promise { return WOS.callBackendService("block", "SaveTerminalState", Array.from(arguments)) } SaveWaveAiData(arg2: string, arg3: OpenAIPromptMessageType[]): Promise { diff --git a/frontend/app/view/term/termwrap.ts b/frontend/app/view/term/termwrap.ts index 77a7acdfe..270850c6c 100644 --- a/frontend/app/view/term/termwrap.ts +++ b/frontend/app/view/term/termwrap.ts @@ -216,7 +216,21 @@ export class TermWrap { if (cacheFile != null) { ptyOffset = cacheFile.meta["ptyoffset"] ?? 0; if (cacheData.byteLength > 0) { + const curTermSize: TermSize = { rows: this.terminal.rows, cols: this.terminal.cols }; + const fileTermSize: TermSize = cacheFile.meta["termsize"]; + let didResize = false; + if ( + fileTermSize != null && + (fileTermSize.rows != curTermSize.rows || fileTermSize.cols != curTermSize.cols) + ) { + console.log("terminal restore size mismatch, temp resize", fileTermSize, curTermSize); + this.terminal.resize(fileTermSize.cols, fileTermSize.rows); + didResize = true; + } this.doTerminalWrite(cacheData, ptyOffset); + if (didResize) { + this.terminal.resize(curTermSize.cols, curTermSize.rows); + } } } const { data: mainData, fileInfo: mainFile } = await fetchWaveFile(this.blockId, TermFileName, ptyOffset); @@ -268,8 +282,9 @@ export class TermWrap { return; } const serializedOutput = this.serializeAddon.serialize(); - console.log("idle timeout term", this.dataBytesProcessed, serializedOutput.length); - services.BlockService.SaveTerminalState(this.blockId, serializedOutput, "full", this.ptyOffset); + const termSize: TermSize = { rows: this.terminal.rows, cols: this.terminal.cols }; + console.log("idle timeout term", this.dataBytesProcessed, serializedOutput.length, termSize); + services.BlockService.SaveTerminalState(this.blockId, serializedOutput, "full", this.ptyOffset, termSize); this.dataBytesProcessed = 0; } diff --git a/pkg/service/blockservice/blockservice.go b/pkg/service/blockservice/blockservice.go index 8dc6d942f..92a6ba149 100644 --- a/pkg/service/blockservice/blockservice.go +++ b/pkg/service/blockservice/blockservice.go @@ -38,7 +38,14 @@ func (bs *BlockService) GetControllerStatus(ctx context.Context, blockId string) return bc.GetRuntimeStatus(), nil } -func (bs *BlockService) SaveTerminalState(ctx context.Context, blockId string, state string, stateType string, ptyOffset int64) error { +func (*BlockService) SaveTerminalState_Meta() tsgenmeta.MethodMeta { + return tsgenmeta.MethodMeta{ + Desc: "save the terminal state to a blockfile", + ArgNames: []string{"ctx", "blockId", "state", "stateType", "ptyOffset", "termSize"}, + } +} + +func (bs *BlockService) SaveTerminalState(ctx context.Context, blockId string, state string, stateType string, ptyOffset int64, termSize waveobj.TermSize) error { _, err := wstore.DBMustGet[*waveobj.Block](ctx, blockId) if err != nil { return err @@ -52,7 +59,11 @@ func (bs *BlockService) SaveTerminalState(ctx context.Context, blockId string, s if err != nil { return fmt.Errorf("cannot save terminal state: %w", err) } - err = filestore.WFS.WriteMeta(ctx, blockId, "cache:term:"+stateType, filestore.FileMeta{"ptyoffset": ptyOffset}, true) + fileMeta := filestore.FileMeta{ + "ptyoffset": ptyOffset, + "termsize": termSize, + } + err = filestore.WFS.WriteMeta(ctx, blockId, "cache:term:"+stateType, fileMeta, true) if err != nil { return fmt.Errorf("cannot save terminal state meta: %w", err) }