vonshednob / pter

Manage your todo.txt in a commandline user interface (TUI)
https://vonshednob.cc/pter/
MIT License
102 stars 6 forks source link

List all contexts or projects #27

Closed lrustand closed 1 year ago

lrustand commented 1 year ago

Similar to search-context and search-project, but for all projects, not only those on the current item. I currently use manually created saved searches for all of my contexts, but this is very tedious and requires me to constantly update my list of saved searches. I would like to be able to press a keybind and then get a list of all projects/contexts to choose from.

Also a keybind to clear the search or "go home" would be great. I tried to make a saved search with an empty search string for this purpose, but it does not get saved.

lrustand commented 1 year ago

I have made implementations for these functions, but I do not have an account on Codeberg so I can't send you a pull request, so I will just paste it here.

    def do_list_project(self):
        projects = []
        for t in self.tasks.all_items:
            for c in t.task.projects:
                if c not in projects:
                    projects.append(c)

        if len(projects) == 0:
            return

        projects.sort()
        if len(projects) == 1:
            self.set_search('+'+projects[0])
        else:
            self.set_search('')
            self.focus.append(Selector(self.tasks,
                                       projects,
                                       lambda c: self.add_to_search('+'+c),
                                       title="Select project",
                                       numbered=True))
            self.paint(True)

    def do_list_context(self):
        contexts = []
        for t in self.tasks.all_items:
            for c in t.task.contexts:
                if c not in contexts:
                    contexts.append(c)

        if len(contexts) == 0:
            return

        contexts.sort()
        if len(contexts) == 1:
            self.set_search('@'+contexts[0])
        else:
            self.set_search('')
            self.focus.append(Selector(self.tasks,
                                       contexts,
                                       lambda c: self.add_to_search('@'+c),
                                       title="Select Context",
                                       numbered=True))
            self.paint(True)
vonshednob commented 1 year ago

Both really good ideas, thanks for the input!

Also, thanks a lot for the code snippet, I’ll have a look at it and keep you posted here about the progress :)

vonshednob commented 1 year ago

Alright then, have a look at version 3.5.0 -- the functions clear-search (bound to ^ by default), select-project (F6), and select-context (F7) are now implemented.

Let me know if this solves the issue for you!

lrustand commented 1 year ago

This is great, thanks! And so much cleaner than mine.

vonshednob commented 1 year ago

Thanks :slightly_smiling_face:; the starting point was your code at any rate!

Do you mind being added to the contributors?

lrustand commented 1 year ago

Thanks, go ahead if you want. Although I wouldn't say I really did that much

vonshednob commented 1 year ago

I wouldn’t say I really did that much

Nobody ever does :smirk: