New pro­ject: Anki” for the com­mand-line

Created: Thu Mar 28 15:25:05 CET 2019

Last mod­i­fied: Fri Apr 5 23:14:51 CEST 2019


Go check the source code here!

Latest im­prove­ments: click here.

I wanted some­thing that works pretty much like Anki but for the com­mand line.

I wanted it writ­ten in C, I wanted it to be smart and not show the same cards every time.

Wide char­ac­ters are sup­ported. It means you can store cards that are writ­ten in japan­ese for in­stance.

Don’t ex­pect *.apkg com­pat­i­bil­ity. Cards will be stored in reg­u­lar text files. For now they are hard coded.

Is there a pro­to­type al­ready?

Yes, and here is the first record­ing!

I hard­coded the cards as fol­low:

o(L"あ", L"a\n");
o(L"い", L"i\n");
o(L"う", L"u\n");
o(L"え", L"e\n");
o(L"お", L"o\n");

o(L"か", L"ka\n");
o(L"き", L"ki\n");
o(L"く", L"ku\n");
o(L"け", L"ke\n");
o(L"こ", L"ko\n");

/* [...] */

Data struc­tures?

Cards are se­ri­al­ized into hash tables. I’m us­ing the fol­low­ing C struc­ture to store cards in mem­ory:

struct Card {
    wchar_t *question; /* key */
    wchar_t *answer;
    unsigned int priority;
    unsigned int last_appearance;

    struct Card *next; /* linked list */
};

Finding the next card to show is a sim­ple task:

Iterate over the hash table, find the card with the high­est pri­or­ity that has­n’t shown up in a while (or the in­verse), in­crease its ->last_appearance field and de­crease ->priority.

Any sug­ges­tion, re­quest for fea­tures etc. goes in the com­ment sec­tion right be­low.

source code