Store TermSize in RuntimeOpts on Resize (#293)

This keeps the TermSize in RuntimeOpts which allows the terminally to be
correctly sized when reloading a block. Also, it seems to correctly size
the terminal on an app reboot (or at least immediately fixes it).
This commit is contained in:
Sylvie Crowe
2024-08-29 20:13:02 -07:00
committed by GitHub
parent 3f92c31bfe
commit 934d7247db
+19 -1
View File
@@ -361,6 +361,10 @@ func (bc *BlockController) DoRunShellCommand(rc *RunShellOpts, blockMeta waveobj
}
if ic.TermSize != nil {
log.Printf("SETTERMSIZE: %dx%d\n", ic.TermSize.Rows, ic.TermSize.Cols)
err = setTermSize(ctx, bc.BlockId, *ic.TermSize)
if err != nil {
log.Printf("error setting pty size: %v\n", err)
}
err = bc.ShellProc.Cmd.SetSize(ic.TermSize.Rows, ic.TermSize.Cols)
if err != nil {
log.Printf("error setting pty size: %v\n", err)
@@ -417,6 +421,21 @@ func getTermSize(bdata *waveobj.Block) waveobj.TermSize {
}
}
func setTermSize(ctx context.Context, blockId string, termSize waveobj.TermSize) error {
ctx = waveobj.ContextWithUpdates(ctx)
bdata, err := wstore.DBMustGet[*waveobj.Block](context.Background(), blockId)
if err != nil {
return fmt.Errorf("error getting block data: %v", err)
}
if bdata.RuntimeOpts == nil {
return fmt.Errorf("error from nil RuntimeOpts: %v", err)
}
bdata.RuntimeOpts.TermSize = termSize
updates := waveobj.ContextGetUpdatesRtn(ctx)
eventbus.SendUpdateEvents(updates)
return nil
}
func (bc *BlockController) run(bdata *waveobj.Block, blockMeta map[string]any) {
defer func() {
bc.UpdateControllerAndSendUpdate(func() bool {
@@ -466,7 +485,6 @@ func (bc *BlockController) SendInput(inputUnion *BlockInputUnion) error {
}
func (bc *BlockController) RestartController() error {
// kill the command if it's running
bc.Lock.Lock()
if bc.ShellProc != nil {