updates for rtnstate

This commit is contained in:
sawka 2022-10-27 00:36:03 -07:00
parent babf4f392a
commit bb7f475055
5 changed files with 116 additions and 7 deletions

View File

@ -189,6 +189,8 @@ class Prompt extends React.Component<{rptr : RemotePtrType, rstate : RemoteState
class LineCmd extends React.Component<{sw : ScreenWindow, line : LineType, width : number, staticRender : boolean, visible : OV<boolean>, onHeightChange : HeightChangeCallbackType}, {}> {
termLoaded : mobx.IObservableValue<boolean> = mobx.observable.box(false);
lineRef : React.RefObject<any> = React.createRef();
rtnStateDiff : mobx.IObservableValue<string> = mobx.observable.box(null);
rtnStateDiffFetched : boolean = false;
constructor(props) {
super(props);
@ -209,6 +211,28 @@ class LineCmd extends React.Component<{sw : ScreenWindow, line : LineType, width
}
}
checkStateDiffLoad() : void {
let {line, staticRender, visible} = this.props;
if (staticRender) {
return;
}
if (!visible) {
if (this.rtnStateDiffFetched) {
this.rtnStateDiffFetched = false;
this.setRtnStateDiff(null);
}
return;
}
let cmd = GlobalModel.getCmd(line);
if (cmd == null || !cmd.getRtnState() || this.rtnStateDiffFetched) {
return;
}
if (cmd.getStatus() != "done") {
return;
}
this.fetchRtnStateDiff();
}
loadTerminal() : void {
let {sw, line} = this.props;
let model = GlobalModel;
@ -239,6 +263,32 @@ class LineCmd extends React.Component<{sw : ScreenWindow, line : LineType, width
}
}
fetchRtnStateDiff() : void {
if (this.rtnStateDiffFetched) {
return;
}
let {line} = this.props;
this.rtnStateDiffFetched = true;
let usp = new URLSearchParams({sessionid: line.sessionid, cmdid: line.cmdid});
let url = "http://localhost:8080/api/rtnstate?" + usp.toString();
fetch(url).then((resp) => {
if (!resp.ok) {
throw new Error(sprintf("Bad fetch response for /api/rtnstate: %d %s", resp.status, resp.statusText));
}
return resp.text();
}).then((text) => {
this.setRtnStateDiff(text ?? "");
}).catch((err) => {
this.setRtnStateDiff("ERROR " + err.toString())
});
}
setRtnStateDiff(val : string) : void {
mobx.action(() => {
this.rtnStateDiff.set(val);
})();
}
componentDidMount() {
}
@ -310,6 +360,7 @@ class LineCmd extends React.Component<{sw : ScreenWindow, line : LineType, width
this.props.onHeightChange(line.linenum, curHeight, snapshot.height);
}
this.checkLoad();
this.checkStateDiffLoad();
}
render() {
@ -340,7 +391,7 @@ class LineCmd extends React.Component<{sw : ScreenWindow, line : LineType, width
let isFgFocused = isPhysicalFocused && swFocusType == "cmd-fg";
let isStatic = staticRender;
return (
<div className={cn("line", "line-cmd", {"focus": isFocused})} id={"line-" + getLineId(line)} ref={this.lineRef} style={{position: "relative"}} data-lineid={line.lineid} data-linenum={line.linenum} data-windowid={line.windowid} data-cmdid={line.cmdid}>
<div className={cn("line", "line-cmd", {"focus": isFocused}, {"has-rtnstate": cmd.getRtnState()})} id={"line-" + getLineId(line)} ref={this.lineRef} style={{position: "relative"}} data-lineid={line.lineid} data-linenum={line.linenum} data-windowid={line.windowid} data-cmdid={line.cmdid}>
<div className={cn("focus-indicator", {"selected": isSelected}, {"active": isSelected && isFocused}, {"fg-focus": isFgFocused})}/>
<div className="line-header">
<div className={cn("avatar", "num-"+lineNumStr.length, "status-" + status, {"ephemeral": line.ephemeral})} onClick={this.doRefresh}>
@ -366,13 +417,26 @@ class LineCmd extends React.Component<{sw : ScreenWindow, line : LineType, width
</div>
</div>
</div>
<div className={cn("terminal-wrapper", {"focus": isFocused}, {"cmd-done": !cmd.isRunning()})}>
<div className={cn("terminal-wrapper", {"focus": isFocused}, {"cmd-done": !cmd.isRunning()}, {"zero-height": (termHeight == 0)})}>
<If condition={!isFocused}>
<div className="term-block" onClick={this.clickTermBlock}></div>
</If>
<div className="terminal-connectelem" id={"term-" + getLineId(line)} data-cmdid={line.cmdid} style={{height: termHeight}}></div>
<If condition={!termLoaded}><div style={{position: "absolute", top: 60, left: 30}}>(loading)</div></If>
</div>
<If condition={cmd.getRtnState() && cmd.getStatus() == "done"}>
<div className="cmd-rtnstate">
<If condition={this.rtnStateDiff.get() == ""}>
<div className="cmd-rtnstate-label">state unchanged</div>
<div className="cmd-rtnstate-sep"></div>
</If>
<If condition={this.rtnStateDiff.get() != null && this.rtnStateDiff.get() != ""}>
<div className="cmd-rtnstate-label">new state</div>
<div className="cmd-rtnstate-sep"></div>
<div className="cmd-rtnstate-diff">{this.rtnStateDiff.get()}</div>
</If>
</div>
</If>
</div>
);
}

View File

@ -138,6 +138,10 @@ class Cmd {
})();
}
getRtnState() : boolean {
return this.data.get().rtnstate;
}
getStatus() : string {
return this.data.get().status;
}
@ -1374,8 +1378,8 @@ class InputModel {
resetInputMode() : void {
mobx.action(() => {
inputModel.setInputMode(null);
inputModel.setCurLine("");
this.setInputMode(null);
this.setCurLine("");
})();
}
@ -2018,7 +2022,7 @@ class Model {
_loadWindowAsync(newWin : Window) {
this.windows.set(newWin.sessionId + "/" + newWin.windowId, newWin);
let usp = new URLSearchParams({sessionid: newWin.sessionId, windowid: newWin.windowId});
let url = new URL(sprintf("http://localhost:8080/api/get-window?") + usp.toString());
let url = new URL("http://localhost:8080/api/get-window?" + usp.toString());
fetch(url).then((resp) => handleJsonFetchResponse(url, resp)).then((data) => {
if (data.data == null) {
console.log("null window returned from get-window");

View File

@ -410,6 +410,11 @@ html, body, #main {
background-color: #000;
}
&.has-rtnstate .terminal-wrapper {
padding-bottom: 0;
margin-bottom: -5px;
}
.terminal-wrapper {
background-color: #000;
padding: 2px 10px 5px 4px;
@ -418,6 +423,10 @@ html, body, #main {
margin-top: 4px;
align-self: flex-start;
&.zero-height {
display: none;
}
&.focus {
/* box-shadow: 0 0 3px 3px rgba(255, 255, 255, 0.3); */
}
@ -435,6 +444,37 @@ html, body, #main {
display: none;
}
}
.cmd-rtnstate {
position: relative;
.cmd-rtnstate-label {
position: relative;
z-index: 2;
.mono-font(9px);
margin-left: 10px;
padding: 2px 5px 2px 5px;
color: #666;
background-color: black;
display: inline-block;
}
.cmd-rtnstate-sep {
height: 1px;
border-bottom: 1px solid #222;
position: relative;
top: -8px;
width: min(300px, 50%);
margin-bottom: -3px;
}
.cmd-rtnstate-diff {
color: @term-white;
.mono-font(12px);
white-space: pre;
margin-left: 15px;
}
}
}
.cmd-input-info {

View File

@ -254,7 +254,7 @@ class TermWrap {
if (ptyOffsetStr != null && !isNaN(parseInt(ptyOffsetStr))) {
ptyOffset = parseInt(ptyOffsetStr);
}
return resp.arrayBuffer()
return resp.arrayBuffer();
}).then((buf) => {
setTimeout(() => {
this.reloading = false;

View File

@ -26,6 +26,7 @@ type LineType = {
linetype : string,
text : string,
cmdid : string,
contentheight : number,
ephemeral? : boolean,
remove? : boolean,
};
@ -246,7 +247,7 @@ type CmdDataType = {
startpk : CmdStartPacketType,
donepk : CmdDonePacketType,
runout : any[],
usedrows : number,
rtnstate : boolean,
remove? : boolean,
};