diff --git a/package.json b/package.json index d760c8752..aec89bd9d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Prompt", - "version": "0.1.6", + "version": "0.1.7", "main": "dist/emain.js", "license": "Proprietary", "dependencies": { diff --git a/src/main.tsx b/src/main.tsx index 38d25e65e..342132111 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -2798,7 +2798,6 @@ class Main extends React.Component<{}, {}> { @boundMethod handleContextMenu(e : any) { - console.log("main contextmenu"); let isInNonTermInput = false; let activeElem = document.activeElement; if (activeElem != null && activeElem.nodeName == "TEXTAREA") { diff --git a/src/markdownrenderer.tsx b/src/markdownrenderer.tsx index 58fd9a9d4..0e1e43de6 100644 --- a/src/markdownrenderer.tsx +++ b/src/markdownrenderer.tsx @@ -26,13 +26,25 @@ function CodeRenderer(props : any) : any { ); } +const MaxMarkdownSize = 50000; + @mobxReact.observer class SimpleMarkdownRenderer extends React.Component<{data : Blob, context : RendererContext, opts : RendererOpts, savedHeight : number}, {}> { markdownText : OV = mobx.observable.box(null, {name: "markdownText"}); + markdownError : OV = mobx.observable.box(null, {name: "markdownError"}); componentDidMount() { - let prtn = this.props.data.text() + let dataBlob = this.props.data; + if (dataBlob.size > 50000) { + this.markdownError.set(sprintf("error: markdown too large to render size=%d", dataBlob.size)); + return; + } + let prtn = dataBlob.text() prtn.then((text) => { + if (/[\x00-\x08]/.test(text)) { + this.markdownError.set(sprintf("error: not rendering markdown, binary characters detected")); + return; + } mobx.action(() => { this.markdownText.set(text); })(); @@ -40,6 +52,9 @@ class SimpleMarkdownRenderer extends React.Component<{data : Blob, context : Ren } render() { + if (this.markdownError.get() != null) { + return
{this.markdownError.get()}
; + } if (this.markdownText.get() == null) { return
} @@ -53,10 +68,11 @@ class SimpleMarkdownRenderer extends React.Component<{data : Blob, context : Ren h6: (props) => HeaderRenderer(props, 6), code: CodeRenderer, }; + let opts = this.props.opts; let markdownText = this.markdownText.get(); return (
-
+
diff --git a/src/model.ts b/src/model.ts index d23642fc8..bbfd2db5a 100644 --- a/src/model.ts +++ b/src/model.ts @@ -2409,6 +2409,9 @@ class Model { if (isBlank(plugin.name)) { throw new Error("invalid plugin, no name"); } + if (plugin.name == "terminal" || plugin.name == "none") { + throw new Error(sprintf("invalid plugin, name '%s' is reserved", plugin.name)); + } let existingPlugin = this.getRendererPluginByName(plugin.name); if (existingPlugin != null) { throw new Error(sprintf("plugin with name %s already registered", plugin.name)); @@ -3213,6 +3216,20 @@ class CommandRunner { GlobalModel.submitCommand("line", "view", [sessionId, screenId, String(lineNum)], {"nohist": "1"}, false); } + lineArchive(lineArg : string, archive : boolean) { + let kwargs = {"nohist": "1"}; + let archiveStr = (archive ? "1" : "0"); + GlobalModel.submitCommand("line", "archive", [lineArg, archiveStr], kwargs, false); + } + + lineSet(lineArg : string, opts : {renderer? : string}) { + let kwargs = {"nohist": "1"}; + if ("renderer" in opts) { + kwargs["renderer"] = opts.renderer ?? ""; + } + GlobalModel.submitCommand("line", "set", [lineArg], kwargs, false); + } + createNewSession() { GlobalModel.submitCommand("session", "open", null, {"nohist": "1"}, false); } diff --git a/src/settings.tsx b/src/settings.tsx index b509c6a83..18fe788e5 100644 --- a/src/settings.tsx +++ b/src/settings.tsx @@ -7,7 +7,7 @@ import {If, For, When, Otherwise, Choose} from "tsx-control-statements/component import cn from "classnames"; import {GlobalModel, GlobalCommandRunner, TabColors} from "./model"; import {Toggle} from "./elements"; -import {LineType} from "./types"; +import {LineType, RendererPluginType} from "./types"; type OV = mobx.IObservableValue; type OArr = mobx.IObservableArray; @@ -232,8 +232,18 @@ class SessionSettingsModal extends React.Component<{sessionId : string}, {}> { @mobxReact.observer class LineSettingsModal extends React.Component<{line : LineType}, {}> { + tempArchived : OV; + tempRenderer : OV; + rendererDropdownActive : OV = mobx.observable.box(false, {name: "lineSettings-rendererDropdownActive"}); + constructor(props : any) { super(props); + let {line} = props; + if (line == null) { + return; + } + this.tempArchived = mobx.observable.box(!!line.archived, {name: "lineSettings-tempArchived"}); + this.tempRenderer = mobx.observable.box(line.renderer, {name: "lineSettings-renderer"}); } @boundMethod @@ -245,9 +255,68 @@ class LineSettingsModal extends React.Component<{line : LineType}, {}> { @boundMethod handleOK() : void { + let {line} = this.props; mobx.action(() => { GlobalModel.lineSettingsModal.set(null); })(); + if (this.tempRenderer.get() != line.renderer) { + GlobalCommandRunner.lineSet(line.lineid, { + "renderer": this.tempRenderer.get(), + }); + } + if (this.tempArchived.get() != !!line.archived) { + GlobalCommandRunner.lineArchive(line.lineid, this.tempArchived.get()); + } + } + + @boundMethod + handleChangeArchived(val : boolean) : void { + mobx.action(() => { + this.tempArchived.set(val); + })(); + } + + @boundMethod + toggleRendererDropdown() : void { + mobx.action(() => { + this.rendererDropdownActive.set(!this.rendererDropdownActive.get()); + })(); + } + + @boundMethod + clickSetRenderer(renderer : string) : void { + mobx.action(() => { + this.tempRenderer.set(renderer); + this.rendererDropdownActive.set(false); + })(); + } + + renderRendererDropdown() : any { + let {line} = this.props; + let renderer = this.tempRenderer.get() ?? "terminal"; + let plugins = GlobalModel.rendererPlugins; + let plugin : RendererPluginType = null; + return ( +
+
+ +
+
+
+
this.clickSetRenderer("none") } key="none" className="dropdown-item">none
+
this.clickSetRenderer(null) } key="terminal" className="dropdown-item">terminal
+ +
this.clickSetRenderer(plugin.name) } key={plugin.name} className="dropdown-item">{plugin.name}
+
+
+
+
+ ); } render() { @@ -271,9 +340,22 @@ class LineSettingsModal extends React.Component<{line : LineType}, {}> { Renderer
- xxx + {this.renderRendererDropdown()}
+
+
+ Archived +
+
+ +
+ will be archived + will be un-archived +
+
+
+