cmd-fg, update when cmd done back to input

This commit is contained in:
sawka
2022-10-11 23:11:43 -07:00
parent 61dac018fb
commit c940c7b85b
4 changed files with 51 additions and 9 deletions
+1 -1
View File
@@ -260,7 +260,7 @@ func RunCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.U
if sw != nil {
updateMap := make(map[string]interface{})
updateMap[sstore.SWField_SelectedLine] = rtnLine.LineNum
updateMap[sstore.SWField_Focus] = sstore.SWFocusCmd
updateMap[sstore.SWField_Focus] = sstore.SWFocusCmdFg
sw, err = sstore.UpdateScreenWindow(ctx, ids.SessionId, ids.ScreenId, ids.WindowId, updateMap)
if err != nil {
// ignore error again (nothing to do)
+6
View File
@@ -1191,6 +1191,12 @@ func (msh *MShellProc) handleCmdDonePacket(donePk *packet.CmdDonePacketType) {
msh.WriteToPtyBuffer("[error] updating cmddone: %v\n", err)
return
}
sws, err := sstore.UpdateSWsWithCmdFg(context.Background(), donePk.CK.GetSessionId(), donePk.CK.GetCmdId())
if err != nil {
fmt.Printf("[error] trying to update cmd-fg screen windows: %v\n", err)
// fall-through (nothing to do)
}
update.ScreenWindows = sws
if update != nil {
sstore.MainBus.SendUpdate(donePk.CK.GetSessionId(), update)
}
+38 -8
View File
@@ -655,7 +655,7 @@ func GetCmdById(ctx context.Context, sessionId string, cmdId string) (*CmdType,
return cmd, nil
}
func UpdateCmdDonePk(ctx context.Context, donePk *packet.CmdDonePacketType) (UpdatePacket, error) {
func UpdateCmdDonePk(ctx context.Context, donePk *packet.CmdDonePacketType) (*ModelUpdate, error) {
if donePk == nil || donePk.CK.IsEmpty() {
return nil, fmt.Errorf("invalid cmddone packet (no ck)")
}
@@ -676,7 +676,7 @@ func UpdateCmdDonePk(ctx context.Context, donePk *packet.CmdDonePacketType) (Upd
if rtnCmd == nil {
return nil, fmt.Errorf("cmd data not found for ck[%s]", donePk.CK)
}
return ModelUpdate{Cmd: rtnCmd}, nil
return &ModelUpdate{Cmd: rtnCmd}, nil
}
func AppendCmdErrorPk(ctx context.Context, errPk *packet.CmdErrorPacketType) error {
@@ -690,12 +690,6 @@ func AppendCmdErrorPk(ctx context.Context, errPk *packet.CmdErrorPacketType) err
})
}
type SWKey struct {
SessionId string
ScreenId string
WindowId string
}
func HangupAllRunningCmds(ctx context.Context) error {
return WithTx(ctx, func(tx *TxWrap) error {
query := `UPDATE cmd SET status = ? WHERE status = ?`
@@ -1179,3 +1173,39 @@ func GetLineResolveItems(ctx context.Context, sessionId string, windowId string)
}
return rtn, nil
}
func UpdateSWsWithCmdFg(ctx context.Context, sessionId string, cmdId string) ([]*ScreenWindowType, error) {
var rtn []*ScreenWindowType
txErr := WithTx(ctx, func(tx *TxWrap) error {
query := `SELECT sessionid, screenid, windowid
FROM screen_window sw
WHERE
sessionid = ?
AND focustype = 'cmd-fg'
AND selectedline IN (SELECT linenum
FROM line l
WHERE l.sessionid = sw.sessionid
AND l.windowid = sw.windowid
AND l.cmdid = ?
)`
var swKeys []SWKey
tx.SelectWrap(&swKeys, query, sessionId, cmdId)
if len(swKeys) == 0 {
return nil
}
for _, key := range swKeys {
editMap := make(map[string]interface{})
editMap[SWField_Focus] = SWFocusInput
sw, err := UpdateScreenWindow(tx.Context(), key.SessionId, key.ScreenId, key.WindowId, editMap)
if err != nil {
return err
}
rtn = append(rtn, sw)
}
return nil
})
if txErr != nil {
return nil, txErr
}
return rtn, nil
}
+6
View File
@@ -394,6 +394,12 @@ func (a SWAnchorType) Value() (driver.Value, error) {
return quickValueJson(a)
}
type SWKey struct {
SessionId string
ScreenId string
WindowId string
}
type ScreenWindowType struct {
SessionId string `json:"sessionid"`
ScreenId string `json:"screenid"`