Skip to content

Commit

Permalink
Merge version 0.3.2 from develop into master
Browse files Browse the repository at this point in the history
  • Loading branch information
twibiral authored Apr 18, 2022
2 parents 92115de + d0934e6 commit b7eee45
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 193 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]


## [0.3.2] - 2022-04-18
### Changed
- Fix markdown post processor
- Remove use of innerHTML

## [0.3.1] - 2022-04-18
### Added
- Changelog
Expand Down
107 changes: 107 additions & 0 deletions Outputter.ts
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);
}
}
47 changes: 47 additions & 0 deletions SettingsTab.ts
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;
}));
}
}
Loading

0 comments on commit b7eee45

Please sign in to comment.