diff --git a/package.json b/package.json index ead3bae..af069d3 100644 --- a/package.json +++ b/package.json @@ -192,7 +192,7 @@ "enumDescriptions": [ "The directed graph layout library Dagre", "Eclipse Layout Kernel (ELK) with the Layered algorithm", - "Terrastruct's AutoLayout Approach - available if installed" + "Terrastruct's AutoLayout Approach" ], "description": "Layout used for preview." }, diff --git a/pages/previewPage.html b/pages/previewPage.html index 67e940e..382381c 100644 --- a/pages/previewPage.html +++ b/pages/previewPage.html @@ -66,7 +66,7 @@ height: 100%; } - path { + #toolbar path { fill: var(--vscode-button-foreground); } diff --git a/src/layoutPicker.ts b/src/layoutPicker.ts index 3023383..2925e78 100644 --- a/src/layoutPicker.ts +++ b/src/layoutPicker.ts @@ -33,8 +33,9 @@ const talaPluginName: string = */ export class layoutPicker { constructor() { - // If the plugin file exists, add the option if it hasn't been added before - if (util.isFileOnPath(talaPluginName)) { + // If d2 reports TALA (bundled or as a plugin), or the plugin file exists, + // add the option if it hasn't been added before + if (util.isLayoutAvailable("tala") || util.isFileOnPath(talaPluginName)) { if (layouts.indexOf(layoutTala) === -1) { layouts.push(layoutTala); } diff --git a/src/utility.ts b/src/utility.ts index 982296a..94b0953 100644 --- a/src/utility.ts +++ b/src/utility.ts @@ -122,6 +122,21 @@ class Utility { util.showErrorToolsNotFound(""); } } + + /** + * isLayoutAvailable - returns true if `d2 layout` reports the given + * layout engine, whether it is bundled with d2 or installed as a + * plugin on the path. + */ + isLayoutAvailable(layout: string): boolean { + const d2Path: string = ws.get("execPath", "d2"); + const result = spawnSync(d2Path, ["layout"], { encoding: "utf-8" }); + if (result.error || result.status !== 0) { + return false; + } + + return new RegExp(`^${layout}\\b`, "m").test(result.stdout); + } } export class VT {