site

Website's source files.
Log | Files | Refs | Submodules | LICENSE

commit caea8ced2615bc94e762d69ffe4845d08a7e2bc1
parent d3cd9926192f266a5e1f7cc645140cc74c03e901
Author: Ryan Jeffrey <ryan@ryanmj.xyz>
Date:   Sat, 22 Jan 2022 14:14:07 -0800

New dynamic command system

Diffstat:
Mserver.ts | 61++++++++++++++++++++++++++++---------------------------------
Mviews/index.handlebars | 2+-
Mviews/partials/terminalTemplate.handlebars | 28++++++++++++++--------------
3 files changed, 43 insertions(+), 48 deletions(-)

diff --git a/server.ts b/server.ts @@ -96,45 +96,37 @@ class LSStat { } } -class TerminalWindow { - lsList: LSStat[]; +// Dummy class just for inheritance. +class Command { + args: string; + constructor(args: string) { + this.args = args; + } +} - where: string; - markup: string; +class LS extends Command { + lsList: LSStat[]; - constructor() { + constructor(dir: string, ext:string, names: string[]) { + super(dir); + this.lsList = LSStat.lsList(dir, ext, names); } +} - static makeDir(path: string) : TerminalWindow { - let newWin = new TerminalWindow(); - // LS if it is a directory, read file if not. - if(fs.lstatSync(path).isDirectory()) { - newWin.where = path; - newWin.lsList = LSStat.lsDir(path); - newWin.markup = ""; - } - else { - newWin.where = ""; - newWin.lsList = []; - newWin.markup = fs.readFileSync(path, 'utf8'); - } - return newWin; - } +class Cat extends Command { + markup: string; - static makeLS(dir: string, ext: string, paths: string[]) : TerminalWindow { - let newWin = new TerminalWindow(); - newWin.where = dir; - newWin.lsList = LSStat.lsList(dir, ext, paths); - newWin.markup = ""; - return newWin; + constructor(path: string) { + super(path); + this.markup = fs.readFileSync(path, 'utf8'); } +} + +class TerminalWindow { + commands: Command[]; - static makeList(lsList: LSStat[]) : TerminalWindow { - let newWin = new TerminalWindow(); - newWin.lsList = lsList; - newWin.where = ""; - newWin.markup = ""; - return newWin; + constructor(...commands: Command[]) { + this.commands = commands; } } @@ -188,9 +180,12 @@ app.get('/:item', (req, res, next) => { } }); +// TODO!!!! each window needs multiple commands. app.get('/', (req, res, next) => { res.status(200).render('index', { - windows: [LSStat.makeLS('.', '.html', ['main', 'software', 'sneed'])] + windows: [new TerminalWindow(new Cat('public/figlet.html'), + new LS('.', '.html', ['main', 'software', 'sneed']), + new Cat('public/front.html'))], }); }); diff --git a/views/index.handlebars b/views/index.handlebars @@ -1,3 +1,3 @@ {{#each windows}} - {{> terminalTemplate isTerminal=true}} + {{> terminalTemplate}} {{/each}} diff --git a/views/partials/terminalTemplate.handlebars b/views/partials/terminalTemplate.handlebars @@ -1,21 +1,21 @@ -{{#if isTerminal}} - <div class="twin topl"> - <div style="tcontent"> - </div> - <div id="content"> - {{#if lsList}} - <p> - <span class="prompt1">ryan</span><span class="prompt2">@</span><span class="prompt3">themainframe</span><span class="prompt4"></span> ls {{where}} - </p> +<div class="twin topl"> + <div style="tcontent"> + </div> + <div id="content"> + {{#each commands}} + {{#if markup}} + <hr class="prompt-break"> + <span class="prompt1">ryan</span><span class="prompt2">@</span><span class="prompt3">themainframe</span><span class="prompt4"></span> <span>cat {{args}}</span> + {{{markup}}} + {{else}} + <hr class="prompt-break"> + <span class="prompt1">ryan</span><span class="prompt2">@</span><span class="prompt3">themainframe</span><span class="prompt4"></span> <span>ls {{args}}</span> {{#each lsList}} {{> lsTemplate}} {{/each}} {{/if}} + {{/each}} - {{#if markup}} - {{{markup}}} - {{/if}} - </div> </div> -{{/if}} +</div>