resize terminal on restoring state (#1100) (backport from dev0.9) (#1116)

This commit is contained in:
Mike Sawka 2024-10-24 11:01:58 -07:00 committed by GitHub
parent d65eabe494
commit 1742c19e13
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 33 additions and 5 deletions

View File

@ -10,7 +10,9 @@ class BlockServiceType {
GetControllerStatus(arg2: string): Promise<BlockControllerRuntimeStatus> {
return WOS.callBackendService("block", "GetControllerStatus", Array.from(arguments))
}
SaveTerminalState(arg2: string, arg3: string, arg4: string, arg5: number): Promise<void> {
// save the terminal state to a blockfile
SaveTerminalState(blockId: string, state: string, stateType: string, ptyOffset: number, termSize: TermSize): Promise<void> {
return WOS.callBackendService("block", "SaveTerminalState", Array.from(arguments))
}
SaveWaveAiData(arg2: string, arg3: OpenAIPromptMessageType[]): Promise<void> {

View File

@ -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;
}

View File

@ -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)
}