From 3ad7feedad5abc47aec62c2482d8e010fcfc2381 Mon Sep 17 00:00:00 2001 From: Red Adaya Date: Thu, 8 Feb 2024 13:34:46 +0800 Subject: [PATCH] replace /model_old imports with /model --- src/app/app.tsx | 4 +- src/app/appconst.ts | 30 + src/app/bookmarks/bookmarks.tsx | 48 +- src/app/clientsettings/clientsettings.tsx | 28 +- src/app/common/elements/markdown.tsx | 2 +- src/app/common/elements/resizablesidebar.tsx | 2 +- .../elements/showwaveshellinstallprompt.tsx | 2 +- src/app/common/modals/about.tsx | 14 +- src/app/common/modals/alert.tsx | 2 +- src/app/common/modals/clientstop.tsx | 2 +- src/app/common/modals/createremoteconn.tsx | 2 +- src/app/common/modals/disconnected.tsx | 2 +- src/app/common/modals/editremoteconn.tsx | 2 +- src/app/common/modals/linesettings.tsx | 2 +- src/app/common/modals/provider.tsx | 2 +- src/app/common/modals/screensettings.tsx | 7 +- src/app/common/modals/sessionsettings.tsx | 2 +- src/app/common/modals/tabswitcher.tsx | 4 +- src/app/common/modals/tos.tsx | 2 +- .../common/modals/viewremoteconndetail.tsx | 2 +- src/app/common/prompt/prompt.tsx | 2 +- src/app/connections/connections.tsx | 2 +- src/app/history/history.tsx | 2 +- src/app/line/linecomps.tsx | 11 +- src/app/line/renderer/basicrenderer.tsx | 2 +- src/app/pluginsview/pluginsview.tsx | 2 +- src/app/sidebar/sidebar.tsx | 8 +- src/app/workspace/cmdinput/aichat.tsx | 2 +- src/app/workspace/cmdinput/cmdinput.tsx | 2 +- src/app/workspace/cmdinput/historyinfo.tsx | 2 +- src/app/workspace/cmdinput/infomsg.tsx | 2 +- src/app/workspace/cmdinput/textareainput.tsx | 2 +- src/app/workspace/screen/screenview.tsx | 15 +- src/app/workspace/screen/tab.tsx | 2 +- src/app/workspace/screen/tabs.tsx | 2 +- src/app/workspace/workspaceview.tsx | 2 +- src/model/bookmarks.ts | 2 +- src/model/commandrunner.ts | 437 --------------- src/model/forwardlinecontainer.ts | 117 ++++ src/model/historyview.ts | 2 +- src/model/index.ts | 4 +- src/model/input.ts | 2 +- src/model/model.ts | 514 ++++++++++++++++-- src/model/plugins.ts | 2 +- src/model/remotes.ts | 2 +- src/model/screen.ts | 6 +- src/plugins/code/code.tsx | 2 +- src/plugins/core/basicrenderer.tsx | 2 +- src/plugins/csv/csv.tsx | 2 +- src/plugins/mustache/mustache.tsx | 2 +- src/plugins/terminal/term.ts | 2 +- src/plugins/terminal/terminal.tsx | 2 +- src/types/types.ts | 4 +- 53 files changed, 724 insertions(+), 601 deletions(-) delete mode 100644 src/model/commandrunner.ts create mode 100644 src/model/forwardlinecontainer.ts diff --git a/src/app/app.tsx b/src/app/app.tsx index 77bab137c..48295fdcf 100644 --- a/src/app/app.tsx +++ b/src/app/app.tsx @@ -9,7 +9,7 @@ import { If } from "tsx-control-statements/components"; import dayjs from "dayjs"; import type { ContextMenuOpts } from "../types/types"; import localizedFormat from "dayjs/plugin/localizedFormat"; -import { GlobalModel } from "../model/model_old"; +import { GlobalModel } from "../model"; import { isBlank } from "../util/util"; import { WorkspaceView } from "./workspace/workspaceview"; import { PluginsView } from "./pluginsview/pluginsview"; @@ -32,7 +32,7 @@ class App extends React.Component<{}, {}> { dcWait: OV = mobx.observable.box(false, { name: "dcWait" }); mainContentRef: React.RefObject = React.createRef(); - constructor(props: any) { + constructor(props: {}) { super(props); if (GlobalModel.isDev) document.body.className = "is-dev"; } diff --git a/src/app/appconst.ts b/src/app/appconst.ts index 69bcf6042..6a0df44be 100644 --- a/src/app/appconst.ts +++ b/src/app/appconst.ts @@ -16,3 +16,33 @@ export const LineContainer_Sidebar = "sidebar"; export const ConfirmKey_HideShellPrompt = "hideshellprompt"; export const NoStrPos = -1; + +export const RemotePtyRows = 8; // also in main.tsx +export const RemotePtyCols = 80; +export const ProdServerEndpoint = "http://127.0.0.1:1619"; +export const ProdServerWsEndpoint = "ws://127.0.0.1:1623"; +export const DevServerEndpoint = "http://127.0.0.1:8090"; +export const DevServerWsEndpoint = "ws://127.0.0.1:8091"; +export const DefaultTermFontSize = 12; +export const MinFontSize = 8; +export const MaxFontSize = 24; +export const InputChunkSize = 500; +export const RemoteColors = ["red", "green", "yellow", "blue", "magenta", "cyan", "white", "orange"]; +export const TabColors = ["red", "orange", "yellow", "green", "mint", "cyan", "blue", "violet", "pink", "white"]; +export const TabIcons = [ + "sparkle", + "fire", + "ghost", + "cloud", + "compass", + "crown", + "droplet", + "graduation-cap", + "heart", + "file", +]; + +// @ts-ignore +export const VERSION = __WAVETERM_VERSION__; +// @ts-ignore +export const BUILD = __WAVETERM_BUILD__; diff --git a/src/app/bookmarks/bookmarks.tsx b/src/app/bookmarks/bookmarks.tsx index b6f6d40f2..fda4ce580 100644 --- a/src/app/bookmarks/bookmarks.tsx +++ b/src/app/bookmarks/bookmarks.tsx @@ -8,7 +8,7 @@ import { boundMethod } from "autobind-decorator"; import { If, For } from "tsx-control-statements/components"; import cn from "classnames"; import type { BookmarkType } from "../../types/types"; -import { GlobalModel } from "../../model/model_old"; +import { Model } from "../../model"; import { CmdStrCode, Markdown } from "../common/elements"; import { ReactComponent as XmarkIcon } from "../assets/icons/line/xmark.svg"; @@ -19,39 +19,50 @@ import { ReactComponent as FavoritesIcon } from "../assets/icons/favourites.svg" import "./bookmarks.less"; +type BookmarkProps = { + bookmark: BookmarkType; +}; + @mobxReact.observer -class Bookmark extends React.Component<{ bookmark: BookmarkType }, {}> { +class Bookmark extends React.Component { + globalModel: Model; + + constructor(props: BookmarkProps) { + super(props); + this.globalModel = Model.getInstance(); + } + @boundMethod handleDeleteClick(): void { let { bookmark } = this.props; - let model = GlobalModel.bookmarksModel; + let model = this.globalModel.bookmarksModel; model.handleDeleteBookmark(bookmark.bookmarkid); } @boundMethod handleEditClick(): void { let { bookmark } = this.props; - let model = GlobalModel.bookmarksModel; + let model = this.globalModel.bookmarksModel; model.handleEditBookmark(bookmark.bookmarkid); } @boundMethod handleEditCancel(): void { - let model = GlobalModel.bookmarksModel; + let model = this.globalModel.bookmarksModel; model.cancelEdit(); return; } @boundMethod handleEditUpdate(): void { - let model = GlobalModel.bookmarksModel; + let model = this.globalModel.bookmarksModel; model.confirmEdit(); return; } @boundMethod handleDescChange(e: any): void { - let model = GlobalModel.bookmarksModel; + let model = this.globalModel.bookmarksModel; mobx.action(() => { model.tempDesc.set(e.target.value); })(); @@ -59,7 +70,7 @@ class Bookmark extends React.Component<{ bookmark: BookmarkType }, {}> { @boundMethod handleCmdChange(e: any): void { - let model = GlobalModel.bookmarksModel; + let model = this.globalModel.bookmarksModel; mobx.action(() => { model.tempCmd.set(e.target.value); })(); @@ -68,27 +79,27 @@ class Bookmark extends React.Component<{ bookmark: BookmarkType }, {}> { @boundMethod handleClick(): void { let { bookmark } = this.props; - let model = GlobalModel.bookmarksModel; + let model = this.globalModel.bookmarksModel; model.selectBookmark(bookmark.bookmarkid); } @boundMethod handleUse(): void { let { bookmark } = this.props; - let model = GlobalModel.bookmarksModel; + let model = this.globalModel.bookmarksModel; model.useBookmark(bookmark.bookmarkid); } @boundMethod clickCopy(): void { let bm = this.props.bookmark; - let model = GlobalModel.bookmarksModel; + let model = this.globalModel.bookmarksModel; model.handleCopyBookmark(bm.bookmarkid); } render() { let bm = this.props.bookmark; - let model = GlobalModel.bookmarksModel; + let model = this.globalModel.bookmarksModel; let isSelected = model.activeBookmark.get() == bm.bookmarkid; let markdown = bm.description ?? ""; let hasDesc = markdown != ""; @@ -179,17 +190,24 @@ class Bookmark extends React.Component<{ bookmark: BookmarkType }, {}> { @mobxReact.observer class BookmarksView extends React.Component<{}, {}> { + globalModel: Model; + + constructor(props: {}) { + super(props); + this.globalModel = Model.getInstance(); + } + @boundMethod closeView(): void { - GlobalModel.bookmarksModel.closeView(); + this.globalModel.bookmarksModel.closeView(); } render() { - let isHidden = GlobalModel.activeMainView.get() != "bookmarks"; + let isHidden = this.globalModel.activeMainView.get() != "bookmarks"; if (isHidden) { return null; } - let bookmarks = GlobalModel.bookmarksModel.bookmarks; + let bookmarks = this.globalModel.bookmarksModel.bookmarks; let idx: number = 0; let bookmark: BookmarkType = null; return ( diff --git a/src/app/clientsettings/clientsettings.tsx b/src/app/clientsettings/clientsettings.tsx index b8a80593e..932696e1f 100644 --- a/src/app/clientsettings/clientsettings.tsx +++ b/src/app/clientsettings/clientsettings.tsx @@ -6,24 +6,20 @@ import * as mobxReact from "mobx-react"; import * as mobx from "mobx"; import { boundMethod } from "autobind-decorator"; import cn from "classnames"; -import { GlobalModel, GlobalCommandRunner, MinFontSize, MaxFontSize, RemotesModel } from "../../model/model_old"; +import { GlobalModel, GlobalCommandRunner, RemotesModel } from "../../model"; import { Toggle, InlineSettingsTextEdit, SettingsError, Dropdown } from "../common/elements"; -import { CommandRtnType, ClientDataType } from "../../types/types"; +import * as types from "../../types/types"; import { commandRtnHandler, isBlank } from "../../util/util"; +import * as appconst from "../appconst"; import "./clientsettings.less"; -type OV = mobx.IObservableValue; - -// @ts-ignore -const VERSION = __WAVETERM_VERSION__; -// @ts-ignore -const BUILD = __WAVETERM_BUILD__; - @mobxReact.observer class ClientSettingsView extends React.Component<{ model: RemotesModel }, { hoveredItemId: string }> { - fontSizeDropdownActive: OV = mobx.observable.box(false, { name: "clientSettings-fontSizeDropdownActive" }); - errorMessage: OV = mobx.observable.box(null, { name: "ClientSettings-errorMessage" }); + fontSizeDropdownActive: types.OV = mobx.observable.box(false, { + name: "clientSettings-fontSizeDropdownActive", + }); + errorMessage: types.OV = mobx.observable.box(null, { name: "ClientSettings-errorMessage" }); @boundMethod dismissError(): void { @@ -52,7 +48,7 @@ class ClientSettingsView extends React.Component<{ model: RemotesModel }, { hove @boundMethod handleChangeTelemetry(val: boolean): void { - let prtn: Promise = null; + let prtn: Promise = null; if (val) { prtn = GlobalCommandRunner.telemetryOn(false); } else { @@ -63,7 +59,7 @@ class ClientSettingsView extends React.Component<{ model: RemotesModel }, { hove @boundMethod handleChangeReleaseCheck(val: boolean): void { - let prtn: Promise = null; + let prtn: Promise = null; if (val) { prtn = GlobalCommandRunner.releaseCheckAutoOn(false); } else { @@ -74,7 +70,7 @@ class ClientSettingsView extends React.Component<{ model: RemotesModel }, { hove getFontSizes(): any { let availableFontSizes: { label: string; value: number }[] = []; - for (let s = MinFontSize; s <= MaxFontSize; s++) { + for (let s = appconst.MinFontSize; s <= appconst.MaxFontSize; s++) { availableFontSizes.push({ label: s + "px", value: s }); } return availableFontSizes; @@ -116,7 +112,7 @@ class ClientSettingsView extends React.Component<{ model: RemotesModel }, { hove return null; } - let cdata: ClientDataType = GlobalModel.clientData.get(); + let cdata: types.ClientDataType = GlobalModel.clientData.get(); let openAIOpts = cdata.openaiopts ?? {}; let apiTokenStr = isBlank(openAIOpts.apitoken) ? "(not set)" : "********"; let maxTokensStr = String( @@ -151,7 +147,7 @@ class ClientSettingsView extends React.Component<{ model: RemotesModel }, { hove
Client Version
- {VERSION} {BUILD} + {appconst.VERSION} {appconst.BUILD}
diff --git a/src/app/common/elements/markdown.tsx b/src/app/common/elements/markdown.tsx index 799526256..0c3b66577 100644 --- a/src/app/common/elements/markdown.tsx +++ b/src/app/common/elements/markdown.tsx @@ -6,7 +6,7 @@ import * as mobxReact from "mobx-react"; import ReactMarkdown from "react-markdown"; import remarkGfm from "remark-gfm"; import cn from "classnames"; -import { GlobalModel } from "../../../model/model_old"; +import { GlobalModel } from "../../../model"; import "./markdown.less"; diff --git a/src/app/common/elements/resizablesidebar.tsx b/src/app/common/elements/resizablesidebar.tsx index 0110e76ff..959553fd5 100644 --- a/src/app/common/elements/resizablesidebar.tsx +++ b/src/app/common/elements/resizablesidebar.tsx @@ -6,7 +6,7 @@ import * as mobxReact from "mobx-react"; import * as mobx from "mobx"; import { boundMethod } from "autobind-decorator"; import cn from "classnames"; -import { GlobalModel, GlobalCommandRunner } from "../../../model/model_old"; +import { GlobalModel, GlobalCommandRunner } from "../../../model"; import { MagicLayout } from "../../magiclayout"; import "./resizablesidebar.less"; diff --git a/src/app/common/elements/showwaveshellinstallprompt.tsx b/src/app/common/elements/showwaveshellinstallprompt.tsx index 645396448..60bdec137 100644 --- a/src/app/common/elements/showwaveshellinstallprompt.tsx +++ b/src/app/common/elements/showwaveshellinstallprompt.tsx @@ -1,7 +1,7 @@ // Copyright 2023, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 -import { GlobalModel } from "../../../model/model_old"; +import { GlobalModel } from "../../../model"; import * as appconst from "../../appconst"; function ShowWaveShellInstallPrompt(callbackFn: () => void) { diff --git a/src/app/common/modals/about.tsx b/src/app/common/modals/about.tsx index f8443a432..e2a144830 100644 --- a/src/app/common/modals/about.tsx +++ b/src/app/common/modals/about.tsx @@ -5,18 +5,14 @@ import * as React from "react"; import * as mobxReact from "mobx-react"; import * as mobx from "mobx"; import { boundMethod } from "autobind-decorator"; -import { GlobalModel } from "../../../model/model_old"; +import { GlobalModel } from "../../../model"; import { Modal, LinkButton } from "../elements"; import * as util from "../../../util/util"; +import * as appconst from "../../appconst"; import logo from "../../assets/waveterm-logo-with-bg.svg"; import "./about.less"; -// @ts-ignore -const VERSION = __WAVETERM_VERSION__; -// @ts-ignore -let BUILD = __WAVETERM_BUILD__; - @mobxReact.observer class AboutModal extends React.Component<{}, {}> { @boundMethod @@ -42,7 +38,7 @@ class AboutModal extends React.Component<{}, {}> { return (
- Client Version {VERSION} ({BUILD}) + Client Version {appconst.VERSION} ({appconst.BUILD})
); @@ -55,7 +51,7 @@ class AboutModal extends React.Component<{}, {}> { Up to Date
- Client Version {VERSION} ({BUILD}) + Client Version {appconst.VERSION} ({appconst.BUILD})
); @@ -67,7 +63,7 @@ class AboutModal extends React.Component<{}, {}> { Outdated Version
- Client Version {VERSION} ({BUILD}) + Client Version {appconst.VERSION} ({appconst.BUILD})
|
- +
{ {screen.getTabIcon()}
|
- +
= mobx.IObservableValue; type CV = mobx.IComputedValue; diff --git a/src/app/pluginsview/pluginsview.tsx b/src/app/pluginsview/pluginsview.tsx index c21fab9bb..51472e5da 100644 --- a/src/app/pluginsview/pluginsview.tsx +++ b/src/app/pluginsview/pluginsview.tsx @@ -5,7 +5,7 @@ import * as React from "react"; import * as mobxReact from "mobx-react"; import * as mobx from "mobx"; import { boundMethod } from "autobind-decorator"; -import { GlobalModel } from "../../model/model_old"; +import { GlobalModel } from "../../model"; import { PluginModel } from "../../plugins/plugins"; import { Markdown } from "../common/elements"; diff --git a/src/app/sidebar/sidebar.tsx b/src/app/sidebar/sidebar.tsx index afacee293..76a0f0e6e 100644 --- a/src/app/sidebar/sidebar.tsx +++ b/src/app/sidebar/sidebar.tsx @@ -17,10 +17,10 @@ import { ReactComponent as WorkspacesIcon } from "../assets/icons/workspaces.svg import { ReactComponent as SettingsIcon } from "../assets/icons/settings.svg"; import localizedFormat from "dayjs/plugin/localizedFormat"; -import { GlobalModel, GlobalCommandRunner, Session, VERSION } from "../../model/model_old"; +import { GlobalModel, GlobalCommandRunner, Session } from "../../model"; import { isBlank, openLink } from "../../util/util"; import { ResizableSidebar } from "../common/elements"; -import * as constants from "../appconst"; +import * as appconst from "../appconst"; import "./sidebar.less"; import { ActionsIcon, CenteredIcon, FrontIcon, StatusIndicator } from "../common/icons/icons"; @@ -167,7 +167,7 @@ class MainSideBar extends React.Component { mobx.action(() => { GlobalModel.sessionSettingsModal.set(session.sessionId); })(); - GlobalModel.modalsModel.pushModal(constants.SESSION_SETTINGS); + GlobalModel.modalsModel.pushModal(appconst.SESSION_SETTINGS); } getSessions() { @@ -208,7 +208,7 @@ class MainSideBar extends React.Component { let clientData = this.props.clientData; let needsUpdate = false; if (!clientData?.clientopts.noreleasecheck && !isBlank(clientData?.releaseinfo?.latestversion)) { - needsUpdate = compareLoose(VERSION, clientData.releaseinfo.latestversion) < 0; + needsUpdate = compareLoose(appconst.VERSION, clientData.releaseinfo.latestversion) < 0; } let mainSidebar = GlobalModel.mainSidebarModel; let isCollapsed = mainSidebar.getCollapsed(); diff --git a/src/app/workspace/cmdinput/aichat.tsx b/src/app/workspace/cmdinput/aichat.tsx index f90e93b6c..b75aacbc0 100644 --- a/src/app/workspace/cmdinput/aichat.tsx +++ b/src/app/workspace/cmdinput/aichat.tsx @@ -4,7 +4,7 @@ import * as React from "react"; import * as mobxReact from "mobx-react"; import * as mobx from "mobx"; -import { GlobalModel } from "../../../model/model_old"; +import { GlobalModel } from "../../../model"; import { isBlank } from "../../../util/util"; import { boundMethod } from "autobind-decorator"; import cn from "classnames"; diff --git a/src/app/workspace/cmdinput/cmdinput.tsx b/src/app/workspace/cmdinput/cmdinput.tsx index 16da5c259..6241924a6 100644 --- a/src/app/workspace/cmdinput/cmdinput.tsx +++ b/src/app/workspace/cmdinput/cmdinput.tsx @@ -10,7 +10,7 @@ import cn from "classnames"; import dayjs from "dayjs"; import type { RemoteType, RemoteInstanceType, RemotePtrType } from "../../../types/types"; import localizedFormat from "dayjs/plugin/localizedFormat"; -import { GlobalModel, GlobalCommandRunner, Screen } from "../../../model/model_old"; +import { GlobalModel, GlobalCommandRunner, Screen } from "../../../model"; import { renderCmdText } from "../../common/elements"; import { TextAreaInput } from "./textareainput"; import { InfoMsg } from "./infomsg"; diff --git a/src/app/workspace/cmdinput/historyinfo.tsx b/src/app/workspace/cmdinput/historyinfo.tsx index e10b20f4c..59f5c444c 100644 --- a/src/app/workspace/cmdinput/historyinfo.tsx +++ b/src/app/workspace/cmdinput/historyinfo.tsx @@ -11,7 +11,7 @@ import cn from "classnames"; import dayjs from "dayjs"; import type { HistoryItem, HistoryQueryOpts } from "../../../types/types"; import localizedFormat from "dayjs/plugin/localizedFormat"; -import { GlobalModel } from "../../../model/model_old"; +import { GlobalModel } from "../../../model"; import { isBlank } from "../../../util/util"; dayjs.extend(localizedFormat); diff --git a/src/app/workspace/cmdinput/infomsg.tsx b/src/app/workspace/cmdinput/infomsg.tsx index 68b22ed38..9460266ba 100644 --- a/src/app/workspace/cmdinput/infomsg.tsx +++ b/src/app/workspace/cmdinput/infomsg.tsx @@ -7,7 +7,7 @@ import { If, For } from "tsx-control-statements/components"; import cn from "classnames"; import dayjs from "dayjs"; import localizedFormat from "dayjs/plugin/localizedFormat"; -import { GlobalModel } from "../../../model/model_old"; +import { GlobalModel } from "../../../model"; import { makeExternLink } from "../../../util/util"; dayjs.extend(localizedFormat); diff --git a/src/app/workspace/cmdinput/textareainput.tsx b/src/app/workspace/cmdinput/textareainput.tsx index 1609334ef..5284deaeb 100644 --- a/src/app/workspace/cmdinput/textareainput.tsx +++ b/src/app/workspace/cmdinput/textareainput.tsx @@ -9,7 +9,7 @@ import * as util from "../../../util/util"; import { If } from "tsx-control-statements/components"; import { boundMethod } from "autobind-decorator"; import cn from "classnames"; -import { GlobalModel, GlobalCommandRunner, Screen } from "../../../model/model_old"; +import { GlobalModel, GlobalCommandRunner, Screen } from "../../../model"; import { getMonoFontSize } from "../../../util/textmeasure"; import { isModKeyPress, hasNoModifiers } from "../../../util/util"; import * as appconst from "../../appconst"; diff --git a/src/app/workspace/screen/screenview.tsx b/src/app/workspace/screen/screenview.tsx index cc9dd6fb9..71aad5871 100644 --- a/src/app/workspace/screen/screenview.tsx +++ b/src/app/workspace/screen/screenview.tsx @@ -10,16 +10,7 @@ import { If, For } from "tsx-control-statements/components"; import cn from "classnames"; import { debounce } from "throttle-debounce"; import dayjs from "dayjs"; -import { - GlobalCommandRunner, - TabColors, - TabIcons, - ForwardLineContainer, - GlobalModel, - ScreenLines, - Screen, - Session, -} from "../../../model/model_old"; +import { GlobalCommandRunner, ForwardLineContainer, GlobalModel, ScreenLines, Screen, Session } from "../../../model"; import type { LineType, RenderModeType, LineFactoryProps } from "../../../types/types"; import * as T from "../../../types/types"; import localizedFormat from "dayjs/plugin/localizedFormat"; @@ -442,7 +433,7 @@ class NewTabSettings extends React.Component<{ screen: Screen }, {}> {
this.selectTabIcon("square")}>
- +
{ <>
Select the color
- +
{ - let prtn = this.globalModel.submitCommand("history", "purge", lines, { nohist: "1" }, false); - return prtn; - } - - switchSession(session: string) { - mobx.action(() => { - this.globalModel.activeMainView.set("session"); - })(); - this.globalModel.submitCommand("session", null, [session], { nohist: "1" }, false); - } - - switchScreen(screen: string, session?: string) { - mobx.action(() => { - this.globalModel.activeMainView.set("session"); - })(); - let kwargs = { nohist: "1" }; - if (session != null) { - kwargs["session"] = session; - } - this.globalModel.submitCommand("screen", null, [screen], kwargs, false); - } - - lineView(sessionId: string, screenId: string, lineNum?: number) { - let screen = this.globalModel.getScreenById(sessionId, screenId); - if (screen != null && lineNum != null) { - screen.setAnchorFields(lineNum, 0, "line:view"); - } - let lineNumStr = lineNum == null || lineNum == 0 ? "E" : String(lineNum); - this.globalModel.submitCommand("line", "view", [sessionId, screenId, lineNumStr], { nohist: "1" }, false); - } - - lineArchive(lineArg: string, archive: boolean): Promise { - let kwargs = { nohist: "1" }; - let archiveStr = archive ? "1" : "0"; - return this.globalModel.submitCommand("line", "archive", [lineArg, archiveStr], kwargs, false); - } - - lineDelete(lineArg: string, interactive: boolean): Promise { - return this.globalModel.submitCommand("line", "delete", [lineArg], { nohist: "1" }, interactive); - } - - lineRestart(lineArg: string, interactive: boolean): Promise { - return this.globalModel.submitCommand("line", "restart", [lineArg], { nohist: "1" }, interactive); - } - - lineSet(lineArg: string, opts: { renderer?: string }): Promise { - let kwargs = { nohist: "1" }; - if ("renderer" in opts) { - kwargs["renderer"] = opts.renderer ?? ""; - } - return this.globalModel.submitCommand("line", "set", [lineArg], kwargs, false); - } - - createNewSession() { - this.globalModel.submitCommand("session", "open", null, { nohist: "1" }, false); - } - - createNewScreen() { - this.globalModel.submitCommand("screen", "open", null, { nohist: "1" }, false); - } - - closeScreen(screen: string) { - this.globalModel.submitCommand("screen", "close", [screen], { nohist: "1" }, false); - } - - // include is lineIds to include, exclude is lineIds to exclude - // if include is given then it *only* does those ids. if exclude is given (or not), - // it does all running commands in the screen except for excluded. - resizeScreen(screenId: string, rows: number, cols: number, opts?: { include?: string[]; exclude?: string[] }) { - let kwargs: Record = { - nohist: "1", - screen: screenId, - cols: String(cols), - rows: String(rows), - }; - if (opts?.include != null && opts?.include.length > 0) { - kwargs.include = opts.include.join(","); - } - if (opts?.exclude != null && opts?.exclude.length > 0) { - kwargs.exclude = opts.exclude.join(","); - } - this.globalModel.submitCommand("screen", "resize", null, kwargs, false); - } - - screenArchive(screenId: string, shouldArchive: boolean): Promise { - return this.globalModel.submitCommand( - "screen", - "archive", - [screenId, shouldArchive ? "1" : "0"], - { nohist: "1" }, - false - ); - } - - screenDelete(screenId: string, interactive: boolean): Promise { - return this.globalModel.submitCommand("screen", "delete", [screenId], { nohist: "1" }, interactive); - } - - screenWebShare(screenId: string, shouldShare: boolean): Promise { - let kwargs: Record = { nohist: "1" }; - kwargs["screen"] = screenId; - return this.globalModel.submitCommand("screen", "webshare", [shouldShare ? "1" : "0"], kwargs, false); - } - - showRemote(remoteid: string) { - this.globalModel.submitCommand("remote", "show", null, { nohist: "1", remote: remoteid }, true); - } - - showAllRemotes() { - this.globalModel.submitCommand("remote", "showall", null, { nohist: "1" }, true); - } - - connectRemote(remoteid: string) { - this.globalModel.submitCommand("remote", "connect", null, { nohist: "1", remote: remoteid }, true); - } - - disconnectRemote(remoteid: string) { - this.globalModel.submitCommand("remote", "disconnect", null, { nohist: "1", remote: remoteid }, true); - } - - installRemote(remoteid: string) { - this.globalModel.submitCommand("remote", "install", null, { nohist: "1", remote: remoteid }, true); - } - - installCancelRemote(remoteid: string) { - this.globalModel.submitCommand("remote", "installcancel", null, { nohist: "1", remote: remoteid }, true); - } - - createRemote(cname: string, kwargsArg: Record, interactive: boolean): Promise { - let kwargs = Object.assign({}, kwargsArg); - kwargs["nohist"] = "1"; - return this.globalModel.submitCommand("remote", "new", [cname], kwargs, interactive); - } - - openCreateRemote(): void { - this.globalModel.submitCommand("remote", "new", null, { nohist: "1", visual: "1" }, true); - } - - screenSetRemote(remoteArg: string, nohist: boolean, interactive: boolean): Promise { - let kwargs = {}; - if (nohist) { - kwargs["nohist"] = "1"; - } - return this.globalModel.submitCommand("connect", null, [remoteArg], kwargs, interactive); - } - - editRemote(remoteid: string, kwargsArg: Record): void { - let kwargs = Object.assign({}, kwargsArg); - kwargs["nohist"] = "1"; - kwargs["remote"] = remoteid; - this.globalModel.submitCommand("remote", "set", null, kwargs, true); - } - - openEditRemote(remoteid: string): void { - this.globalModel.submitCommand("remote", "set", null, { remote: remoteid, nohist: "1", visual: "1" }, true); - } - - archiveRemote(remoteid: string) { - this.globalModel.submitCommand("remote", "archive", null, { remote: remoteid, nohist: "1" }, true); - } - - importSshConfig() { - this.globalModel.submitCommand("remote", "parse", null, { nohist: "1", visual: "1" }, true); - } - - screenSelectLine(lineArg: string, focusVal?: string) { - let kwargs: Record = { - nohist: "1", - line: lineArg, - }; - if (focusVal != null) { - kwargs["focus"] = focusVal; - } - this.globalModel.submitCommand("screen", "set", null, kwargs, false); - } - - screenReorder(screenId: string, index: string) { - let kwargs: Record = { - nohist: "1", - screenId: screenId, - index: index, - }; - this.globalModel.submitCommand("screen", "reorder", null, kwargs, false); - } - - setTermUsedRows(termContext: RendererContext, height: number) { - let kwargs: Record = {}; - kwargs["screen"] = termContext.screenId; - kwargs["hohist"] = "1"; - let posargs = [String(termContext.lineNum), String(height)]; - this.globalModel.submitCommand("line", "setheight", posargs, kwargs, false); - } - - screenSetAnchor(sessionId: string, screenId: string, anchorVal: string): void { - let kwargs = { - nohist: "1", - anchor: anchorVal, - session: sessionId, - screen: screenId, - }; - this.globalModel.submitCommand("screen", "set", null, kwargs, false); - } - - screenSetFocus(focusVal: string): void { - this.globalModel.submitCommand("screen", "set", null, { focus: focusVal, nohist: "1" }, false); - } - - screenSetSettings( - screenId: string, - settings: { tabcolor?: string; tabicon?: string; name?: string; sharename?: string }, - interactive: boolean - ): Promise { - let kwargs: { [key: string]: any } = Object.assign({}, settings); - kwargs["nohist"] = "1"; - kwargs["screen"] = screenId; - return this.globalModel.submitCommand("screen", "set", null, kwargs, interactive); - } - - sessionArchive(sessionId: string, shouldArchive: boolean): Promise { - return this.globalModel.submitCommand( - "session", - "archive", - [sessionId, shouldArchive ? "1" : "0"], - { nohist: "1" }, - false - ); - } - - sessionDelete(sessionId: string): Promise { - return this.globalModel.submitCommand("session", "delete", [sessionId], { nohist: "1" }, false); - } - - sessionSetSettings(sessionId: string, settings: { name?: string }, interactive: boolean): Promise { - let kwargs = Object.assign({}, settings); - kwargs["nohist"] = "1"; - kwargs["session"] = sessionId; - return this.globalModel.submitCommand("session", "set", null, kwargs, interactive); - } - - lineStar(lineId: string, starVal: number) { - this.globalModel.submitCommand("line", "star", [lineId, String(starVal)], { nohist: "1" }, true); - } - - lineBookmark(lineId: string) { - this.globalModel.submitCommand("line", "bookmark", [lineId], { nohist: "1" }, true); - } - - linePin(lineId: string, val: boolean) { - this.globalModel.submitCommand("line", "pin", [lineId, val ? "1" : "0"], { nohist: "1" }, true); - } - - bookmarksView() { - this.globalModel.submitCommand("bookmarks", "show", null, { nohist: "1" }, true); - } - - connectionsView() { - this.globalModel.connectionViewModel.showConnectionsView(); - } - - clientSettingsView() { - this.globalModel.clientSettingsViewModel.showClientSettingsView(); - } - - historyView(params: HistorySearchParams) { - let kwargs = { nohist: "1" }; - kwargs["offset"] = String(params.offset); - kwargs["rawoffset"] = String(params.rawOffset); - if (params.searchText != null) { - kwargs["text"] = params.searchText; - } - if (params.searchSessionId != null) { - kwargs["searchsession"] = params.searchSessionId; - } - if (params.searchRemoteId != null) { - kwargs["searchremote"] = params.searchRemoteId; - } - if (params.fromTs != null) { - kwargs["fromts"] = String(params.fromTs); - } - if (params.noMeta) { - kwargs["meta"] = "0"; - } - if (params.filterCmds) { - kwargs["filter"] = "1"; - } - this.globalModel.submitCommand("history", "viewall", null, kwargs, true); - } - - telemetryOff(interactive: boolean): Promise { - return this.globalModel.submitCommand("telemetry", "off", null, { nohist: "1" }, interactive); - } - - telemetryOn(interactive: boolean): Promise { - return this.globalModel.submitCommand("telemetry", "on", null, { nohist: "1" }, interactive); - } - - releaseCheckAutoOff(interactive: boolean): Promise { - return this.globalModel.submitCommand("releasecheck", "autooff", null, { nohist: "1" }, interactive); - } - - releaseCheckAutoOn(interactive: boolean): Promise { - return this.globalModel.submitCommand("releasecheck", "autoon", null, { nohist: "1" }, interactive); - } - - setTermFontSize(fsize: number, interactive: boolean): Promise { - let kwargs = { - nohist: "1", - termfontsize: String(fsize), - }; - return this.globalModel.submitCommand("client", "set", null, kwargs, interactive); - } - - setClientOpenAISettings(opts: { model?: string; apitoken?: string; maxtokens?: string }): Promise { - let kwargs = { - nohist: "1", - }; - if (opts.model != null) { - kwargs["openaimodel"] = opts.model; - } - if (opts.apitoken != null) { - kwargs["openaiapitoken"] = opts.apitoken; - } - if (opts.maxtokens != null) { - kwargs["openaimaxtokens"] = opts.maxtokens; - } - return this.globalModel.submitCommand("client", "set", null, kwargs, false); - } - - clientAcceptTos(): void { - this.globalModel.submitCommand("client", "accepttos", null, { nohist: "1" }, true); - } - - clientSetConfirmFlag(flag: string, value: boolean): Promise { - let kwargs = { nohist: "1" }; - let valueStr = value ? "1" : "0"; - return this.globalModel.submitCommand("client", "setconfirmflag", [flag, valueStr], kwargs, false); - } - - clientSetSidebar(width: number, collapsed: boolean): Promise { - let kwargs = { nohist: "1", width: `${width}`, collapsed: collapsed ? "1" : "0" }; - return this.globalModel.submitCommand("client", "setsidebar", null, kwargs, false); - } - - editBookmark(bookmarkId: string, desc: string, cmdstr: string) { - let kwargs = { - nohist: "1", - desc: desc, - cmdstr: cmdstr, - }; - this.globalModel.submitCommand("bookmark", "set", [bookmarkId], kwargs, true); - } - - deleteBookmark(bookmarkId: string): void { - this.globalModel.submitCommand("bookmark", "delete", [bookmarkId], { nohist: "1" }, true); - } - - openSharedSession(): void { - this.globalModel.submitCommand("session", "openshared", null, { nohist: "1" }, true); - } - - setLineState( - screenId: string, - lineId: string, - state: LineStateType, - interactive: boolean - ): Promise { - let stateStr = JSON.stringify(state); - return this.globalModel.submitCommand( - "line", - "set", - [lineId], - { screen: screenId, nohist: "1", state: stateStr }, - interactive - ); - } - - screenSidebarAddLine(lineId: string) { - this.globalModel.submitCommand("sidebar", "add", null, { nohist: "1", line: lineId }, false); - } - - screenSidebarRemove() { - this.globalModel.submitCommand("sidebar", "remove", null, { nohist: "1" }, false); - } - - screenSidebarClose(): void { - this.globalModel.submitCommand("sidebar", "close", null, { nohist: "1" }, false); - } - - screenSidebarOpen(width?: string): void { - let kwargs: Record = { nohist: "1" }; - if (width != null) { - kwargs.width = width; - } - this.globalModel.submitCommand("sidebar", "open", null, kwargs, false); - } -} - -export { CommandRunner }; diff --git a/src/model/forwardlinecontainer.ts b/src/model/forwardlinecontainer.ts new file mode 100644 index 000000000..02260163c --- /dev/null +++ b/src/model/forwardlinecontainer.ts @@ -0,0 +1,117 @@ +// Copyright 2023, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +import { TermWrap } from "../plugins/terminal/term"; +import * as types from "../types/types"; +import { windowWidthToCols, windowHeightToRows } from "../util/textmeasure"; +import { MagicLayout } from "../app/magiclayout"; +import { Model } from "./model"; +import { CommandRunner } from "./model"; +import { Cmd } from "./cmd"; +import { Screen } from "./screen"; + +class ForwardLineContainer { + globalCommandRunner: CommandRunner; + globalModel: Model; + winSize: types.WindowSize; + screen: Screen; + containerType: types.LineContainerStrs; + lineId: string; + + constructor(screen: Screen, winSize: types.WindowSize, containerType: types.LineContainerStrs, lineId: string) { + this.globalModel = Model.getInstance(); + this.globalCommandRunner = CommandRunner.getInstance(); + this.screen = screen; + this.winSize = winSize; + this.containerType = containerType; + this.lineId = lineId; + } + + screenSizeCallback(winSize: types.WindowSize): void { + this.winSize = winSize; + let termWrap = this.getTermWrap(this.lineId); + if (termWrap != null) { + let fontSize = this.globalModel.termFontSize.get(); + let cols = windowWidthToCols(winSize.width, fontSize); + let rows = windowHeightToRows(winSize.height, fontSize); + termWrap.resizeCols(cols); + this.globalCommandRunner.resizeScreen(this.screen.screenId, rows, cols, { include: [this.lineId] }); + } + } + + getContainerType(): types.LineContainerStrs { + return this.containerType; + } + + getCmd(line: types.LineType): Cmd { + return this.screen.getCmd(line); + } + + isSidebarOpen(): boolean { + return false; + } + + isLineIdInSidebar(lineId: string): boolean { + return false; + } + + setLineFocus(lineNum: number, focus: boolean): void { + this.screen.setLineFocus(lineNum, focus); + } + + setContentHeight(context: types.RendererContext, height: number): void { + return; + } + + getMaxContentSize(): types.WindowSize { + let rtn = { width: this.winSize.width, height: this.winSize.height }; + rtn.width = rtn.width - MagicLayout.ScreenMaxContentWidthBuffer; + return rtn; + } + + getIdealContentSize(): types.WindowSize { + return this.winSize; + } + + loadTerminalRenderer(elem: Element, line: types.LineType, cmd: Cmd, width: number): void { + this.screen.loadTerminalRenderer(elem, line, cmd, width); + } + + registerRenderer(lineId: string, renderer: types.RendererModel): void { + this.screen.registerRenderer(lineId, renderer); + } + + unloadRenderer(lineId: string): void { + this.screen.unloadRenderer(lineId); + } + + getContentHeight(context: types.RendererContext): number { + return this.screen.getContentHeight(context); + } + + getUsedRows(context: types.RendererContext, line: types.LineType, cmd: Cmd, width: number): number { + return this.screen.getUsedRows(context, line, cmd, width); + } + + getIsFocused(lineNum: number): boolean { + return this.screen.getIsFocused(lineNum); + } + + getRenderer(lineId: string): types.RendererModel { + return this.screen.getRenderer(lineId); + } + + getTermWrap(lineId: string): TermWrap { + return this.screen.getTermWrap(lineId); + } + + getFocusType(): types.FocusTypeStrs { + return this.screen.getFocusType(); + } + + getSelectedLine(): number { + return this.screen.getSelectedLine(); + } +} + +export { ForwardLineContainer }; diff --git a/src/model/historyview.ts b/src/model/historyview.ts index 798e9948d..ef8f2d505 100644 --- a/src/model/historyview.ts +++ b/src/model/historyview.ts @@ -17,7 +17,7 @@ import dayjs from "dayjs"; import * as appconst from "../app/appconst"; import { checkKeyPressed, adaptFromReactOrNativeKeyEvent } from "../util/keyutil"; import { OV, OArr, OMap } from "../types/types"; -import { CommandRunner } from "./commandrunner"; +import { CommandRunner } from "./model"; import { Model } from "./model"; import { Cmd } from "./cmd"; import { SpecialLineContainer } from "./speciallinecontainer"; diff --git a/src/model/index.ts b/src/model/index.ts index 72cc2fa23..39ce398b7 100644 --- a/src/model/index.ts +++ b/src/model/index.ts @@ -1,15 +1,15 @@ +export * from "./model"; export { BookmarksModel } from "./bookmarks"; export { ClientSettingsViewModel } from "./clientsettingsview"; export { Cmd } from "./cmd"; -export { CommandRunner } from "./commandrunner"; export { ConnectionsViewModel } from "./connectionsview"; export { InputModel } from "./input"; export { MainSidebarModel } from "./mainsidebar"; export { ModalsModel } from "./modals"; -export { Model } from "./model"; export { PluginsModel } from "./plugins"; export { RemotesModel } from "./remotes"; export { Screen } from "./screen"; export { ScreenLines } from "./screenlines"; export { Session } from "./session"; export { SpecialLineContainer } from "./speciallinecontainer"; +export { ForwardLineContainer } from "./forwardlinecontainer"; diff --git a/src/model/input.ts b/src/model/input.ts index ec05288cb..aa9a3ed38 100644 --- a/src/model/input.ts +++ b/src/model/input.ts @@ -18,7 +18,7 @@ import { StrWithPos } from "../types/types"; import * as appconst from "../app/appconst"; import { OV } from "../types/types"; import { Model } from "./model"; -import { CommandRunner } from "./commandrunner"; +import { CommandRunner } from "./model"; function getDefaultHistoryQueryOpts(): HistoryQueryOpts { return { diff --git a/src/model/model.ts b/src/model/model.ts index eb56d88b9..f76b3ea53 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -38,6 +38,8 @@ import { CmdInputTextPacketType, FileInfoType, ExtFile, + HistorySearchParams, + LineStateType, } from "../types/types"; import { WSControl } from "./ws"; import { cmdStatusIsRunning } from "../app/line/lineutil"; @@ -46,7 +48,6 @@ import { remotePtrToString, cmdPacketString } from "../util/modelutil"; import { checkKeyPressed, adaptFromReactOrNativeKeyEvent, setKeyUtilPlatform } from "../util/keyutil"; import { OV, OArr, OMap, CV } from "../types/types"; import { Session } from "./session"; -import { CommandRunner } from "./commandrunner"; import { ScreenLines } from "./screenlines"; import { InputModel } from "./input"; import { PluginsModel } from "./plugins"; @@ -60,19 +61,6 @@ import { MainSidebarModel } from "./mainsidebar"; import { Screen } from "./screen"; import { Cmd } from "./cmd"; -const ProdServerEndpoint = "http://127.0.0.1:1619"; -const ProdServerWsEndpoint = "ws://127.0.0.1:1623"; -const DevServerEndpoint = "http://127.0.0.1:8090"; -const DevServerWsEndpoint = "ws://127.0.0.1:8091"; -const DefaultTermFontSize = 12; -const MinFontSize = 8; -const MaxFontSize = 24; - -// @ts-ignore -const VERSION = __WAVETERM_VERSION__; -// @ts-ignore -const BUILD = __WAVETERM_BUILD__; - type KeyModsType = { meta?: boolean; ctrl?: boolean; @@ -120,7 +108,6 @@ function getApi(): ElectronApi { } class Model { - globalCommandRunner: CommandRunner; clientId: string; activeSessionId: OV = mobx.observable.box(null, { name: "activeSessionId", @@ -192,8 +179,7 @@ class Model { }); packetSeqNum: number = 0; - private constructor(commandRunner: CommandRunner) { - this.globalCommandRunner = commandRunner; + private constructor() { this.clientId = getApi().getId(); this.isDev = getApi().getIsDev(); this.authKey = getApi().getAuthKey(); @@ -219,14 +205,14 @@ class Model { this.termFontSize = mobx.computed(() => { let cdata = this.clientData.get(); if (cdata == null || cdata.feopts == null || cdata.feopts.termfontsize == null) { - return DefaultTermFontSize; + return appconst.DefaultTermFontSize; } let fontSize = Math.ceil(cdata.feopts.termfontsize); - if (fontSize < MinFontSize) { - return MinFontSize; + if (fontSize < appconst.MinFontSize) { + return appconst.MinFontSize; } - if (fontSize > MaxFontSize) { - return MaxFontSize; + if (fontSize > appconst.MaxFontSize) { + return appconst.MaxFontSize; } return fontSize; }); @@ -252,8 +238,7 @@ class Model { static getInstance() { if (!(window as any).GlobalModel) { - const commandRunner = CommandRunner.getInstance(); - (window as any).GlobalModel = new Model(commandRunner); + (window as any).GlobalModel = new Model(); } return (window as any).GlobalModel; } @@ -382,17 +367,17 @@ class Model { getBaseHostPort(): string { if (this.isDev) { - return DevServerEndpoint; + return appconst.DevServerEndpoint; } - return ProdServerEndpoint; + return appconst.ProdServerEndpoint; } setTermFontSize(fontSize: number) { - if (fontSize < MinFontSize) { - fontSize = MinFontSize; + if (fontSize < appconst.MinFontSize) { + fontSize = appconst.MinFontSize; } - if (fontSize > MaxFontSize) { - fontSize = MaxFontSize; + if (fontSize > appconst.MaxFontSize) { + fontSize = appconst.MaxFontSize; } mobx.action(() => { this.termFontSize.set(fontSize); @@ -401,9 +386,9 @@ class Model { getBaseWsHostPort(): string { if (this.isDev) { - return DevServerWsEndpoint; + return appconst.DevServerWsEndpoint; } - return ProdServerWsEndpoint; + return appconst.ProdServerWsEndpoint; } getFetchHeaders(): Record { @@ -468,7 +453,7 @@ class Model { } if (checkKeyPressed(waveEvent, "Cmd:b")) { e.preventDefault(); - this.globalCommandRunner.bookmarksView(); + GlobalCommandRunner.bookmarksView(); } if (this.activeMainView.get() == "session" && checkKeyPressed(waveEvent, "Cmd:Ctrl:s")) { e.preventDefault(); @@ -476,9 +461,9 @@ class Model { if (activeScreen != null) { let isSidebarOpen = activeScreen.isSidebarOpen(); if (isSidebarOpen) { - this.globalCommandRunner.screenSidebarClose(); + GlobalCommandRunner.screenSidebarClose(); } else { - this.globalCommandRunner.screenSidebarOpen(); + GlobalCommandRunner.screenSidebarOpen(); } } } @@ -511,7 +496,7 @@ class Model { return false; } } - this.globalCommandRunner.lineDelete(String(selectedLine), true); + GlobalCommandRunner.lineDelete(String(selectedLine), true); return true; } @@ -531,7 +516,7 @@ class Model { if (!result) { return; } - this.globalCommandRunner.screenDelete(activeScreen.screenId, true); + GlobalCommandRunner.screenDelete(activeScreen.screenId, true); }); } @@ -545,14 +530,14 @@ class Model { } if (mods.shift) { // restart last line - this.globalCommandRunner.lineRestart("E", true); + GlobalCommandRunner.lineRestart("E", true); } else { // restart selected line let selectedLine = activeScreen.selectedLine.get(); if (selectedLine == null || selectedLine == 0) { return; } - this.globalCommandRunner.lineRestart(String(selectedLine), true); + GlobalCommandRunner.lineRestart(String(selectedLine), true); } } @@ -622,7 +607,7 @@ class Model { setContentHeight(context: RendererContext, height: number): void { let key = context.screenId + "/" + context.lineId; this.termUsedRowsCache[key] = height; - this.globalCommandRunner.setTermUsedRows(context, height); + GlobalCommandRunner.setTermUsedRows(context, height); } contextScreen(e: any, screenId: string) { @@ -640,7 +625,7 @@ class Model { remote: null, winsize: null, linenum: null, - build: VERSION + " " + BUILD, + build: appconst.VERSION + " " + appconst.BUILD, }; let session = this.getActiveSession(); if (session != null) { @@ -657,7 +642,7 @@ class Model { } onTCmd(e: any, mods: KeyModsType) { - this.globalCommandRunner.createNewScreen(); + GlobalCommandRunner.createNewScreen(); } onICmd(e: any, mods: KeyModsType) { @@ -667,7 +652,7 @@ class Model { onLCmd(e: any, mods: KeyModsType) { let screen = this.getActiveScreen(); if (screen != null) { - this.globalCommandRunner.screenSetFocus("cmd"); + GlobalCommandRunner.screenSetFocus("cmd"); } } @@ -722,35 +707,35 @@ class Model { } onMetaPageUp(): void { - this.globalCommandRunner.screenSelectLine("-1"); + GlobalCommandRunner.screenSelectLine("-1"); } onMetaPageDown(): void { - this.globalCommandRunner.screenSelectLine("+1"); + GlobalCommandRunner.screenSelectLine("+1"); } onMetaArrowUp(): void { - this.globalCommandRunner.screenSelectLine("-1"); + GlobalCommandRunner.screenSelectLine("-1"); } onMetaArrowDown(): void { - this.globalCommandRunner.screenSelectLine("+1"); + GlobalCommandRunner.screenSelectLine("+1"); } onBracketCmd(e: any, arg: { relative: number }, mods: KeyModsType) { if (arg.relative == 1) { - this.globalCommandRunner.switchScreen("+"); + GlobalCommandRunner.switchScreen("+"); } else if (arg.relative == -1) { - this.globalCommandRunner.switchScreen("-"); + GlobalCommandRunner.switchScreen("-"); } } onDigitCmd(e: any, arg: { digit: number }, mods: KeyModsType) { if (mods.meta && mods.ctrl) { - this.globalCommandRunner.switchSession(String(arg.digit)); + GlobalCommandRunner.switchSession(String(arg.digit)); return; } - this.globalCommandRunner.switchScreen(String(arg.digit)); + GlobalCommandRunner.switchScreen(String(arg.digit)); } isConnected(): boolean { @@ -1431,4 +1416,429 @@ class Model { } } -export { Model }; +class CommandRunner { + private constructor() {} + + static getInstance() { + if (!(window as any).GlobalCommandRunner) { + (window as any).GlobalCommandRunner = new CommandRunner(); + } + return (window as any).GlobalCommandRunner; + } + + loadHistory(show: boolean, htype: string) { + let kwargs = { nohist: "1" }; + if (!show) { + kwargs["noshow"] = "1"; + } + if (htype != null && htype != "screen") { + kwargs["type"] = htype; + } + GlobalModel.submitCommand("history", null, null, kwargs, true); + } + + resetShellState() { + GlobalModel.submitCommand("reset", null, null, null, true); + } + + historyPurgeLines(lines: string[]): Promise { + let prtn = GlobalModel.submitCommand("history", "purge", lines, { nohist: "1" }, false); + return prtn; + } + + switchSession(session: string) { + mobx.action(() => { + GlobalModel.activeMainView.set("session"); + })(); + GlobalModel.submitCommand("session", null, [session], { nohist: "1" }, false); + } + + switchScreen(screen: string, session?: string) { + mobx.action(() => { + GlobalModel.activeMainView.set("session"); + })(); + let kwargs = { nohist: "1" }; + if (session != null) { + kwargs["session"] = session; + } + GlobalModel.submitCommand("screen", null, [screen], kwargs, false); + } + + lineView(sessionId: string, screenId: string, lineNum?: number) { + let screen = GlobalModel.getScreenById(sessionId, screenId); + if (screen != null && lineNum != null) { + screen.setAnchorFields(lineNum, 0, "line:view"); + } + let lineNumStr = lineNum == null || lineNum == 0 ? "E" : String(lineNum); + GlobalModel.submitCommand("line", "view", [sessionId, screenId, lineNumStr], { nohist: "1" }, false); + } + + lineArchive(lineArg: string, archive: boolean): Promise { + let kwargs = { nohist: "1" }; + let archiveStr = archive ? "1" : "0"; + return GlobalModel.submitCommand("line", "archive", [lineArg, archiveStr], kwargs, false); + } + + lineDelete(lineArg: string, interactive: boolean): Promise { + return GlobalModel.submitCommand("line", "delete", [lineArg], { nohist: "1" }, interactive); + } + + lineRestart(lineArg: string, interactive: boolean): Promise { + return GlobalModel.submitCommand("line", "restart", [lineArg], { nohist: "1" }, interactive); + } + + lineSet(lineArg: string, opts: { renderer?: string }): Promise { + let kwargs = { nohist: "1" }; + if ("renderer" in opts) { + kwargs["renderer"] = opts.renderer ?? ""; + } + return GlobalModel.submitCommand("line", "set", [lineArg], kwargs, false); + } + + createNewSession() { + GlobalModel.submitCommand("session", "open", null, { nohist: "1" }, false); + } + + createNewScreen() { + GlobalModel.submitCommand("screen", "open", null, { nohist: "1" }, false); + } + + closeScreen(screen: string) { + GlobalModel.submitCommand("screen", "close", [screen], { nohist: "1" }, false); + } + + // include is lineIds to include, exclude is lineIds to exclude + // if include is given then it *only* does those ids. if exclude is given (or not), + // it does all running commands in the screen except for excluded. + resizeScreen(screenId: string, rows: number, cols: number, opts?: { include?: string[]; exclude?: string[] }) { + let kwargs: Record = { + nohist: "1", + screen: screenId, + cols: String(cols), + rows: String(rows), + }; + if (opts?.include != null && opts?.include.length > 0) { + kwargs.include = opts.include.join(","); + } + if (opts?.exclude != null && opts?.exclude.length > 0) { + kwargs.exclude = opts.exclude.join(","); + } + GlobalModel.submitCommand("screen", "resize", null, kwargs, false); + } + + screenArchive(screenId: string, shouldArchive: boolean): Promise { + return GlobalModel.submitCommand( + "screen", + "archive", + [screenId, shouldArchive ? "1" : "0"], + { nohist: "1" }, + false + ); + } + + screenDelete(screenId: string, interactive: boolean): Promise { + return GlobalModel.submitCommand("screen", "delete", [screenId], { nohist: "1" }, interactive); + } + + screenWebShare(screenId: string, shouldShare: boolean): Promise { + let kwargs: Record = { nohist: "1" }; + kwargs["screen"] = screenId; + return GlobalModel.submitCommand("screen", "webshare", [shouldShare ? "1" : "0"], kwargs, false); + } + + showRemote(remoteid: string) { + GlobalModel.submitCommand("remote", "show", null, { nohist: "1", remote: remoteid }, true); + } + + showAllRemotes() { + GlobalModel.submitCommand("remote", "showall", null, { nohist: "1" }, true); + } + + connectRemote(remoteid: string) { + GlobalModel.submitCommand("remote", "connect", null, { nohist: "1", remote: remoteid }, true); + } + + disconnectRemote(remoteid: string) { + GlobalModel.submitCommand("remote", "disconnect", null, { nohist: "1", remote: remoteid }, true); + } + + installRemote(remoteid: string) { + GlobalModel.submitCommand("remote", "install", null, { nohist: "1", remote: remoteid }, true); + } + + installCancelRemote(remoteid: string) { + GlobalModel.submitCommand("remote", "installcancel", null, { nohist: "1", remote: remoteid }, true); + } + + createRemote(cname: string, kwargsArg: Record, interactive: boolean): Promise { + let kwargs = Object.assign({}, kwargsArg); + kwargs["nohist"] = "1"; + return GlobalModel.submitCommand("remote", "new", [cname], kwargs, interactive); + } + + openCreateRemote(): void { + GlobalModel.submitCommand("remote", "new", null, { nohist: "1", visual: "1" }, true); + } + + screenSetRemote(remoteArg: string, nohist: boolean, interactive: boolean): Promise { + let kwargs = {}; + if (nohist) { + kwargs["nohist"] = "1"; + } + return GlobalModel.submitCommand("connect", null, [remoteArg], kwargs, interactive); + } + + editRemote(remoteid: string, kwargsArg: Record): void { + let kwargs = Object.assign({}, kwargsArg); + kwargs["nohist"] = "1"; + kwargs["remote"] = remoteid; + GlobalModel.submitCommand("remote", "set", null, kwargs, true); + } + + openEditRemote(remoteid: string): void { + GlobalModel.submitCommand("remote", "set", null, { remote: remoteid, nohist: "1", visual: "1" }, true); + } + + archiveRemote(remoteid: string) { + GlobalModel.submitCommand("remote", "archive", null, { remote: remoteid, nohist: "1" }, true); + } + + importSshConfig() { + GlobalModel.submitCommand("remote", "parse", null, { nohist: "1", visual: "1" }, true); + } + + screenSelectLine(lineArg: string, focusVal?: string) { + let kwargs: Record = { + nohist: "1", + line: lineArg, + }; + if (focusVal != null) { + kwargs["focus"] = focusVal; + } + GlobalModel.submitCommand("screen", "set", null, kwargs, false); + } + + screenReorder(screenId: string, index: string) { + let kwargs: Record = { + nohist: "1", + screenId: screenId, + index: index, + }; + GlobalModel.submitCommand("screen", "reorder", null, kwargs, false); + } + + setTermUsedRows(termContext: RendererContext, height: number) { + let kwargs: Record = {}; + kwargs["screen"] = termContext.screenId; + kwargs["hohist"] = "1"; + let posargs = [String(termContext.lineNum), String(height)]; + GlobalModel.submitCommand("line", "setheight", posargs, kwargs, false); + } + + screenSetAnchor(sessionId: string, screenId: string, anchorVal: string): void { + let kwargs = { + nohist: "1", + anchor: anchorVal, + session: sessionId, + screen: screenId, + }; + GlobalModel.submitCommand("screen", "set", null, kwargs, false); + } + + screenSetFocus(focusVal: string): void { + GlobalModel.submitCommand("screen", "set", null, { focus: focusVal, nohist: "1" }, false); + } + + screenSetSettings( + screenId: string, + settings: { tabcolor?: string; tabicon?: string; name?: string; sharename?: string }, + interactive: boolean + ): Promise { + let kwargs: { [key: string]: any } = Object.assign({}, settings); + kwargs["nohist"] = "1"; + kwargs["screen"] = screenId; + return GlobalModel.submitCommand("screen", "set", null, kwargs, interactive); + } + + sessionArchive(sessionId: string, shouldArchive: boolean): Promise { + return GlobalModel.submitCommand( + "session", + "archive", + [sessionId, shouldArchive ? "1" : "0"], + { nohist: "1" }, + false + ); + } + + sessionDelete(sessionId: string): Promise { + return GlobalModel.submitCommand("session", "delete", [sessionId], { nohist: "1" }, false); + } + + sessionSetSettings(sessionId: string, settings: { name?: string }, interactive: boolean): Promise { + let kwargs = Object.assign({}, settings); + kwargs["nohist"] = "1"; + kwargs["session"] = sessionId; + return GlobalModel.submitCommand("session", "set", null, kwargs, interactive); + } + + lineStar(lineId: string, starVal: number) { + GlobalModel.submitCommand("line", "star", [lineId, String(starVal)], { nohist: "1" }, true); + } + + lineBookmark(lineId: string) { + GlobalModel.submitCommand("line", "bookmark", [lineId], { nohist: "1" }, true); + } + + linePin(lineId: string, val: boolean) { + GlobalModel.submitCommand("line", "pin", [lineId, val ? "1" : "0"], { nohist: "1" }, true); + } + + bookmarksView() { + GlobalModel.submitCommand("bookmarks", "show", null, { nohist: "1" }, true); + } + + connectionsView() { + GlobalModel.connectionViewModel.showConnectionsView(); + } + + clientSettingsView() { + GlobalModel.clientSettingsViewModel.showClientSettingsView(); + } + + historyView(params: HistorySearchParams) { + let kwargs = { nohist: "1" }; + kwargs["offset"] = String(params.offset); + kwargs["rawoffset"] = String(params.rawOffset); + if (params.searchText != null) { + kwargs["text"] = params.searchText; + } + if (params.searchSessionId != null) { + kwargs["searchsession"] = params.searchSessionId; + } + if (params.searchRemoteId != null) { + kwargs["searchremote"] = params.searchRemoteId; + } + if (params.fromTs != null) { + kwargs["fromts"] = String(params.fromTs); + } + if (params.noMeta) { + kwargs["meta"] = "0"; + } + if (params.filterCmds) { + kwargs["filter"] = "1"; + } + GlobalModel.submitCommand("history", "viewall", null, kwargs, true); + } + + telemetryOff(interactive: boolean): Promise { + return GlobalModel.submitCommand("telemetry", "off", null, { nohist: "1" }, interactive); + } + + telemetryOn(interactive: boolean): Promise { + return GlobalModel.submitCommand("telemetry", "on", null, { nohist: "1" }, interactive); + } + + releaseCheckAutoOff(interactive: boolean): Promise { + return GlobalModel.submitCommand("releasecheck", "autooff", null, { nohist: "1" }, interactive); + } + + releaseCheckAutoOn(interactive: boolean): Promise { + return GlobalModel.submitCommand("releasecheck", "autoon", null, { nohist: "1" }, interactive); + } + + setTermFontSize(fsize: number, interactive: boolean): Promise { + let kwargs = { + nohist: "1", + termfontsize: String(fsize), + }; + return GlobalModel.submitCommand("client", "set", null, kwargs, interactive); + } + + setClientOpenAISettings(opts: { model?: string; apitoken?: string; maxtokens?: string }): Promise { + let kwargs = { + nohist: "1", + }; + if (opts.model != null) { + kwargs["openaimodel"] = opts.model; + } + if (opts.apitoken != null) { + kwargs["openaiapitoken"] = opts.apitoken; + } + if (opts.maxtokens != null) { + kwargs["openaimaxtokens"] = opts.maxtokens; + } + return GlobalModel.submitCommand("client", "set", null, kwargs, false); + } + + clientAcceptTos(): void { + GlobalModel.submitCommand("client", "accepttos", null, { nohist: "1" }, true); + } + + clientSetConfirmFlag(flag: string, value: boolean): Promise { + let kwargs = { nohist: "1" }; + let valueStr = value ? "1" : "0"; + return GlobalModel.submitCommand("client", "setconfirmflag", [flag, valueStr], kwargs, false); + } + + clientSetSidebar(width: number, collapsed: boolean): Promise { + let kwargs = { nohist: "1", width: `${width}`, collapsed: collapsed ? "1" : "0" }; + return GlobalModel.submitCommand("client", "setsidebar", null, kwargs, false); + } + + editBookmark(bookmarkId: string, desc: string, cmdstr: string) { + let kwargs = { + nohist: "1", + desc: desc, + cmdstr: cmdstr, + }; + GlobalModel.submitCommand("bookmark", "set", [bookmarkId], kwargs, true); + } + + deleteBookmark(bookmarkId: string): void { + GlobalModel.submitCommand("bookmark", "delete", [bookmarkId], { nohist: "1" }, true); + } + + openSharedSession(): void { + GlobalModel.submitCommand("session", "openshared", null, { nohist: "1" }, true); + } + + setLineState( + screenId: string, + lineId: string, + state: LineStateType, + interactive: boolean + ): Promise { + let stateStr = JSON.stringify(state); + return GlobalModel.submitCommand( + "line", + "set", + [lineId], + { screen: screenId, nohist: "1", state: stateStr }, + interactive + ); + } + + screenSidebarAddLine(lineId: string) { + GlobalModel.submitCommand("sidebar", "add", null, { nohist: "1", line: lineId }, false); + } + + screenSidebarRemove() { + GlobalModel.submitCommand("sidebar", "remove", null, { nohist: "1" }, false); + } + + screenSidebarClose(): void { + GlobalModel.submitCommand("sidebar", "close", null, { nohist: "1" }, false); + } + + screenSidebarOpen(width?: string): void { + let kwargs: Record = { nohist: "1" }; + if (width != null) { + kwargs.width = width; + } + GlobalModel.submitCommand("sidebar", "open", null, kwargs, false); + } +} + +const GlobalModel = Model.getInstance(); +const GlobalCommandRunner = CommandRunner.getInstance(); +export { Model, CommandRunner, GlobalModel, GlobalCommandRunner }; diff --git a/src/model/plugins.ts b/src/model/plugins.ts index 28e7f9906..adeb766c8 100644 --- a/src/model/plugins.ts +++ b/src/model/plugins.ts @@ -5,7 +5,7 @@ import * as mobx from "mobx"; import { PluginModel } from "../plugins/plugins"; import { RendererPluginType } from "../types/types"; import { OV } from "../types/types"; -import { CommandRunner } from "./commandrunner"; +import { CommandRunner } from "./model"; import { Model } from "./model"; class PluginsModel { diff --git a/src/model/remotes.ts b/src/model/remotes.ts index 1d40e9863..e36e81a05 100644 --- a/src/model/remotes.ts +++ b/src/model/remotes.ts @@ -8,7 +8,7 @@ import { TermWrap } from "../plugins/terminal/term"; import { RemoteInputPacketType, RemoteEditType } from "../types/types"; import * as appconst from "../app/appconst"; import { OV } from "../types/types"; -import { CommandRunner } from "./commandrunner"; +import { CommandRunner } from "./model"; import { Model } from "./model"; import { getTermPtyData } from "../util/modelutil"; diff --git a/src/model/screen.ts b/src/model/screen.ts index 8db3f5a04..72638c0c9 100644 --- a/src/model/screen.ts +++ b/src/model/screen.ts @@ -29,12 +29,12 @@ import * as appconst from "../app/appconst"; import { checkKeyPressed, adaptFromReactOrNativeKeyEvent } from "../util/keyutil"; import { OV } from "../types/types"; import { Model } from "./model"; -import { CommandRunner } from "./commandrunner"; +import { CommandRunner } from "./model"; import { Cmd } from "./cmd"; import { ScreenLines } from "./screenlines"; import { getTermPtyData } from "../util/modelutil"; -class ScreenModel { +class Screen { globalCommandRunner: CommandRunner; globalModel: Model; sessionId: string; @@ -696,4 +696,4 @@ class ScreenModel { } } -export { ScreenModel }; +export { Screen }; diff --git a/src/plugins/code/code.tsx b/src/plugins/code/code.tsx index f24af6e45..8897ec1a9 100644 --- a/src/plugins/code/code.tsx +++ b/src/plugins/code/code.tsx @@ -6,7 +6,7 @@ import * as T from "../../types/types"; import Editor, { Monaco } from "@monaco-editor/react"; import type * as MonacoTypes from "monaco-editor/esm/vs/editor/editor.api"; import { Markdown } from "../../app/common/elements"; -import { GlobalModel, GlobalCommandRunner } from "../../model/model_old"; +import { GlobalModel, GlobalCommandRunner } from "../../model"; import Split from "react-split-it"; import loader from "@monaco-editor/loader"; loader.config({ paths: { vs: "./node_modules/monaco-editor/min/vs" } }); diff --git a/src/plugins/core/basicrenderer.tsx b/src/plugins/core/basicrenderer.tsx index 40eff857e..4b5506a5f 100644 --- a/src/plugins/core/basicrenderer.tsx +++ b/src/plugins/core/basicrenderer.tsx @@ -20,7 +20,7 @@ import type { import * as T from "../../types/types"; import { debounce, throttle } from "throttle-debounce"; import * as util from "../../util/util"; -import { GlobalModel } from "../../model/model_old"; +import { GlobalModel } from "../../model"; type OV = mobx.IObservableValue; type CV = mobx.IComputedValue; diff --git a/src/plugins/csv/csv.tsx b/src/plugins/csv/csv.tsx index 58c809713..2580a5568 100644 --- a/src/plugins/csv/csv.tsx +++ b/src/plugins/csv/csv.tsx @@ -4,7 +4,7 @@ import React, { FC, useEffect, useState, useRef, useMemo } from "react"; import { RendererContext, RendererOpts, LineStateType, RendererModelContainerApi } from "../../types/types"; import * as T from "../../types/types"; -import { GlobalModel } from "../../model/model_old"; +import { GlobalModel } from "../../model"; import Papa from "papaparse"; import { createColumnHelper, diff --git a/src/plugins/mustache/mustache.tsx b/src/plugins/mustache/mustache.tsx index 1f15a9245..0112c2b97 100644 --- a/src/plugins/mustache/mustache.tsx +++ b/src/plugins/mustache/mustache.tsx @@ -9,7 +9,7 @@ import * as T from "../../types/types"; import { isBlank } from "../../util/util"; import mustache from "mustache"; import * as DOMPurify from "dompurify"; -import { GlobalModel } from "../../model/model_old"; +import { GlobalModel } from "../../model"; import "./mustache.less"; diff --git a/src/plugins/terminal/term.ts b/src/plugins/terminal/term.ts index f82aa8af1..29084fdc9 100644 --- a/src/plugins/terminal/term.ts +++ b/src/plugins/terminal/term.ts @@ -9,7 +9,7 @@ import { sprintf } from "sprintf-js"; import { boundMethod } from "autobind-decorator"; import { windowWidthToCols, windowHeightToRows } from "../../util/textmeasure"; import { boundInt } from "../../util/util"; -import { GlobalModel } from "../../model/model_old"; +import { GlobalModel } from "../../model"; import { Model } from "../../model/model"; import type { TermContextUnion, diff --git a/src/plugins/terminal/terminal.tsx b/src/plugins/terminal/terminal.tsx index 1acaeb9ed..d085adc27 100644 --- a/src/plugins/terminal/terminal.tsx +++ b/src/plugins/terminal/terminal.tsx @@ -8,7 +8,7 @@ import { boundMethod } from "autobind-decorator"; import dayjs from "dayjs"; import localizedFormat from "dayjs/plugin/localizedFormat"; import { If } from "tsx-control-statements/components"; -import { GlobalModel, LineContainerModel } from "../../model/model_old"; +import { GlobalModel, LineContainerModel } from "../../model"; import { termHeightFromRows } from "../../util/textmeasure"; import type { LineType } from "../../types/types"; import cn from "classnames"; diff --git a/src/types/types.ts b/src/types/types.ts index 17f80b8a4..782e81a63 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -4,7 +4,7 @@ import * as React from "react"; import * as mobx from "mobx"; import { TermWrap } from "../plugins/terminal/term"; -import { Cmd } from "../model/cmd"; +import { Cmd, Model } from "../model"; type ShareModeType = "local" | "web"; type FocusTypeStrs = "input" | "cmd"; @@ -474,7 +474,7 @@ type RendererModelInitializeParams = { opts: RendererOpts; lineState: LineStateType; api: RendererModelContainerApi; - ptyDataSource: (termContext: TermContextUnion) => Promise; + ptyDataSource: (termContext: TermContextUnion, globalModel: Model) => Promise; }; type RendererModel = {