From 6196f6c4aabae74f16ea32f31951651ab0ad8edc Mon Sep 17 00:00:00 2001 From: Tangent Wantwight Date: Fri, 20 Oct 2023 18:22:08 -0400 Subject: [PATCH] expose getOpt error handling to frontend --- TODO | 3 --- src/3x5.ts | 12 ++++++------ src/lib/card.ts | 11 +++++------ 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/TODO b/TODO index f641526..7b0fbe4 100644 --- a/TODO +++ b/TODO @@ -1,9 +1,6 @@ - path to event listener: - card fields (vars maybe not needed yet?) - - get field command - - current card in state - - command - set field command - formatter helper for debug page - unit test diff --git a/src/3x5.ts b/src/3x5.ts index 7bff5aa..2d2b410 100644 --- a/src/3x5.ts +++ b/src/3x5.ts @@ -1,8 +1,8 @@ -import { Card, CardVm, GetField } from './lib/card'; -import { ALL as HTML } from './lib/html'; -import { parse } from './parser'; -import { runNoctl, Vm } from './vm'; -import { AsHtml, AsText, TextPiece } from './words'; +import { Card, CardVm, GetField } from "./lib/card"; +import { ALL as HTML } from "./lib/html"; +import { parse } from "./parser"; +import { runNoctl, Vm } from "./vm"; +import { AsHtml, AsText, TextPiece } from "./words"; /** * Updates a card's fields @@ -65,7 +65,7 @@ title "Hello, World!" const codeInput = document.createElement("textarea"); Object.assign(codeInput.style, TEXTAREA_STYLE, { height: "20em" }); codeInput.value = String.raw` -h1 "Hello, World!" +h1 [get title] para [2 + 2] block { This is a paragraph of text, with one [b bold] word. Yes, this means there has to be some magic in text processing... this won't work. diff --git a/src/lib/card.ts b/src/lib/card.ts index 7c925fa..43d5e10 100644 --- a/src/lib/card.ts +++ b/src/lib/card.ts @@ -1,6 +1,6 @@ -import { Vm } from '../vm'; -import { TextPiece } from '../words'; -import { getOpt } from './options'; +import { Vm } from "../vm"; +import { TextPiece } from "../words"; +import { getOpt } from "./options"; /** * Basic unit of information, also an "actor" in the programming system @@ -19,7 +19,6 @@ export type CardVm = Vm<{ }>; export function GetField(vm: CardVm, argv: TextPiece[]): TextPiece { - const [{ error = false }, fieldName] = getOpt(argv, { min: 1, max: 1 }); - // TODO: handle error - return { text: vm.card.fields[fieldName] ?? "" }; + const [{ error }, fieldName] = getOpt(argv, { $min: 1, $max: 1 }); + return { text: vm.card.fields[fieldName] ?? error ?? "" }; }