From bed3abd97afddaf14bea2c615f8ee3a0a069f78c Mon Sep 17 00:00:00 2001 From: Jack Wilsdon Date: Wed, 28 Nov 2018 17:01:30 +0000 Subject: [PATCH] Allow exiting object selection early --- beets/ui/__init__.py | 9 +++++++-- docs/changelog.rst | 2 ++ docs/reference/cli.rst | 7 ++++--- test/test_ui_init.py | 10 ++++++++++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/beets/ui/__init__.py b/beets/ui/__init__.py index d3c3dafc2..1abce2e67 100644 --- a/beets/ui/__init__.py +++ b/beets/ui/__init__.py @@ -408,9 +408,14 @@ def input_select_objects(prompt, objs, rep): out = [] for obj in objs: rep(obj) - if input_yn(u'%s? (yes/no)' % prompt, True): + answer = input_options( + ('y', 'n', 'q'), True, u'%s? (yes/no/quit)' % prompt, + u'Enter Y or N:' + ) + if answer == u'y': out.append(obj) - print() # go to a new line + elif answer == u'q': + return out return out else: # No. diff --git a/docs/changelog.rst b/docs/changelog.rst index 61e244310..657d2a86e 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -46,6 +46,8 @@ New features: example, ``beet modify -a artist:beatles artpath!`` resets ``artpath`` attribute from matching albums back to the default value. :bug:`2497` +* Modify selection can now be applied early without selecting every item. + :bug:`3083` Changes: diff --git a/docs/reference/cli.rst b/docs/reference/cli.rst index 39a4b3f10..7b9e9eb72 100644 --- a/docs/reference/cli.rst +++ b/docs/reference/cli.rst @@ -269,9 +269,10 @@ affected items in the library and asks for your permission before making any changes. You can then choose to abort the change (type `n`), confirm (`y`), or interactively choose some of the items (`s`). In the latter case, the command will prompt you for every matching item or album and invite you to -type `y` or `n`. This option lets you choose precisely which data to change -without spending too much time to carefully craft a query. To skip the prompts -entirely, use the ``-y`` option. +type `y` to apply the changes, `n` to discard them or `q` to exit and apply +the selected changes. This option lets you choose precisely which data to +change without spending too much time to carefully craft a query. To skip the +prompts entirely, use the ``-y`` option. .. _move-cmd: diff --git a/test/test_ui_init.py b/test/test_ui_init.py index 3a146b0c0..41f167193 100644 --- a/test/test_ui_init.py +++ b/test/test_ui_init.py @@ -73,6 +73,16 @@ class InputMethodsTest(_common.TestCase): lambda s: self._print_helper2(s, "Prefix")) self.assertEqual(items, ['1', '2', '4']) + # Test selective 3 + self.io.addinput('s') + self.io.addinput('y') + self.io.addinput('n') + self.io.addinput('y') + self.io.addinput('q') + items = ui.input_select_objects( + "Prompt", full_items, self._print_helper) + self.assertEqual(items, ['1', '3']) + class InitTest(_common.LibTestCase): def setUp(self):