Implement correction interface
John Smith

John Smith commited on 2022-2 22:12:41
Showing 2 changed files, with 38 additions and 3 deletions.


When the user responds to a prompt with "correction",
the card from which it originated gets added to an edit queue.
At the end of the session, Memoire asks the user
what to do with each such card:
* delete: the card gets deleted
* edit: the card PromptText gets replaced with user input
* cancel: move on; nothing happens to the card
... ...
@@ -106,6 +106,7 @@ elseif action == "r" then
106 106
         local climt = io.read("l")
107 107
         local climn = tonumber(climt)
108 108
         if climn then
109
+            local editqueue = {}
109 110
             local start = os.time()
110 111
             -- review prompts in this session's set
111 112
             for ind, ip in ipairs(ctrt) do
... ...
@@ -128,24 +129,55 @@ elseif action == "r" then
128 129
                 local resp = io.read("l")
129 130
                 local sc = succfromstr(resp)
130 131
                 if sc == -1 then
131
-                    deck[ip[1]][ip[2]] = deck[ip[1]][ip[2]]
132
-                    -- TODO: edit card
132
+                    table.insert(editqueue, ip[1])
133 133
                 else
134 134
                     review.update(deck[ip[1]][ip[2]], st, sc)
135 135
                 end
136 136
                 clear()
137 137
             end
138
+            if #ctrt > 0 then
138 139
                 local endt = os.time()
139 140
                 io.write(string.format(
140 141
                     "Reviewed %d prompts in %d seconds\n",
141 142
                     math.min(#ctrt, climn),
142 143
                     endt - start
143 144
                 ))
144
-            if #ctrt > 0 then
145 145
                 io.write(string.format(
146 146
                     "(%f seconds per card)\n",
147 147
                     (endt - start) / math.min(#ctrt, climn)
148 148
                 ))
149
+            end
150
+            if #editqueue > 0 then
151
+                io.write(string.format(
152
+                    "\n%d cards queued for editing -- press Enter to proceed",
153
+                    #editqueue
154
+                ))
155
+                io.read("l")
156
+                for ind, ci in ipairs(editqueue) do
157
+                    local pr = deck[ci][1]
158
+                    if pr then
159
+                        io.write(string.format(
160
+                            "Card #%d:\n%s\nCancel correction / Delete / Edit ",
161
+                            ci, pr:spt()
162
+                        ))
163
+                        local resp = io.read("l"):sub(1, 1):lower()
164
+                        if resp == "d" then
165
+                            deck[ci][1].deleted = true
166
+                        elseif resp == "e" then
167
+                            io.write("Enter edited version:\n")
168
+                            local ev = io.read("l")
169
+                            local cardrec = Prompt:torec(deck[ci])
170
+                            cardrec.PromptText = { ev }
171
+                            deck[ci] = Prompt:fromrecs({ cardrec })[1]
172
+                        -- assume all other inputs to mean Cancel
173
+                        else
174
+                        end
175
+                    else
176
+                        io.write(string.format("Card #%d is invalid!\n", ci))
177
+                    end
178
+                end
179
+            end
180
+            if climn > 0 then
149 181
                 loader.save(deckfname, deck)
150 182
             end
151 183
         else
... ...
@@ -76,6 +76,9 @@ end
76 76
     returns (on failure) nil
77 77
 ]]
78 78
 function Prompt:torec(prompts)
79
+    if prompts[1].deleted then
80
+        return {}
81
+    end
79 82
     local fspt = prompts[1]:spt()
80 83
     local ret = { PromptText = { fspt }, LastReview = {}, LastDelay = {}, Successes = {}, Failures = {} }
81 84
     if prompts[1].created then
82 85