From 43689ac3f8b5879d1b81fc23813c9d23ac048a90 Mon Sep 17 00:00:00 2001 From: sawka Date: Tue, 27 Dec 2022 23:12:27 -0800 Subject: [PATCH] line archived (not line:hidden). remove some debugging code --- db/migrations/000001_init.up.sql | 2 +- pkg/cmdrunner/cmdrunner.go | 16 ++++++++-------- pkg/cmdrunner/termopts.go | 4 ++-- pkg/comp/comp.go | 1 - pkg/shparse/comp.go | 2 -- pkg/sstore/dbops.go | 10 +++++----- pkg/sstore/sstore.go | 2 +- 7 files changed, 17 insertions(+), 20 deletions(-) diff --git a/db/migrations/000001_init.up.sql b/db/migrations/000001_init.up.sql index 4c1e0272..e13caed8 100644 --- a/db/migrations/000001_init.up.sql +++ b/db/migrations/000001_init.up.sql @@ -103,7 +103,7 @@ CREATE TABLE line ( ephemeral boolean NOT NULL, contentheight int NOT NULL, star int NOT NULL, - hidden boolean NOT NULL, + archived boolean NOT NULL, PRIMARY KEY (sessionid, windowid, lineid) ); diff --git a/pkg/cmdrunner/cmdrunner.go b/pkg/cmdrunner/cmdrunner.go index e22ef7d5..6729db5b 100644 --- a/pkg/cmdrunner/cmdrunner.go +++ b/pkg/cmdrunner/cmdrunner.go @@ -152,7 +152,7 @@ func init() { registerCmdFn("line", LineCommand) registerCmdFn("line:show", LineShowCommand) registerCmdFn("line:star", LineStarCommand) - registerCmdFn("line:hide", LineHideCommand) + registerCmdFn("line:archive", LineArchiveCommand) registerCmdFn("line:purge", LinePurgeCommand) registerCmdFn("_history", HistoryCommand) @@ -1781,13 +1781,13 @@ func LineStarCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sst return sstore.ModelUpdate{Line: lineObj}, nil } -func LineHideCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) { +func LineArchiveCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) { ids, err := resolveUiIds(ctx, pk, R_Session|R_Screen|R_Window) if err != nil { return nil, err } if len(pk.Args) == 0 { - return nil, fmt.Errorf("/line:hide requires an argument (line number or id)") + return nil, fmt.Errorf("/line:archive requires an argument (line number or id)") } lineArg := pk.Args[0] lineId, err := sstore.FindLineIdByArg(ctx, ids.SessionId, ids.WindowId, lineArg) @@ -1797,17 +1797,17 @@ func LineHideCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sst if lineId == "" { return nil, fmt.Errorf("line %q not found", lineArg) } - shouldHide := true + shouldArchive := true if len(pk.Args) >= 2 { - shouldHide = resolveBool(pk.Args[1], true) + shouldArchive = resolveBool(pk.Args[1], true) } - err = sstore.SetLineHiddenById(ctx, lineId, shouldHide) + err = sstore.SetLineArchivedById(ctx, lineId, shouldArchive) if err != nil { - return nil, fmt.Errorf("/line:hide error updating hidden status: %v", err) + return nil, fmt.Errorf("/line:archive error updating hidden status: %v", err) } lineObj, err := sstore.GetLineById(ctx, lineId) if err != nil { - return nil, fmt.Errorf("/line:star error getting line: %v", err) + return nil, fmt.Errorf("/line:archive error getting line: %v", err) } if lineObj == nil { // no line (which is strange given we checked for it above). just return a nop. diff --git a/pkg/cmdrunner/termopts.go b/pkg/cmdrunner/termopts.go index 34c35f59..e5c87a85 100644 --- a/pkg/cmdrunner/termopts.go +++ b/pkg/cmdrunner/termopts.go @@ -11,8 +11,8 @@ import ( "github.com/scripthaus-dev/sh2-server/pkg/remote" ) -// PTERM=WxH,Wx25 -// PTERM="Wx25!" +// PTERM=MxM,Mx25 +// PTERM="Mx25!" // PTERM=80x25,80x35 type PTermOptsType struct { diff --git a/pkg/comp/comp.go b/pkg/comp/comp.go index 24525479..8dc8f457 100644 --- a/pkg/comp/comp.go +++ b/pkg/comp/comp.go @@ -525,7 +525,6 @@ func DoCompGen(ctx context.Context, cmdStr utilfn.StrWithPos, compCtx CompContex words := shparse.Tokenize(cmdStr.Str) cmds := shparse.ParseCommands(words) compPos := shparse.FindCompletionPos(cmds, cmdStr.Pos) - fmt.Printf("comppos: %v\n", compPos) if compPos.CompType == shparse.CompTypeInvalid { return nil, nil, nil } diff --git a/pkg/shparse/comp.go b/pkg/shparse/comp.go index fbc6065c..f33e1ad5 100644 --- a/pkg/shparse/comp.go +++ b/pkg/shparse/comp.go @@ -1,7 +1,6 @@ package shparse import ( - "fmt" "strings" "github.com/scripthaus-dev/sh2-server/pkg/utilfn" @@ -278,7 +277,6 @@ func (cpos CompletionPos) Extend(origStr utilfn.StrWithPos, extensionStr string, compWord = MakeEmptyWord(WordTypeLit, nil, cpos.RawPos, true) } realOffset := compWord.Offset + cpos.SuperOffset - fmt.Printf("cpos-extend: %d[%s] ext[%s] cword[%v] off:%d super:%d real:%d\n", len([]rune(origStr.Str)), origStr, extensionStr, compWord, compWord.Offset, cpos.SuperOffset, realOffset) if strings.HasSuffix(extensionStr, "/") { extensionComplete = false } diff --git a/pkg/sstore/dbops.go b/pkg/sstore/dbops.go index c293462b..1f30fb34 100644 --- a/pkg/sstore/dbops.go +++ b/pkg/sstore/dbops.go @@ -687,8 +687,8 @@ func InsertLine(ctx context.Context, line *LineType, cmd *CmdType) error { query = `SELECT nextlinenum FROM window WHERE sessionid = ? AND windowid = ?` nextLineNum := tx.GetInt(query, line.SessionId, line.WindowId) line.LineNum = int64(nextLineNum) - query = `INSERT INTO line ( sessionid, windowid, userid, lineid, ts, linenum, linenumtemp, linelocal, linetype, text, cmdid, ephemeral, contentheight, star, hidden) - VALUES (:sessionid,:windowid,:userid,:lineid,:ts,:linenum,:linenumtemp,:linelocal,:linetype,:text,:cmdid,:ephemeral,:contentheight,:star,:hidden)` + query = `INSERT INTO line ( sessionid, windowid, userid, lineid, ts, linenum, linenumtemp, linelocal, linetype, text, cmdid, ephemeral, contentheight, star, archived) + VALUES (:sessionid,:windowid,:userid,:lineid,:ts,:linenum,:linenumtemp,:linelocal,:linetype,:text,:cmdid,:ephemeral,:contentheight,:star,:archived)` tx.NamedExecWrap(query, line) query = `UPDATE window SET nextlinenum = ? WHERE sessionid = ? AND windowid = ?` tx.ExecWrap(query, nextLineNum+1, line.SessionId, line.WindowId) @@ -1741,10 +1741,10 @@ func GetLineById(ctx context.Context, lineId string) (*LineType, error) { return rtn, nil } -func SetLineHiddenById(ctx context.Context, lineId string, hidden bool) error { +func SetLineArchivedById(ctx context.Context, lineId string, archived bool) error { txErr := WithTx(ctx, func(tx *TxWrap) error { - query := `UPDATE line SET hidden = ? WHERE lineid = ?` - tx.ExecWrap(query, hidden, lineId) + query := `UPDATE line SET archived = ? WHERE lineid = ?` + tx.ExecWrap(query, archived, lineId) return nil }) return txErr diff --git a/pkg/sstore/sstore.go b/pkg/sstore/sstore.go index a34bb166..eadecb22 100644 --- a/pkg/sstore/sstore.go +++ b/pkg/sstore/sstore.go @@ -590,7 +590,7 @@ type LineType struct { Ephemeral bool `json:"ephemeral,omitempty"` ContentHeight int64 `json:"contentheight,omitempty"` Star bool `json:"star,omitempty"` - Hidden bool `json:"hidden,omitempty"` + Archived bool `json:"archived,omitempty"` Remove bool `json:"remove,omitempty"` }