From cee091893a2d9d9aad26959dab095e71bc43b895 Mon Sep 17 00:00:00 2001 From: Linus Lee Date: Thu, 24 Sep 2020 06:42:23 -0400 Subject: Nail down basic app styles / layout --- static/js/lang.js | 4 +-- static/js/main.js | 73 +++++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 62 insertions(+), 15 deletions(-) (limited to 'static/js') diff --git a/static/js/lang.js b/static/js/lang.js index 4d17b48..08e1499 100644 --- a/static/js/lang.js +++ b/static/js/lang.js @@ -47,7 +47,7 @@ class Reader { */ class Wordifier { constructor(str) { - this.reader = new Reader(str); + this.reader = new Reader(str.trim()); this.tokens = []; } wordify() { @@ -83,7 +83,7 @@ class Wordifier { } this.reader.dropWhitespace(); } - return this.tokens.slice(1); + return this.tokens; } wordifyString(endChar) { let acc = ''; diff --git a/static/js/main.js b/static/js/main.js index b6aa634..3815538 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -1,5 +1,4 @@ -const PROG_DEFAULT = ` -DISCOVER HOW TO factorial WITH n +const PROG_DEFAULT = `DISCOVER HOW TO factorial WITH n WE SAID WHAT IF n IS ACTUALLY 0 WE SAID @@ -16,6 +15,18 @@ YOU WON'T WANT TO MISS result PLEASE LIKE AND SUBSCRIBE`; +const HEADLINES = [ + `You Won't Believe What This Programming Language Can Do!`, + `The Best Programming Language You Haven't Heard Of (It Will Surprise You!)`, + `Shocking New Programming Language Bewilders Programmers at Google and Facebook!`, + `Programmer Who Made Everything Now Predicts the Next Big Language!`, + `The Secret Programming Language Every 10x Programmer Recommends!`, +]; + +function randomHeadline() { + return HEADLINES[~~(Math.random() * HEADLINES.length)]; +} + const { Component, } = window.Torus; @@ -28,6 +39,10 @@ class Editor extends Component { this.errors = ''; this.handleRun = () => this.eval(); + this.handleReset = () => { + this.prog = PROG_DEFAULT; + this.render(); + } this.handleInput = evt => { this.prog = evt.target.value; this.render(); @@ -35,12 +50,13 @@ class Editor extends Component { } eval() { this.output = ''; + this.errors = ''; try { const tokens = tokenize(this.prog); const nodes = new Parser(tokens).parse(); const env = new Environment({ print: s => { - this.output += s.toString(); + this.output += s.toString() + '\n'; this.render(); }, }); @@ -53,23 +69,31 @@ class Editor extends Component { compose() { return jdom`
+ ${this.prog === PROG_DEFAULT ? null : + jdom``}
-
-
-
- ${this.output.split('\n').map(line => jdom`${line}`)} -
-
- ${this.errors.split('\n').map(line => jdom`${line}`)} -
+
+ ${this.output ? this.output + .split('\n') + .map(line => jdom`${line}`) + : jdom`No output.`}
+ ${this.errors ? jdom`
+ ${this.errors.split('\n').map(line => jdom`${line}`)} +
` : null}
`; } } @@ -80,9 +104,32 @@ class App extends Component { } compose() { return jdom`
-

Tabloid

-

The Clickbait Headline Programming Language

+
+

${randomHeadline()}

+ +

+ Tabloid: The Clickbait Headline Programming Language +

+
${this.editor.node} +

What?

+

But why?

+

Does it actually work?

+
`; } } -- cgit v1.2.3-70-g09d2