DKL9 GitList
Repositories
DKL9 home
memoire
Code
Commits
Branches
Tags
Search
Tree:
254cab7
Branches
Tags
master
memoire
addcards.lua
Split actions out into separate files
John Smith
commited
254cab7
at 2023-133 18:45:37
addcards.lua
Blame
History
Raw
--[[ returns a not-necessarily-meaningful number iff `s` has mismathched curly-brackets ]] local function mismatched(s) return ("}" .. s):find("}[^{]+}") or (s .. "{"):find("{[^}]+{") end local function fn(config, deck) if isatty() then io.write("Reading prompts; press Ctrl-D to stop\n") end local rt = io.read("a") local cardctr = 0 local prctr = 0 for pt in rt:gmatch("(..-)\n\n") do local nc = {} -- these Prompts will just be converted to Rec, so we don't need to exclude answers from prompt-text for _re in pt:gmatch("%{[^%}]+%}") do table.insert(nc, Prompt:new(pt, "", os.time(), 30, 0, 0, os.time(), config:get("StartingEase") or 2.5)) prctr = prctr + 1 end if mismatched(pt) then io.write(string.format("Prompt %d:1 (\"%s\") contains mismatched braces\n", #deck + 1, pt)) end if #nc >= 1 then table.insert(deck, nc) cardctr = cardctr + 1 else io.write(string.format("Prompt \"%s\" contains no answers (check braces)\n", pt)) end end io.write(string.format( "Added %d cards (%d prompts)\n", cardctr, prctr )) if cardctr > 0 then return deck end end return { desc = "(a)dd card (from stdin)", nd = true, fn = fn }