generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge version 0.3.2 from develop into master
- Loading branch information
Showing
9 changed files
with
260 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
export class Outputter { | ||
codeBlockElement: HTMLElement; | ||
outputElement: HTMLElement; | ||
clearButton: HTMLButtonElement; | ||
stdoutElem: HTMLSpanElement; | ||
stderrElem: HTMLSpanElement; | ||
stdoutText: string; | ||
stderrText: string; | ||
|
||
constructor (codeBlock: HTMLElement) { | ||
this.codeBlockElement = codeBlock; | ||
this.stdoutText = ""; | ||
this.stderrText = ""; | ||
} | ||
|
||
clear() { | ||
if(this.outputElement) { | ||
this.stdoutElem.setText(""); | ||
this.stderrElem.setText(""); | ||
} | ||
this.stdoutText = ""; | ||
this.stderrText = ""; | ||
} | ||
|
||
delete() { | ||
if(this.outputElement) | ||
this.outputElement.style.display = "none"; | ||
|
||
if(this.clearButton) | ||
this.clearButton.style.display = "none"; | ||
|
||
this.clear() | ||
} | ||
|
||
write(text: string) { | ||
if(! this.outputElement) { | ||
this.addOutputElement(); | ||
} | ||
|
||
if(! this.clearButton) { | ||
this.addClearButton(); | ||
} | ||
|
||
this.stdoutText += text; | ||
if(!this.stderrText && !this.stdoutText) return; | ||
|
||
this.stdoutElem.setText(this.stdoutText); | ||
|
||
// make visible again: | ||
this.outputElement.style.display = "block"; | ||
this.clearButton.style.display = "block"; | ||
} | ||
|
||
writeErr(text: string) { | ||
if(! this.outputElement) { | ||
this.addOutputElement(); | ||
} | ||
|
||
if(! this.clearButton) { | ||
this.addClearButton(); | ||
} | ||
|
||
this.stderrText += text; | ||
if(!this.stderrText && !this.stdoutText) return; | ||
|
||
this.stderrElem.setText(this.stderrText); | ||
|
||
// make visible again: | ||
this.outputElement.style.display = "block"; | ||
this.clearButton.style.display = "block"; | ||
} | ||
|
||
private getParentElement() { | ||
return this.codeBlockElement.parentElement as HTMLDivElement; | ||
} | ||
|
||
private addClearButton() { | ||
const parentEl = this.getParentElement(); | ||
|
||
this.clearButton = document.createElement("button"); | ||
this.clearButton.className = "clear-button"; | ||
this.clearButton.setText("Clear"); | ||
this.clearButton.addEventListener("click", () => this.delete()); | ||
|
||
parentEl.appendChild(this.clearButton); | ||
} | ||
|
||
private addOutputElement() { | ||
const parentEl = this.getParentElement(); | ||
|
||
let hr = document.createElement("hr"); | ||
|
||
this.outputElement = document.createElement("code"); | ||
this.outputElement.classList.add("language-output"); | ||
|
||
this.stdoutElem = document.createElement("span"); | ||
this.stdoutElem.addClass("stdout"); | ||
|
||
this.stderrElem = document.createElement("span"); | ||
this.stderrElem.addClass("stderr"); | ||
|
||
this.outputElement.appendChild(hr); | ||
this.outputElement.appendChild(this.stdoutElem); | ||
this.outputElement.appendChild(this.stderrElem); | ||
parentEl.appendChild(this.outputElement); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import {App, PluginSettingTab, Setting} from "obsidian"; | ||
import ExecuteCodePlugin from "./main"; | ||
|
||
export interface ExecutorSettings { | ||
nodePath: string; | ||
timeout: number; | ||
} | ||
|
||
export class SettingsTab extends PluginSettingTab { | ||
plugin: ExecuteCodePlugin; | ||
|
||
constructor(app: App, plugin: ExecuteCodePlugin) { | ||
super(app, plugin); | ||
this.plugin = plugin; | ||
} | ||
|
||
display() { | ||
const {containerEl} = this; | ||
containerEl.empty(); | ||
|
||
containerEl.createEl('h2', {text: 'Settings for the Code Execution Plugin.'}); | ||
|
||
new Setting(containerEl) | ||
.setName('Timeout (in seconds)') | ||
.setDesc('The time after which a program gets shut down automatically. This is to prevent infinite loops. ') | ||
.addText(slider => slider | ||
.setPlaceholder("" + this.plugin.settings.timeout/1000) | ||
.onChange(async (value) => { | ||
if( Number(value) * 1000){ | ||
console.log('Timeout set to: ' + value); | ||
this.plugin.settings.timeout = Number(value) * 1000; | ||
} | ||
await this.plugin.saveSettings(); | ||
})); | ||
|
||
new Setting(containerEl) | ||
.setName('Node path') | ||
.setDesc('The path to your node installation.') | ||
.addText(text => text | ||
.setPlaceholder(this.plugin.settings.nodePath) | ||
.setValue(this.plugin.settings.nodePath) | ||
.onChange(async (value) => { | ||
console.log('Node path set to: ' + value); | ||
this.plugin.settings.nodePath = value; | ||
})); | ||
} | ||
} |
Oops, something went wrong.