Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable concatenation of search queries (split by " / ") #1537

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions alot/buffers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,26 @@ def rebuild(self, reverse=False):
if exclude_tags:
exclude_tags = [t for t in exclude_tags.split(';') if t]

try:
self.result_count = self.dbman.count_messages(self.querystring)
threads = self.dbman.get_threads(
self.querystring, order, exclude_tags)
except NotmuchError:
self.ui.notify('malformed query string: %s' % self.querystring,
'error')
self.listbox = urwid.ListBox([])
self.body = self.listbox
return

self.threadlist = IterableWalker(threads, ThreadlineWidget,
dbman=self.dbman,
reverse=reverse)
querylist = self.querystring.split(' / ')
for query in querylist:
try:
self.result_count = self.dbman.count_messages(query)
threads = self.dbman.get_threads(
query, order, exclude_tags)
except NotmuchError:
self.ui.notify('malformed query string: %s' % query,
'error')
self.listbox = urwid.ListBox([])
self.body = self.listbox
return

iterablewalker = IterableWalker(threads, ThreadlineWidget,
dbman=self.dbman,
reverse=reverse)
if self.threadlist:
self.threadlist.append(iterablewalker)
else:
self.threadlist = iterablewalker

self.listbox = urwid.ListBox(self.threadlist)
self.body = self.listbox
Expand Down
8 changes: 8 additions & 0 deletions alot/walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import urwid


def chain(*iterables):
for iterable in iterables:
yield from iterable


class IterableWalker(urwid.ListWalker):

"""An urwid walker for iterables.
Expand Down Expand Up @@ -92,3 +97,6 @@ def _get_next_item(self):

def get_lines(self):
return self.lines

def append(self, iterableWalker):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if this is called after somebody started iterating over the IterableWalker already? Is that a case we have to think about? Even if this method is trivial it might be worth it to add a docstring to mention such constrains (if there are some).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I'll try to test that case somehow.

self.iterable = chain(self.iterable, iterableWalker.iterable)