update prompt for remotes, display remotes in sidebar

This commit is contained in:
sawka 2022-08-17 13:06:47 -07:00
parent c310a4b9bc
commit 5a835e927e
5 changed files with 99 additions and 33 deletions

View File

@ -55,20 +55,19 @@ function getRemoteStr(remote : RemoteType) : string {
return "(no remote)"; return "(no remote)";
} }
if (remote.remotevars.local) { if (remote.remotevars.local) {
return sprintf("%s@%s", remote.remotevars.remoteuser, "local") return sprintf("%s@%s", remote.remotevars.user, "local");
} }
else if (remote.remotevars.remotehost) { let hoststr = "";
return sprintf("%s@%s", remote.remotevars.remoteuser, remote.remotevars.remotehost); if (remote.remotevars.sudo) {
hoststr = sprintf("sudo@%s@%s", remote.remotevars.user, remote.remotevars.host)
} }
else { else {
let host = remote.remotevars.host || "unknown"; hoststr = sprintf("%s@%s", remote.remotevars.user, remote.remotevars.host)
if (remote.remotevars.user) {
return sprintf("%s@%s", remote.remotevars.user, host)
}
else {
return host;
}
} }
if (remote.remotevars.alias) {
return sprintf("(%s) %s", remote.remotevars.alias, hoststr)
}
return hoststr;
} }
function replaceHomePath(path : string, homeDir : string) : string { function replaceHomePath(path : string, homeDir : string) : string {
@ -450,12 +449,14 @@ class CmdInput extends React.Component<{}, {}> {
if (win != null) { if (win != null) {
ri = win.getCurRemoteInstance(); ri = win.getCurRemoteInstance();
} }
console.log("cmd-input remote", ri);
let remote : RemoteType = null; let remote : RemoteType = null;
let remoteState : RemoteStateType = null; let remoteState : RemoteStateType = null;
if (ri != null) { if (ri != null) {
remote = GlobalModel.getRemote(ri.remoteid); remote = GlobalModel.getRemote(ri.remoteid);
remoteState = ri.state; remoteState = ri.state;
} }
console.log("lookup remote", remote);
let promptStr = getRemoteStr(remote); let promptStr = getRemoteStr(remote);
let cwdStr = getCwdStr(remote, remoteState); let cwdStr = getCwdStr(remote, remoteState);
let infoMsg = GlobalModel.infoMsg.get(); let infoMsg = GlobalModel.infoMsg.get();
@ -850,6 +851,8 @@ class MainSideBar extends React.Component<{}, {}> {
let model = GlobalModel; let model = GlobalModel;
let activeSessionId = model.activeSessionId.get(); let activeSessionId = model.activeSessionId.get();
let session : Session = null; let session : Session = null;
let remotes = model.remotes;
let remote : RemoteType = null;
return ( return (
<div className={cn("main-sidebar", {"collapsed": this.collapsed.get()})}> <div className={cn("main-sidebar", {"collapsed": this.collapsed.get()})}>
<div className="collapse-container"> <div className="collapse-container">
@ -912,11 +915,9 @@ class MainSideBar extends React.Component<{}, {}> {
Remotes Remotes
</p> </p>
<ul className="menu-list"> <ul className="menu-list">
<li><a><i className="status fa fa-circle"/>local</a></li> <For each="remote" of={remotes}>
<li><a><i className="status fa fa-circle"/>local-sudo</a></li> <li><a><i className={cn("remote-status fa fa-circle", "status-" + remote.status)}/>{remote.remotealias ?? remote.remotecanonicalname}</a></li>
<li><a><i className="status offline fa fa-circle"/>mike@app01.ec2</a></li> </For>
<li><a><i className="status fa fa-circle"/>mike@test01.ec2</a></li>
<li><a><i className="status offline fa fa-circle"/>root@app01.ec2</a></li>
</ul> </ul>
<div className="bottom-spacer"></div> <div className="bottom-spacer"></div>
</div> </div>

View File

@ -367,32 +367,68 @@ class Window {
return null; return null;
} }
updateCmd(cmd : CmdDataType) : void {
if (cmd.remove) {
throw new Error("cannot remove cmd with updateCmd call [" + cmd.cmdid + "]");
}
let origCmd = this.cmds[cmd.cmdid];
if (origCmd != null) {
origCmd.setCmd(cmd);
}
return;
}
mergeCmd(cmd : CmdDataType) : void {
if (cmd.remove) {
delete this.cmds[cmd.cmdid];
return;
}
let origCmd = this.cmds[cmd.cmdid];
if (origCmd == null) {
this.cmds[cmd.cmdid] = new Cmd(cmd);
return;
}
origCmd.setCmd(cmd);
return;
}
addLineCmd(line : LineType, cmd : CmdDataType, interactive : boolean) { addLineCmd(line : LineType, cmd : CmdDataType, interactive : boolean) {
if (!this.loaded.get()) { if (!this.loaded.get()) {
return; return;
} }
mobx.action(() => { mobx.action(() => {
if (cmd != null) { if (cmd != null) {
this.cmds[cmd.cmdid] = new Cmd(cmd); this.mergeCmd(cmd);
} }
let lines = this.lines; if (line != null) {
let lineIdx = 0; let lines = this.lines;
for (lineIdx=0; lineIdx<lines.length; lineIdx++) { if (line.remove) {
let lineId = lines[lineIdx].lineid; for (let i=0; i<lines.length; i++) {
let curTs = lines[lineIdx].ts; if (lines[i].lineid == line.lineid) {
if (lineId == line.lineid) { this.lines.splice(i, 1);
this.lines[lineIdx] = line; break;
}
}
return; return;
} }
if (curTs > line.ts || (curTs == line.ts && lineId > line.lineid)) { let lineIdx = 0;
break; for (lineIdx=0; lineIdx<lines.length; lineIdx++) {
let lineId = lines[lineIdx].lineid;
let curTs = lines[lineIdx].ts;
if (lineId == line.lineid) {
this.lines[lineIdx] = line;
return;
}
if (curTs > line.ts || (curTs == line.ts && lineId > line.lineid)) {
break;
}
} }
if (lineIdx == lines.length) {
this.lines.push(line);
return;
}
this.lines.splice(lineIdx, 0, line);
} }
if (lineIdx == lines.length) {
this.lines.push(line);
return;
}
this.lines.splice(lineIdx, 0, line);
})(); })();
} }
}; };
@ -679,7 +715,7 @@ class Model {
ws : WSControl; ws : WSControl;
remotes : OArr<RemoteType> = mobx.observable.array([], {deep: false}); remotes : OArr<RemoteType> = mobx.observable.array([], {deep: false});
remotesLoaded : OV<boolean> = mobx.observable.box(false); remotesLoaded : OV<boolean> = mobx.observable.box(false);
windows : OMap<string, Window> = mobx.observable.map({}, {deep: false}); windows : OMap<string, Window> = mobx.observable.map({}, {deep: false}); // key = "sessionid/windowid"
infoShow : OV<boolean> = mobx.observable.box(false); infoShow : OV<boolean> = mobx.observable.box(false);
infoMsg : OV<InfoType> = mobx.observable.box(null); infoMsg : OV<InfoType> = mobx.observable.box(null);
infoTimeoutId : any = null; infoTimeoutId : any = null;
@ -940,7 +976,12 @@ class Model {
} }
if ("line" in update) { if ("line" in update) {
let lineMsg : LineCmdUpdateType = update; let lineMsg : LineCmdUpdateType = update;
this.addLineCmd(lineMsg.line, lineMsg.cmd, interactive); if (lineMsg.line != null) {
this.addLineCmd(lineMsg.line, lineMsg.cmd, interactive);
}
if (lineMsg.line == null && lineMsg.cmd != null) {
this.updateCmd(lineMsg.cmd);
}
} }
if ("window" in update) { if ("window" in update) {
let winMsg : WindowUpdateType = update; let winMsg : WindowUpdateType = update;
@ -1057,6 +1098,12 @@ class Model {
win.addLineCmd(line, cmd, interactive); win.addLineCmd(line, cmd, interactive);
} }
updateCmd(cmd : CmdDataType) {
this.windows.forEach((win : Window) => {
win.updateCmd(cmd);
});
}
getClientKwargs() : Record<string, string> { getClientKwargs() : Record<string, string> {
let session = this.getActiveSession(); let session = this.getActiveSession();
let win = this.getActiveWindow(); let win = this.getActiveWindow();

View File

@ -246,6 +246,22 @@ html, body, #main {
color: #ddd; color: #ddd;
} }
.remote-status {
font-size: 8px;
margin-right: 5px;
position: relative;
top: -3px;
color: #c4a000;
&.status-connected {
color: #4e9a06;
}
&.status-error, &.status-disconnected {
color: #cc0000;
}
}
.status { .status {
font-size: 8px; font-size: 8px;
margin-right: 5px; margin-right: 5px;

View File

@ -117,10 +117,11 @@ class TermWrap {
if (termYPos >= usedRows) { if (termYPos >= usedRows) {
usedRows = termYPos + 1; usedRows = termYPos + 1;
} }
for (let i=usedRows; i<term.rows; i++) { for (let i=term.rows-1; i>=usedRows; i--) {
let line = termBuf.translateBufferLineToString(i, true); let line = termBuf.translateBufferLineToString(i, true);
if (line != null && line.trim() != "") { if (line != null && line.trim() != "") {
usedRows = i+1; usedRows = i+1;
break;
} }
} }
return usedRows; return usedRows;

View File

@ -176,6 +176,7 @@ type CmdDataType = {
donepk : CmdDonePacketType, donepk : CmdDonePacketType,
runout : any[], runout : any[],
usedrows : number, usedrows : number,
remove? : boolean,
}; };
type PtyDataUpdateType = { type PtyDataUpdateType = {