bloznelis / typioca

Cozy typing speed tester in terminal
MIT License
750 stars 22 forks source link

Dynamic pools (aka word lists) #40

Closed ernierasta closed 2 years ago

ernierasta commented 2 years ago

Hi Lukas! Now, when we have support for international texts, what would you say about having ability to load new pools dynamically? While it would be still required to recompile app, it would allow us to just drop file with some descriptive name into embedables directory and be ready to go.

I am not sure 100% if it is possible, but probably yes. What do you think, is that something we want?

I make no promises, but if you think it is something you like to see in typioca I will try to implement it.

bloznelis commented 2 years ago

Hey, yeah, new pools are the next big feature that I'm going to focus on.

The problem, as you mention, is that we want to load them dynamically and not package it with the binary itself. It is certainly possible, just need to think of:

All that aside, if you want to help, you can try to implement a word list downloader client, which would be later used to call from UI.

ernierasta commented 2 years ago

Oh, great! That's great to hear!

  • Good place to store these pools (maybe /home/{user}/.typioca)

No, just no. :-) This is not best place. In my opinion it should follow modern XDG standard, so: $XDG_DATA_HOME/typioca or if not defined: $HOME/.local/share/typioca - this is proper place to keep it. If there will be any config: $XDG_CONFIG_HOME/typioca or if not defined: $HOME/.config/typioca - all configs should be there.

Here is full specification if you would like to know more: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

Basically all apps follow those rules.

* Whether current format is good enough. For example, maybe it would be wise to use a more structured format like JSON, which would be useful if we want to append some metadata to word lists.

That is a question, I was thinking about this in context of metadata like name of words/sentences collection. JSON, TOML, YAML, those are formats which are harder to generate by using simple tools (like in plain bash f.e.), but if you think it will benefit in better functionality ... go for it. I do not have opinion on that.

* How to make word pools configuration configurable via UI. Download new lists, enable/disable already downloaded ones.

I like this idea very much. Question is, download from where? Maybe a github repo dedicated to typioca words/sentence lists? If yes, which hierarchy would be the best? By languages?

All that aside, if you want to help, you can try to implement a word list downloader client, which would be later used to call from UI.

This is quite trivial in golang. :-) Here is code from one of my project (but I am sure it is not written by me), works good:

// DownloadFile will download a url to a local file. It's efficient because it will
// write as it downloads and not load the whole file into memory.
func DownloadFile(filepath string, url string) error {
    // Get the data
    resp, err := http.Get(url)
    if err != nil {
        return err
    }
    defer resp.Body.Close()

    // Create the file
    out, err := os.Create(filepath)
    if err != nil {
        return err
    }
    defer out.Close()

    // Write the body to file
    _, err = io.Copy(out, resp.Body)
    return err
}
bloznelis commented 2 years ago

This took a while, but was added with https://github.com/bloznelis/typioca/pull/50. Please check if you like it ! @ernierasta