Persist line "minimized" status to DB (#306)

* backend implementation

* integrate minize linesate in UI

* remove debugging code

* change prompt:min key to wave:min
This commit is contained in:
Red J Adaya 2024-02-23 03:45:08 +08:00 committed by GitHub
parent 8bcb99fa35
commit 743d6d8622
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 62 additions and 12 deletions

View File

@ -113,9 +113,6 @@ class LineCmd extends React.Component<
isOverflow: OV<boolean> = mobx.observable.box(false, { isOverflow: OV<boolean> = mobx.observable.box(false, {
name: "line-overflow", name: "line-overflow",
}); });
isMinimized: OV<boolean> = mobx.observable.box(false, {
name: "line-minimised",
});
isCmdExpanded: OV<boolean> = mobx.observable.box(false, { isCmdExpanded: OV<boolean> = mobx.observable.box(false, {
name: "cmd-expanded", name: "cmd-expanded",
}); });
@ -351,9 +348,9 @@ class LineCmd extends React.Component<
@boundMethod @boundMethod
clickMinimize() { clickMinimize() {
mobx.action(() => { const { line } = this.props;
this.isMinimized.set(!this.isMinimized.get()); const isMinimized = line.linestate["wave:min"];
})(); GlobalCommandRunner.lineMinimize(line.lineid, !isMinimized, true);
} }
@boundMethod @boundMethod
@ -566,6 +563,7 @@ class LineCmd extends React.Component<
render() { render() {
const { screen, line, width, staticRender, visible } = this.props; const { screen, line, width, staticRender, visible } = this.props;
const isMinimized = line.linestate["wave:min"];
const isVisible = visible.get(); const isVisible = visible.get();
if (staticRender || !isVisible) { if (staticRender || !isVisible) {
return this.renderSimple(); return this.renderSimple();
@ -678,19 +676,19 @@ class LineCmd extends React.Component<
<If condition={containerType == appconst.LineContainer_Main}> <If condition={containerType == appconst.LineContainer_Main}>
<div <div
key="minimize" key="minimize"
title={`${this.isMinimized.get() ? "Maximise" : "Minimize"}`} title={`${isMinimized ? "Maximise" : "Minimize"}`}
className={cn( className={cn(
"line-icon", "line-icon",
"line-minimize", "line-minimize",
"hoverEffect", "hoverEffect",
this.isMinimized.get() ? "line-icon-show" : "" isMinimized ? "line-icon-show" : ""
)} )}
onClick={this.clickMinimize} onClick={this.clickMinimize}
> >
<If condition={this.isMinimized.get()}> <If condition={isMinimized}>
<i className="fa-sharp fa-regular fa-circle-plus" /> <i className="fa-sharp fa-regular fa-circle-plus" />
</If> </If>
<If condition={!this.isMinimized.get()}> <If condition={!isMinimized}>
<i className="fa-sharp fa-regular fa-circle-minus" /> <i className="fa-sharp fa-regular fa-circle-minus" />
</If> </If>
</div> </div>
@ -717,7 +715,7 @@ class LineCmd extends React.Component<
&nbsp;&nbsp;showing in sidebar =&gt; &nbsp;&nbsp;showing in sidebar =&gt;
</div> </div>
</If> </If>
<If condition={!this.isMinimized.get() && !isInSidebar}> <If condition={!isMinimized && !isInSidebar}>
<ErrorBoundary plugin={rendererPlugin?.name} lineContext={lineutil.getRendererContext(line)}> <ErrorBoundary plugin={rendererPlugin?.name} lineContext={lineutil.getRendererContext(line)}>
<If condition={rendererPlugin == null && !isNoneRenderer}> <If condition={rendererPlugin == null && !isNoneRenderer}>
<TerminalRenderer <TerminalRenderer

View File

@ -6,7 +6,7 @@ import * as mobxReact from "mobx-react";
import * as mobx from "mobx"; import * as mobx from "mobx";
import { debounce } from "throttle-debounce"; import { debounce } from "throttle-debounce";
import * as util from "@/util"; import * as util from "@/util/util";
import { GlobalModel } from "@/models"; import { GlobalModel } from "@/models";
class SimpleBlobRendererModel { class SimpleBlobRendererModel {

View File

@ -77,6 +77,11 @@ class CommandRunner {
return GlobalModel.submitCommand("line", "delete", [lineArg], { nohist: "1" }, interactive); return GlobalModel.submitCommand("line", "delete", [lineArg], { nohist: "1" }, interactive);
} }
lineMinimize(lineId: string, minimize: boolean, interactive: boolean): Promise<CommandRtnType> {
let minimizeStr = minimize ? "1" : "0";
return GlobalModel.submitCommand("line", "minimize", [lineId, minimizeStr], { nohist: "1" }, interactive);
}
lineRestart(lineArg: string, interactive: boolean): Promise<CommandRtnType> { lineRestart(lineArg: string, interactive: boolean): Promise<CommandRtnType> {
return GlobalModel.submitCommand("line", "restart", [lineArg], { nohist: "1" }, interactive); return GlobalModel.submitCommand("line", "restart", [lineArg], { nohist: "1" }, interactive);
} }

View File

@ -217,6 +217,7 @@ func init() {
registerCmdFn("line:view", LineViewCommand) registerCmdFn("line:view", LineViewCommand)
registerCmdFn("line:set", LineSetCommand) registerCmdFn("line:set", LineSetCommand)
registerCmdFn("line:restart", LineRestartCommand) registerCmdFn("line:restart", LineRestartCommand)
registerCmdFn("line:minimize", LineMinimizeCommand)
registerCmdFn("client", ClientCommand) registerCmdFn("client", ClientCommand)
registerCmdFn("client:show", ClientShowCommand) registerCmdFn("client:show", ClientShowCommand)
@ -4325,6 +4326,51 @@ func LineArchiveCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (
return update, nil return update, nil
} }
func LineMinimizeCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (scbus.UpdatePacket, error) {
ids, err := resolveUiIds(ctx, pk, R_Session|R_Screen)
if err != nil {
return nil, err
}
if len(pk.Args) == 0 {
return nil, fmt.Errorf("/line:minimize requires arguments (line number or id and min value)")
}
if len(pk.Args) > 2 {
return nil, fmt.Errorf("/line:minimize only takes up to 2 argument (line number or id and min value)")
}
lineArg1 := pk.Args[0]
lineId, err := sstore.FindLineIdByArg(ctx, ids.ScreenId, lineArg1)
if err != nil {
return nil, fmt.Errorf("error looking up lineid: %v", err)
}
if lineId == "" {
return nil, fmt.Errorf("line %q not found", lineArg1)
}
lineArg2 := pk.Args[1]
minVal := resolveBool(lineArg2, true)
lineState := make(map[string]any)
if minVal {
lineState[sstore.LineState_Min] = minVal
} else {
// Remove sstore.LineState_Min from lineState if it exists
delete(lineState, sstore.LineState_Min)
}
err = sstore.UpdateLineState(ctx, ids.ScreenId, lineId, lineState)
if err != nil {
return nil, fmt.Errorf("cannot update linestate: %v", err)
}
lineObj, err := sstore.GetLineById(ctx, ids.ScreenId, lineId)
if err != nil {
return nil, fmt.Errorf("/line:minimize cannot retrieve updated line: %v", err)
}
if lineObj == nil {
// no line (which is strange given we checked for it above). just return a nop.
return nil, nil
}
update := scbus.MakeUpdatePacket()
sstore.AddLineUpdate(update, lineObj, nil)
return update, nil
}
func LineDeleteCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (scbus.UpdatePacket, error) { func LineDeleteCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (scbus.UpdatePacket, error) {
ids, err := resolveUiIds(ctx, pk, R_Session|R_Screen) ids, err := resolveUiIds(ctx, pk, R_Session|R_Screen)
if err != nil { if err != nil {

View File

@ -63,6 +63,7 @@ const (
const ( const (
LineState_Source = "prompt:source" LineState_Source = "prompt:source"
LineState_File = "prompt:file" LineState_File = "prompt:file"
LineState_Min = "wave:min"
LineState_Template = "template" LineState_Template = "template"
LineState_Mode = "mode" LineState_Mode = "mode"
LineState_Lang = "lang" LineState_Lang = "lang"