return interactive update

This commit is contained in:
sawka 2022-07-15 17:53:23 -07:00
parent 6807547ff7
commit 4785253a10
2 changed files with 24 additions and 17 deletions

View File

@ -200,6 +200,9 @@ func HandleCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstor
case "screen":
return ScreenCommand(ctx, pk)
case "session":
return SessionCommand(ctx, pk)
case "comment":
return CommentCommand(ctx, pk)
@ -292,11 +295,11 @@ func ScreenCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstor
if err != nil {
return nil, fmt.Errorf("/screen:close cannot close screen: %w", err)
}
err = sstore.DeleteScreen(ctx, ids.SessionId, ids.ScreenId)
update, err := sstore.DeleteScreen(ctx, ids.SessionId, ids.ScreenId)
if err != nil {
return nil, err
}
return nil, nil
return update, nil
}
if pk.MetaSubCmd == "open" || pk.MetaSubCmd == "new" {
ids, err := resolveIds(ctx, pk, R_Session)
@ -304,11 +307,11 @@ func ScreenCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstor
return nil, fmt.Errorf("/screen:open cannot open screen: %w", err)
}
activate := resolveBool(pk.Kwargs["activate"], true)
_, err = sstore.InsertScreen(ctx, ids.SessionId, pk.Kwargs["name"], activate)
update, err := sstore.InsertScreen(ctx, ids.SessionId, pk.Kwargs["name"], activate)
if err != nil {
return nil, err
}
return nil, nil
return update, nil
}
if pk.MetaSubCmd != "" {
return nil, fmt.Errorf("invalid /screen subcommand '%s'", pk.MetaSubCmd)
@ -325,8 +328,11 @@ func ScreenCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstor
if err != nil {
return nil, err
}
sstore.SwitchScreenById(ctx, ids.SessionId, screenIdArg)
return nil, nil
update, err := sstore.SwitchScreenById(ctx, ids.SessionId, screenIdArg)
if err != nil {
return nil, err
}
return update, nil
}
func CdCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) {
@ -365,3 +371,7 @@ func CommentCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (ssto
}
return sstore.LineUpdate{Line: rtnLine}, nil
}
func SessionCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) {
return nil, nil
}

View File

@ -248,7 +248,7 @@ func fmtUniqueName(name string, defaultFmtStr string, startIdx int, strs []strin
}
}
func InsertScreen(ctx context.Context, sessionId string, screenName string, activate bool) (string, error) {
func InsertScreen(ctx context.Context, sessionId string, screenName string, activate bool) (UpdatePacket, error) {
var newScreenId string
txErr := WithTx(ctx, func(tx *TxWrap) error {
query := `SELECT sessionid FROM session WHERE sessionid = ?`
@ -273,15 +273,14 @@ func InsertScreen(ctx context.Context, sessionId string, screenName string, acti
})
newScreen, err := GetScreenById(ctx, sessionId, newScreenId)
if err != nil {
return "", err
return nil, err
}
update, session := MakeSingleSessionUpdate(sessionId)
if activate {
session.ActiveScreenId = newScreenId
}
session.Screens = append(session.Screens, newScreen)
MainBus.SendUpdate("", update)
return newScreenId, txErr
return update, txErr
}
func GetScreenById(ctx context.Context, sessionId string, screenId string) (*ScreenType, error) {
@ -422,7 +421,7 @@ func getNextId(ids []string, delId string) string {
return ids[0]
}
func SwitchScreenById(ctx context.Context, sessionId string, screenId string) error {
func SwitchScreenById(ctx context.Context, sessionId string, screenId string) (UpdatePacket, error) {
txErr := WithTx(ctx, func(tx *TxWrap) error {
query := `SELECT screenid FROM screen WHERE sessionid = ? AND screenid = ?`
if !tx.Exists(query, sessionId, screenId) {
@ -434,14 +433,13 @@ func SwitchScreenById(ctx context.Context, sessionId string, screenId string) er
})
update, session := MakeSingleSessionUpdate(sessionId)
session.ActiveScreenId = screenId
MainBus.SendUpdate("", update)
return txErr
return update, txErr
}
func CleanWindows() {
}
func DeleteScreen(ctx context.Context, sessionId string, screenId string) error {
func DeleteScreen(ctx context.Context, sessionId string, screenId string) (UpdatePacket, error) {
var newActiveScreenId string
txErr := WithTx(ctx, func(tx *TxWrap) error {
isActive := tx.Exists(`SELECT sessionid FROM session WHERE sessionid = ? AND activescreenid = ?`, sessionId, screenId)
@ -459,14 +457,13 @@ func DeleteScreen(ctx context.Context, sessionId string, screenId string) error
return nil
})
if txErr != nil {
return txErr
return nil, txErr
}
go CleanWindows()
update, session := MakeSingleSessionUpdate(sessionId)
session.ActiveScreenId = newActiveScreenId
session.Screens = append(session.Screens, &ScreenType{SessionId: sessionId, ScreenId: screenId, Remove: true})
MainBus.SendUpdate("", update)
return nil
return update, nil
}
func GetRemoteState(ctx context.Context, rname string, sessionId string, windowId string) (string, *RemoteState, error) {