mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-30 23:01:30 +01:00
update prompt for remotes, display remotes in sidebar
This commit is contained in:
parent
c310a4b9bc
commit
5a835e927e
31
src/main.tsx
31
src/main.tsx
@ -55,20 +55,19 @@ function getRemoteStr(remote : RemoteType) : string {
|
||||
return "(no remote)";
|
||||
}
|
||||
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) {
|
||||
return sprintf("%s@%s", remote.remotevars.remoteuser, remote.remotevars.remotehost);
|
||||
let hoststr = "";
|
||||
if (remote.remotevars.sudo) {
|
||||
hoststr = sprintf("sudo@%s@%s", remote.remotevars.user, remote.remotevars.host)
|
||||
}
|
||||
else {
|
||||
let host = remote.remotevars.host || "unknown";
|
||||
if (remote.remotevars.user) {
|
||||
return sprintf("%s@%s", remote.remotevars.user, host)
|
||||
}
|
||||
else {
|
||||
return host;
|
||||
}
|
||||
hoststr = sprintf("%s@%s", remote.remotevars.user, remote.remotevars.host)
|
||||
}
|
||||
if (remote.remotevars.alias) {
|
||||
return sprintf("(%s) %s", remote.remotevars.alias, hoststr)
|
||||
}
|
||||
return hoststr;
|
||||
}
|
||||
|
||||
function replaceHomePath(path : string, homeDir : string) : string {
|
||||
@ -450,12 +449,14 @@ class CmdInput extends React.Component<{}, {}> {
|
||||
if (win != null) {
|
||||
ri = win.getCurRemoteInstance();
|
||||
}
|
||||
console.log("cmd-input remote", ri);
|
||||
let remote : RemoteType = null;
|
||||
let remoteState : RemoteStateType = null;
|
||||
if (ri != null) {
|
||||
remote = GlobalModel.getRemote(ri.remoteid);
|
||||
remoteState = ri.state;
|
||||
}
|
||||
console.log("lookup remote", remote);
|
||||
let promptStr = getRemoteStr(remote);
|
||||
let cwdStr = getCwdStr(remote, remoteState);
|
||||
let infoMsg = GlobalModel.infoMsg.get();
|
||||
@ -850,6 +851,8 @@ class MainSideBar extends React.Component<{}, {}> {
|
||||
let model = GlobalModel;
|
||||
let activeSessionId = model.activeSessionId.get();
|
||||
let session : Session = null;
|
||||
let remotes = model.remotes;
|
||||
let remote : RemoteType = null;
|
||||
return (
|
||||
<div className={cn("main-sidebar", {"collapsed": this.collapsed.get()})}>
|
||||
<div className="collapse-container">
|
||||
@ -912,11 +915,9 @@ class MainSideBar extends React.Component<{}, {}> {
|
||||
Remotes
|
||||
</p>
|
||||
<ul className="menu-list">
|
||||
<li><a><i className="status fa fa-circle"/>local</a></li>
|
||||
<li><a><i className="status fa fa-circle"/>local-sudo</a></li>
|
||||
<li><a><i className="status offline fa fa-circle"/>mike@app01.ec2</a></li>
|
||||
<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>
|
||||
<For each="remote" of={remotes}>
|
||||
<li><a><i className={cn("remote-status fa fa-circle", "status-" + remote.status)}/>{remote.remotealias ?? remote.remotecanonicalname}</a></li>
|
||||
</For>
|
||||
</ul>
|
||||
<div className="bottom-spacer"></div>
|
||||
</div>
|
||||
|
81
src/model.ts
81
src/model.ts
@ -367,32 +367,68 @@ class Window {
|
||||
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) {
|
||||
if (!this.loaded.get()) {
|
||||
return;
|
||||
}
|
||||
mobx.action(() => {
|
||||
if (cmd != null) {
|
||||
this.cmds[cmd.cmdid] = new Cmd(cmd);
|
||||
this.mergeCmd(cmd);
|
||||
}
|
||||
let lines = this.lines;
|
||||
let lineIdx = 0;
|
||||
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;
|
||||
if (line != null) {
|
||||
let lines = this.lines;
|
||||
if (line.remove) {
|
||||
for (let i=0; i<lines.length; i++) {
|
||||
if (lines[i].lineid == line.lineid) {
|
||||
this.lines.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (curTs > line.ts || (curTs == line.ts && lineId > line.lineid)) {
|
||||
break;
|
||||
let lineIdx = 0;
|
||||
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;
|
||||
remotes : OArr<RemoteType> = mobx.observable.array([], {deep: 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);
|
||||
infoMsg : OV<InfoType> = mobx.observable.box(null);
|
||||
infoTimeoutId : any = null;
|
||||
@ -940,7 +976,12 @@ class Model {
|
||||
}
|
||||
if ("line" in 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) {
|
||||
let winMsg : WindowUpdateType = update;
|
||||
@ -1057,6 +1098,12 @@ class Model {
|
||||
win.addLineCmd(line, cmd, interactive);
|
||||
}
|
||||
|
||||
updateCmd(cmd : CmdDataType) {
|
||||
this.windows.forEach((win : Window) => {
|
||||
win.updateCmd(cmd);
|
||||
});
|
||||
}
|
||||
|
||||
getClientKwargs() : Record<string, string> {
|
||||
let session = this.getActiveSession();
|
||||
let win = this.getActiveWindow();
|
||||
|
16
src/sh2.less
16
src/sh2.less
@ -246,6 +246,22 @@ html, body, #main {
|
||||
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 {
|
||||
font-size: 8px;
|
||||
margin-right: 5px;
|
||||
|
@ -117,10 +117,11 @@ class TermWrap {
|
||||
if (termYPos >= usedRows) {
|
||||
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);
|
||||
if (line != null && line.trim() != "") {
|
||||
usedRows = i+1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return usedRows;
|
||||
|
@ -176,6 +176,7 @@ type CmdDataType = {
|
||||
donepk : CmdDonePacketType,
|
||||
runout : any[],
|
||||
usedrows : number,
|
||||
remove? : boolean,
|
||||
};
|
||||
|
||||
type PtyDataUpdateType = {
|
||||
|
Loading…
Reference in New Issue
Block a user