Skip to content

Commit

Permalink
updated type definitions to support IDs and multiple outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo2897 committed May 8, 2018
1 parent 4b6f411 commit b03cd9c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
8 changes: 3 additions & 5 deletions src-backend/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import * as vscode from 'vscode';

import {Card} from 'vscode-ipe-types';
import {Card, CardOutput} from 'vscode-ipe-types';
import {WebviewController} from "./webviewController";
import {Interpreter} from "./interpreter";
import {UserInteraction} from "./userInteraction";
Expand All @@ -22,10 +22,8 @@ export function activate(context: vscode.ExtensionContext) {
// Execute code when new card is created
userInteraction.onNewCard(sourceCode => {
interpreter.executeCode(sourceCode).then(output => {
let newCard = new Card(Interpreter.makeCardTitle(sourceCode));
newCard.sourceCode = sourceCode;
newCard.interpreterOutput = output;
webview.addCard(newCard);
let cardTitle = Interpreter.makeCardTitle(sourceCode);
webview.addCard(new Card(0, cardTitle, sourceCode, [new CardOutput("plaintext", output)]));
}).catch(reason => vscode.window.showErrorMessage(reason));
});
});
Expand Down
15 changes: 13 additions & 2 deletions src-common/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@

export class Card {
public collapsed: boolean = false; // not implemented
public codeExpanded: boolean = false;

constructor(
public id: number,
public title: string,
public sourceCode: string = "",
public interpreterOutput: string = ""
public sourceCode: string,
public outputs: CardOutput[]
) {}
}

export class CardOutput {
constructor(
public type: string,
public output: string
) {}
}
4 changes: 2 additions & 2 deletions src-frontend/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {AfterViewInit, Component, QueryList, ViewChild, ViewChildren} from '@angular/core';
import {ExtensionService} from './classes/extension.service';
import {Card} from "vscode-ipe-types";
import {Card, CardOutput} from "vscode-ipe-types";

@Component({
selector: 'app-root',
Expand All @@ -9,7 +9,7 @@ import {Card} from "vscode-ipe-types";
})
export class AppComponent implements AfterViewInit {
cards: Card[] = [
new Card('sample card', 'print("Hello, world!");', 'Hello, world!')
new Card(0, 'sample card', 'print("Hello, world!");', [new CardOutput('plaintext', 'Hello, world!')])
];

constructor(private extension: ExtensionService) {
Expand Down
4 changes: 3 additions & 1 deletion src-frontend/src/app/card/card.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ <h2>{{card.title}}</h2>

<div class="separator"></div>

<div class="card-output"><pre>{{card.interpreterOutput}}</pre></div>
<div class="card-output" *ngFor="let output of card.outputs">
<pre>{{output.output}}</pre>
</div>
</div>

0 comments on commit b03cd9c

Please sign in to comment.