John Smith commited on 2023-133 17:47:50
Showing 1 changed files, with 22 additions and 0 deletions.
The "q" option now presents cards (with indices into the deck) containing a string specified by the user. Users could already do this with grep, but this is easier and better-integrated into Memoire. Perhaps Memoire will support more elaborate queries in the future.
| ... | ... |
@@ -302,6 +302,28 @@ local actions = {
|
| 302 | 302 |
end, |
| 303 | 303 |
}, |
| 304 | 304 |
|
| 305 |
+ q = {
|
|
| 306 |
+ desc = "(q)uery deck for cards (case-sensitive)", |
|
| 307 |
+ nd = true, |
|
| 308 |
+ nq = true, |
|
| 309 |
+ fn = function(config, deck, deckfname, qs) |
|
| 310 |
+ local mcl = {}
|
|
| 311 |
+ for i, card in ipairs(deck) do |
|
| 312 |
+ if card[1]:spt():find(qs) then |
|
| 313 |
+ table.insert(mcl, i) |
|
| 314 |
+ end |
|
| 315 |
+ end |
|
| 316 |
+ if #mcl >= 1 then |
|
| 317 |
+ io.write(string.format("Found %d match%s for %q:\n", #mcl, #mcl == 1 and "" or "es", qs))
|
|
| 318 |
+ else |
|
| 319 |
+ io.write(string.format("No matches for %q\n", qs))
|
|
| 320 |
+ end |
|
| 321 |
+ for _, i in ipairs(mcl) do |
|
| 322 |
+ io.write(string.format("%d %s\n", i, deck[i][1]:spt()))
|
|
| 323 |
+ end |
|
| 324 |
+ end, |
|
| 325 |
+ }, |
|
| 326 |
+ |
|
| 305 | 327 |
r = {
|
| 306 | 328 |
desc = "(r)eview sesion", |
| 307 | 329 |
nd = true, |
| 308 | 330 |