mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-22 16:48:23 +01:00
clear window
This commit is contained in:
parent
aff174fa80
commit
9d6cc1f67a
@ -48,6 +48,7 @@ func init() {
|
||||
registerCmdFn("compgen", CompGenCommand)
|
||||
registerCmdFn("setenv", SetEnvCommand)
|
||||
registerCmdFn("unset", UnSetCommand)
|
||||
registerCmdFn("clear", ClearCommand)
|
||||
|
||||
registerCmdFn("session", SessionCommand)
|
||||
registerCmdFn("session:open", SessionOpenCommand)
|
||||
@ -886,6 +887,22 @@ func SessionCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (ssto
|
||||
return update, nil
|
||||
}
|
||||
|
||||
func ClearCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) {
|
||||
ids, err := resolveIds(ctx, pk, R_Session|R_Screen|R_Window)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
update, err := sstore.ClearWindow(ctx, ids.SessionId, ids.WindowId)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("clearing window: %v", err)
|
||||
}
|
||||
update.Info = &sstore.InfoMsgType{
|
||||
InfoMsg: fmt.Sprintf("window cleared"),
|
||||
TimeoutMs: 2000,
|
||||
}
|
||||
return update, nil
|
||||
}
|
||||
|
||||
func splitLinesForInfo(str string) []string {
|
||||
rtn := strings.Split(str, "\n")
|
||||
if rtn[len(rtn)-1] == "" {
|
||||
|
@ -96,6 +96,7 @@ var BareMetaCmds = []BareMetaCmdDecl{
|
||||
BareMetaCmdDecl{"setenv", "setenv"},
|
||||
BareMetaCmdDecl{"export", "setenv"},
|
||||
BareMetaCmdDecl{"unset", "unset"},
|
||||
BareMetaCmdDecl{"clear", "clear"},
|
||||
}
|
||||
|
||||
func SubMetaCmd(cmd string) string {
|
||||
|
@ -772,3 +772,35 @@ func SetScreenOpts(ctx context.Context, sessionId string, screenId string, opts
|
||||
})
|
||||
return txErr
|
||||
}
|
||||
|
||||
func ClearWindow(ctx context.Context, sessionId string, windowId string) (*ModelUpdate, error) {
|
||||
var lineIds []string
|
||||
txErr := WithTx(ctx, func(tx *TxWrap) error {
|
||||
query := `SELECT windowid FROM window WHERE sessionid = ? AND windowid = ?`
|
||||
if !tx.Exists(query, sessionId, windowId) {
|
||||
return fmt.Errorf("window does not exist")
|
||||
}
|
||||
query = `SELECT lineid FROM line WHERE sessionid = ? AND windowid = ?`
|
||||
lineIds = tx.SelectStrings(query, sessionId, windowId)
|
||||
query = `DELETE FROM line WHERE sessionid = ? AND windowid = ?`
|
||||
tx.ExecWrap(query, sessionId, windowId)
|
||||
return nil
|
||||
})
|
||||
if txErr != nil {
|
||||
return nil, txErr
|
||||
}
|
||||
win, err := GetWindowById(ctx, sessionId, windowId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, lineId := range lineIds {
|
||||
line := &LineType{
|
||||
SessionId: sessionId,
|
||||
WindowId: windowId,
|
||||
LineId: lineId,
|
||||
Remove: true,
|
||||
}
|
||||
win.Lines = append(win.Lines, line)
|
||||
}
|
||||
return &ModelUpdate{Window: win}, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user