diff --git a/src/main.tsx b/src/main.tsx index f01394bfa..35a9f7f43 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -403,12 +403,11 @@ class TextAreaInput extends React.Component<{}, {}> { if (e.code == "Tab") { e.preventDefault(); if (lastTab) { - GlobalModel.submitCommand("compgen", null, [curLine], {"comppos": String(curLine.length), "compshow": "1", "nohist": "1"}); + GlobalModel.submitCommand("compgen", null, [curLine], {"comppos": String(curLine.length), "compshow": "1", "nohist": "1"}, true); return; } else { - GlobalModel.submitCommand("compgen", null, [curLine], {"comppos": String(curLine.length), "nohist": "1"}); - GlobalModel.clearInfoMsg(true); + GlobalModel.submitCommand("compgen", null, [curLine], {"comppos": String(curLine.length), "nohist": "1"}, true); return; } } diff --git a/src/model.ts b/src/model.ts index c3f7f7434..3d974ca7c 100644 --- a/src/model.ts +++ b/src/model.ts @@ -587,8 +587,7 @@ class InputModel { return; } this.clearCurLine(); - GlobalModel.clearInfoMsg(true); - GlobalModel.submitRawCommand(commandStr, true); + GlobalModel.submitRawCommand(commandStr, true, true); })(); } @@ -1012,7 +1011,7 @@ class Model { if ("window" in update) { this.updateWindow(update.window, false); } - if ("info" in update) { + if (interactive && "info" in update) { let info : InfoType = update.info; this.flashInfoMsg(info, info.timeoutms); } @@ -1146,13 +1145,16 @@ class Model { return rtn; } - submitCommandPacket(cmdPk : FeCmdPacketType) { + submitCommandPacket(cmdPk : FeCmdPacketType, interactive : boolean) { let url = sprintf("http://localhost:8080/api/run-command"); fetch(url, {method: "post", body: JSON.stringify(cmdPk)}).then((resp) => handleJsonFetchResponse(url, resp)).then((data) => { mobx.action(() => { let update = data.data; if (update != null) { - this.runUpdate(update, true); + this.runUpdate(update, interactive); + } + if (interactive && (update == null || update.info == null)) { + GlobalModel.clearInfoMsg(true); } })(); }).catch((err) => { @@ -1160,7 +1162,7 @@ class Model { }); } - submitCommand(metaCmd : string, metaSubCmd : string, args : string[], kwargs : Record) { + submitCommand(metaCmd : string, metaSubCmd : string, args : string[], kwargs : Record, interactive : boolean) { let pk : FeCmdPacketType = { type: "fecmd", metacmd: metaCmd, @@ -1168,10 +1170,10 @@ class Model { args: args, kwargs: Object.assign({}, this.getClientKwargs(), kwargs), }; - this.submitCommandPacket(pk); + this.submitCommandPacket(pk, interactive); } - submitRawCommand(cmdStr : string, addToHistory : boolean) { + submitRawCommand(cmdStr : string, addToHistory : boolean, interactive : boolean) : void { let pk : FeCmdPacketType = { type: "fecmd", metacmd: "eval", @@ -1181,7 +1183,7 @@ class Model { if (!addToHistory) { pk.kwargs["nohist"] = "1"; } - this.submitCommandPacket(pk) + this.submitCommandPacket(pk, interactive) } loadSessionList() { @@ -1326,24 +1328,36 @@ class InputClass { constructor() { } + clearCmdInput() : void { + mobx.action(() => { + GlobalModel.clearInfoMsg(true); + GlobalModel.clearCurLine(); + })(); + } + switchSession(session : string) { - GlobalModel.submitCommand("session", null, [session], {"nohist": "1"}); + GlobalModel.submitCommand("session", null, [session], {"nohist": "1"}, false); + this.clearCmdInput(); } switchScreen(screen : string) { - GlobalModel.submitCommand("screen", null, [screen], {"nohist": "1"}); + GlobalModel.submitCommand("screen", null, [screen], {"nohist": "1"}, false); + this.clearCmdInput(); } createNewSession() { - GlobalModel.submitCommand("session", "open", null, {"nohist": "1"}); + GlobalModel.submitCommand("session", "open", null, {"nohist": "1"}, false); + this.clearCmdInput(); } createNewScreen() { - GlobalModel.submitCommand("screen", "open", null, {"nohist": "1"}); + GlobalModel.submitCommand("screen", "open", null, {"nohist": "1"}, false); + this.clearCmdInput(); } closeScreen(screen : string) { - GlobalModel.submitCommand("screen", "close", [screen], {"nohist": "1"}); + GlobalModel.submitCommand("screen", "close", [screen], {"nohist": "1"}, false); + this.clearCmdInput(); } }; diff --git a/src/session.ts b/src/session.ts deleted file mode 100644 index 6ac30c981..000000000 --- a/src/session.ts +++ /dev/null @@ -1,390 +0,0 @@ -import * as mobx from "mobx"; -import {sprintf} from "sprintf-js"; -import {boundMethod} from "autobind-decorator"; -import {handleJsonFetchResponse} from "./util"; -import {TermWrap} from "./term"; -import {v4 as uuidv4} from "uuid"; -import type {SessionDataType, WindowDataType, LineType, RemoteType, HistoryItem, RemoteInstanceType, CmdDataType, FeCmdPacketType} from "./types"; - -var GlobalUser = "sawka"; - -type WindowType = { - sessionid : string, - windowid : string, - name : string, - curremote : string, - lines : mobx.IObservableArray, - linesLoading : mobx.IObservableValue, - version : number, -}; - -function makeTermKey(sessionId : string, cmdId : string, windowId : string, lineid : number) : string { - return sprintf("%s/%s/%s/%s", sessionId, cmdId, windowId, lineid); -} - -function getLineId(line : LineType) : string { - return sprintf("%s-%s-%s", line.sessionid, line.windowid, line.lineid); -} - -class Session { - sessionId : string; - name : string; - windows : WindowType[]; - activeWindowId : mobx.IObservableValue = mobx.observable.box(null); - termMap : Record = {}; - termMapById : Record = {}; - history : HistoryItem[] = []; - loading : mobx.IObservableValue = mobx.observable.box(true); - remotes : RemoteInstanceType[] = []; - globalRemotes : RemoteType[]; - cmds : CmdDataType[]; - - constructor() { - } - - getWindowCurRemoteData(windowid : string) : RemoteInstanceType { - let win = this.getWindowById(windowid); - if (win == null) { - return null; - } - let rname = win.curremote; - let sessionScope = false; - if (rname.startsWith("^")) { - rname = rname.substr(1); - sessionScope = true; - } - for (let i=0; i { - for (let i=0; i handleJsonFetchResponse(url, resp)).then((data) => { - if (data.data == null) { - console.log("null window returned from get-window"); - return; - } - this.setWindowInSession(data.data); - return; - }).catch((err) => { - console.log(sprintf("error getting window=%s lines", windowid), err) - }); - } - - getCmd(cmdId : string) : CmdDataType { - if (!cmdId) { - return null; - } - for (let i=0; i handleJsonFetchResponse(url, resp)).then((data) => { - mobx.action(() => { - if (data.data != null && data.data.line != null) { - let line = data.data.line; - line.isnew = true; - this.addLine(line); - } - if (data.data != null && data.data.cmd != null) { - this.cmds.push(data.data.cmd); - } - })(); - }).catch((err) => { - console.log("error calling run-command", err) - }); - } - - addLine(line : LineType) { - if (line.sessionid != this.sessionId) { - return; - } - let window = this.getWindowById(line.windowid); - if (window == null) { - return; - } - mobx.action(() => { - let lines = window.lines; - let lineIdx = 0; - for (lineIdx=0; lineIdx line.lineid) { - break; - } - } - if (lineIdx == lines.length) { - window.lines.push(line); - return; - } - window.lines.splice(lineIdx, 0, line); - })(); - return; - } - - addToHistory(hitem : HistoryItem) { - this.history.push(hitem); - } - - getNumHistoryItems() : number { - return this.history.length; - } - - getHistoryItem(index : number) : HistoryItem { - if (index == 0) { - return null; - } - if (index > 0) { - if (index > this.history.length-1) { - return null; - } - return this.history[index]; - } - let absIndex = Math.abs(index); - if (absIndex > this.history.length) { - return null; - } - return this.history[this.history.length-absIndex]; - } - - getTermWrapByLine(line : LineType) : TermWrap { - if (!line.cmdid) { - return null; - } - let termKey = makeTermKey(line.sessionid, line.cmdid, line.windowid, line.lineid); - let termWrap = this.termMap[termKey]; - if (termWrap != null) { - return termWrap; - } - let cmd = this.getCmd(line.cmdid); - if (!cmd) { - return null; - } - termWrap = new TermWrap(line.sessionid, line.cmdid, cmd.remoteid, cmd.status); - this.termMap[termKey] = termWrap; - this.termMapById[termWrap.termId] = termWrap; - termWrap.initialized = true; - termWrap.reloadTerminal(true, 0); - return termWrap; - } - - getTermById(termId : string) : TermWrap { - return this.termMapById[termId]; - } - - recvCmdData(termWrap : TermWrap, pk : any) { - console.log("cmddata", pk); - } - - getActiveWindow() : WindowType { - if (this.windows == null || this.windows.length == 0) { - return null; - } - let awid = this.activeWindowId.get(); - for (let i=0; i = mobx.observable.array([]); -var CurrentSession : Session = new Session(); -var CurrentSessionId : mobx.IObservableValue = mobx.observable.box(null); - -function initSession(sessionId : string, force : boolean) { - if (CurrentSession.loading.get() && !force) { - return; - } - let remotesLoaded = false; - let sessionLoaded = false; - CurrentSession.loading.set(true); - fetch("http://localhost:8080/api/get-remotes").then((resp) => handleJsonFetchResponse(url, resp)).then((data) => { - mobx.action(() => { - CurrentSession.globalRemotes = data.data - remotesLoaded = true; - if (remotesLoaded && sessionLoaded) { - CurrentSession.loading.set(false); - } - })(); - }).catch((err) => { - console.log("error calling get-remotes", err) - }); - - let usp = new URLSearchParams({sessionid: sessionId}); - let url = new URL(sprintf("http://localhost:8080/api/get-session?") + usp.toString()); - fetch(url).then((resp) => handleJsonFetchResponse(url, resp)).then((data) => { - mobx.action(() => { - let sdata = data.data; - CurrentSession.sessionId = sdata.sessionid; - CurrentSession.name = sdata.name; - CurrentSession.windows = []; - for (let i=0; i { - console.log("error calling get-session", err) - }); -} - -function winDataToWindow(win : WindowDataType) : WindowType { - let w = { - sessionid: win.sessionid, - windowid: win.windowid, - name: win.name, - curremote: win.curremote, - lines: mobx.observable.array(win.lines || []), - linesLoading: mobx.observable.box(false), - version: win.version, - }; - return w; -} - -function getCurrentSession() : Session { - return CurrentSession; -} - -function newSession() { - -} - -function loadSessionList(init : boolean) { - let url = new URL("http://localhost:8080/api/get-all-sessions"); - fetch(url).then((resp) => handleJsonFetchResponse(url, resp)).then((data) => { - mobx.action(() => { - SessionList.replace(data.data || []); - if (init) { - for (let i=0; i { - console.log("error getting session list"); - }); -} - -function getAllSessions() : mobx.IObservableArray { - return SessionList; -} - -function setCurrentSessionId(sessionId : string) { - if (CurrentSessionId.get() == sessionId) { - return; - } - mobx.action(() => { - CurrentSessionId.set(sessionId); - initSession(sessionId, true); - })(); -} - -function getCurrentSessionId() : string { - return CurrentSessionId.get(); -} - -export {Session, getCurrentSession, getLineId, newSession, loadSessionList, getAllSessions, getCurrentSessionId};