diff --git a/jrnl/Journal.py b/jrnl/Journal.py index e8e8b9ef..ca4a25e2 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -220,25 +220,16 @@ class Journal(object): self.entries = result - def remove_entries_by_title_and_time(self, entries_for_removal: list): - """ - Removes entries from the journal based on their titles and time. Times will - be datetime objects, however, they'll have the seconds stripped from them. - :param entries_for_removal: List of tuples in format of [(date, title), ... ] - """ - # Removal algorithm optimized using the fact that all entries for removal are in sorted - # order and the entries in the journal are also in sorted order. - cleaned_entries = [] - entries_for_removal_idx = 0 + def prompt_delete_entries(self): + """Prompts for deletion of entries in a journal.""" + print("Confirm each entry you want to delete [N/y]:") + to_delete: List[Entry] = [] for entry in self.entries: - if entries_for_removal_idx < len(entries_for_removal) and \ - time.from_same_minute(entry.date, entries_for_removal[entries_for_removal_idx][0]) and \ - entry.title == entries_for_removal[entries_for_removal_idx][1]: - entries_for_removal_idx += 1 - else: - cleaned_entries.append(entry) + response = input("jrnl: Delete entry '{}'? ".format(entry.pprint(short=True))) + if response == "y": + to_delete.append(entry) - self.entries = cleaned_entries + self.entries = [entry for entry in self.entries if entry not in to_delete] def new_entry(self, raw, date=None, sort=True): """Constructs a new entry from some raw text input. diff --git a/jrnl/cli.py b/jrnl/cli.py index fc802ff5..d4ff3032 100644 --- a/jrnl/cli.py +++ b/jrnl/cli.py @@ -13,7 +13,6 @@ from . import Journal from . import util from . import install from . import plugins -from . import time from .util import ERROR_COLOR, RESET_COLOR, UserAbort import jrnl import argparse @@ -298,31 +297,5 @@ def run(manual_args=None): journal.write() elif args.delete: - # Display all journal entry titles in a list and let user select one or more of them - entries = journal.pprint(short=True).split("\n") - raw_entries_to_delete = util.prompt_checklist( - name="entries_to_delete", - choices=entries, - message="Which entries would you like to delete? (Use arrow keys to select, Enter to confirm)" - ) - - # Confirm deletion - util.pretty_print_entries(raw_entries_to_delete) - - confirmation = "Are you sure you'd like to delete " - if len(raw_entries_to_delete) == 0: - return - elif len(raw_entries_to_delete) == 1: - confirmation += "this entry?" - else: - confirmation += "these entries?" - - if not util.yesno(confirmation): - return - - # Actually delete them - # The best we can do seems to be matching time stamps and title - entries_to_delete = [(time.parse(" ".join(entry.split()[:2])), " ".join(entry.split()[2:])) - for entry in raw_entries_to_delete] - journal.remove_entries_by_title_and_time(entries_to_delete) + journal.prompt_delete_entries() journal.write() diff --git a/jrnl/time.py b/jrnl/time.py index c9526f09..9ff125aa 100644 --- a/jrnl/time.py +++ b/jrnl/time.py @@ -63,10 +63,3 @@ def parse(date_str, inclusive=False, default_hour=None, default_minute=None): if dt.days < -28 and not year_present: date = date.replace(date.year - 1) return date - - -def from_same_minute(time1: datetime, time2: datetime) -> bool: - """Compares two datetimes, disregarding the seconds. Returns true if the - two datetimes are on the same day, during the same hour and minute.""" - delta = abs(time1 - time2) - return delta.days == 0 and delta.seconds <= 60 and time1.min == time2.min diff --git a/jrnl/util.py b/jrnl/util.py index c3f6f846..bc36ba9b 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -18,7 +18,6 @@ import codecs import unicodedata import shlex import logging -from PyInquirer import prompt as selection_prompt log = logging.getLogger(__name__) @@ -218,29 +217,3 @@ def split_title(text): if not punkt: return text, "" return text[:punkt.end()].strip(), text[punkt.end():].strip() - - -def pretty_print_entries(entries): - """Similar to Entry.pprint(short=True), except this function takes a - list of strings representing Entry objects instead of the actual objects - :param entries: List of strings in format of "DATE TITLE" """ - for entry in entries: - print("->", entry) - print("") - - -def prompt_checklist(name, choices, message): - formatted_choices = [] - for choice in choices: - formatted_choices.append({"name": choice}) - - questions = [ - { - 'type' : 'checkbox', - 'qmark' : '?', - 'message' : message, - 'name' : name, - 'choices' : formatted_choices - } - ] - return selection_prompt(questions)[name] diff --git a/poetry.lock b/poetry.lock index 424402df..e772b2d2 100644 --- a/poetry.lock +++ b/poetry.lock @@ -267,18 +267,6 @@ optional = false python-versions = "*" version = "1.7.1" -[[package]] -category = "main" -description = "Library for building powerful interactive command lines in Python" -name = "prompt-toolkit" -optional = false -python-versions = "*" -version = "1.0.14" - -[package.dependencies] -six = ">=1.9.0" -wcwidth = "*" - [[package]] category = "dev" description = "Python style guide checker" @@ -303,27 +291,6 @@ optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" version = "2.1.1" -[[package]] -category = "main" -description = "Pygments is a syntax highlighting package written in Python." -name = "pygments" -optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" -version = "2.4.2" - -[[package]] -category = "main" -description = "A Python module for collection of common interactive command line user interfaces, based on Inquirer.js" -name = "pyinquirer" -optional = false -python-versions = "*" -version = "1.0.3" - -[package.dependencies] -Pygments = ">=2.2.0" -prompt_toolkit = "1.0.14" -regex = ">=2016.11.21" - [[package]] category = "main" description = "Extensions to the standard Python datetime module" @@ -368,14 +335,6 @@ optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" version = "5.1.2" -[[package]] -category = "main" -description = "Alternative regular expression module, to replace re." -name = "regex" -optional = false -python-versions = "*" -version = "2019.08.19" - [[package]] category = "main" description = "Python bindings to FreeDesktop.org Secret Service API" @@ -424,16 +383,8 @@ version = "1.5.1" [package.dependencies] pytz = "*" -[[package]] -category = "main" -description = "Measures number of Terminal column cells of wide-character codes" -name = "wcwidth" -optional = false -python-versions = "*" -version = "0.1.7" - [metadata] -content-hash = "ca469ebf9978a0b3b79552e0d83ceff0ff4739ee2666d0605692251bc4fdc82f" +content-hash = "9896cf59c7552b6ad95219ee5555c7445a3fab39c2e4f4c6f3d991a36635e44b" python-versions = "^3.7" [metadata.hashes] @@ -463,21 +414,16 @@ parse = ["1b68657434d371e5156048ca4a0c5aea5afc6ca59a2fea4dd1a575354f617142"] parse-type = ["6e906a66f340252e4c324914a60d417d33a4bea01292ea9bbf68b4fc123be8c9", "f596bdc75d3dd93036fbfe3d04127da9f6df0c26c36e01e76da85adef4336b3c"] parsedatetime = ["3d817c58fb9570d1eec1dd46fa9448cd644eeed4fb612684b02dfda3a79cb84b", "9ee3529454bf35c40a77115f5a596771e59e1aee8c53306f346c461b8e913094"] passlib = ["3d948f64138c25633613f303bcc471126eae67c04d5e3f6b7b8ce6242f8653e0", "43526aea08fa32c6b6dbbbe9963c4c767285b78147b7437597f992812f69d280"] -prompt-toolkit = ["7281b5199235adaef6980942840c43753e4ab20dfe41338da634fb41c194f9d8", "82c7f8e07d7a0411ff5367a5a8ff520f0112b9179f3e599ee8ad2ad9b943d911", "cc66413b1b4b17021675d9f2d15d57e640b06ddfd99bb724c73484126d22622f"] pycodestyle = ["95a2219d12372f05704562a14ec30bc76b05a5b297b21a5dfe3f6fac3491ae56", "e40a936c9a450ad81df37f549d676d127b1b66000a6c500caa2b085bc0ca976c"] pycparser = ["a988718abfad80b6b157acce7bf130a30876d27603738ac39f140993246b25b3"] pyflakes = ["17dbeb2e3f4d772725c777fabc446d5634d1038f234e77343108ce445ea69ce0", "d976835886f8c5b31d47970ed689944a0262b5f3afa00a5a7b4dc81e5449f8a2"] -pygments = ["71e430bc85c88a430f000ac1d9b331d2407f681d6f6aec95e8bcfbc3df5b0127", "881c4c157e45f30af185c1ffe8d549d48ac9127433f2c380c24b84572ad66297"] -pyinquirer = ["c9a92d68d7727fbd886a7908c08fd9e9773e5dc211bf5cbf836ba90d366dee51"] python-dateutil = ["7e6584c74aeed623791615e26efd690f29817a27c73085b78e4bad02493df2fb", "c89805f6f4d64db21ed966fda138f8a5ed7a4fdbc1a8ee329ce1b74e3c74da9e"] pytz = ["303879e36b721603cc54604edcac9d20401bdbe31e1e4fdee5b9f98d5d31dfda", "d747dd3d23d77ef44c6a3526e274af6efeb0a6f1afd5a69ba4d5be4098c8e141"] pywin32-ctypes = ["24ffc3b341d457d48e8922352130cf2644024a4ff09762a2261fd34c36ee5942", "9dc2d991b3479cc2df15930958b674a48a227d5361d413827a4cfd0b5876fc98"] pyxdg = ["1948ff8e2db02156c0cccd2529b43c0cff56ebaa71f5f021bbd755bc1419190e", "fe2928d3f532ed32b39c32a482b54136fe766d19936afc96c8f00645f9da1a06"] pyyaml = ["0113bc0ec2ad727182326b61326afa3d1d8280ae1122493553fd6f4397f33df9", "01adf0b6c6f61bd11af6e10ca52b7d4057dd0be0343eb9283c878cf3af56aee4", "5124373960b0b3f4aa7df1707e63e9f109b5263eca5976c66e08b1c552d4eaf8", "5ca4f10adbddae56d824b2c09668e91219bb178a1eee1faa56af6f99f11bf696", "7907be34ffa3c5a32b60b95f4d95ea25361c951383a894fec31be7252b2b6f34", "7ec9b2a4ed5cad025c2278a1e6a19c011c80a3caaac804fd2d329e9cc2c287c9", "87ae4c829bb25b9fe99cf71fbb2140c448f534e24c998cc60f39ae4f94396a73", "9de9919becc9cc2ff03637872a440195ac4241c80536632fffeb6a1e25a74299", "a5a85b10e450c66b49f98846937e8cfca1db3127a9d5d1e31ca45c3d0bef4c5b", "b0997827b4f6a7c286c01c5f60384d218dca4ed7d9efa945c3e1aa623d5709ae", "b631ef96d3222e62861443cc89d6563ba3eeb816eeb96b2629345ab795e53681", "bf47c0607522fdbca6c9e817a6e81b08491de50f3766a7a0e6a5be7905961b41", "f81025eddd0327c7d4cfe9b62cf33190e1e736cc6e97502b3ec425f574b3e7a8"] -regex = ["1e9f9bc44ca195baf0040b1938e6801d2f3409661c15fe57f8164c678cfc663f", "2079f83ac094b436a8078988e38af44286c67eb5a259becfc563e8a81cb34a11", "43dbcc90e1bd42d905abc8dac75a64768d4b621c9e01adfcd8a57df1af65793e", "587b62d48ca359d2d4f02d486f1f0aa9a20fbaf23a9d4198c4bed72ab2f6c849", "835ccdcdc612821edf132c20aef3eaaecfb884c9454fdc480d5887562594ac61", "93f6c9da57e704e128d90736430c5c59dd733327882b371b0cae8833106c2a21", "a46f27d267665016acb3ec8c6046ec5eae8cf80befe85ba47f43c6f5ec636dcd", "c5c8999b3a341b21ac2c6ec704cfcccbc50f1fedd61b6a8ee915ca7fd4b0a557", "d4d1829cf97632673aa49f378b0a2c3925acd795148c5ace8ef854217abbee89", "d96479257e8e4d1d7800adb26bf9c5ca5bab1648a1eddcac84d107b73dc68327", "f20f4912daf443220436759858f96fefbfc6c6ba9e67835fd6e4e9b73582791a", "f2b37b5b2c2a9d56d9e88efef200ec09c36c7f323f9d58d0b985a90923df386d", "fe765b809a1f7ce642c2edeee351e7ebd84391640031ba4b60af8d91a9045890"] secretstorage = ["20c797ae48a4419f66f8d28fc221623f11fc45b6828f96bdb1ad9990acb59f92", "7a119fb52a88e398dbb22a4b3eb39b779bfbace7e4153b7bc6e5954d86282a8a"] six = ["3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c", "d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73"] toml = ["229f81c57791a41d65e399fc06bf0848bab550a9dfd5ed66df18ce5f05e73d5c", "235682dd292d5899d361a811df37e04a8828a5b1da3115886b73cf81ebc9100e", "f1db651f9657708513243e61e6cc67d101a39bad662eaa9b5546f789338e07a3"] tornado = ["349884248c36801afa19e342a77cc4458caca694b0eda633f5878e458a44cb2c", "398e0d35e086ba38a0427c3b37f4337327231942e731edaa6e9fd1865bbd6f60", "4e73ef678b1a859f0cb29e1d895526a20ea64b5ffd510a2307b5998c7df24281", "559bce3d31484b665259f50cd94c5c28b961b09315ccd838f284687245f416e5", "abbe53a39734ef4aba061fca54e30c6b4639d3e1f59653f0da37a0003de148c7", "c845db36ba616912074c5b1ee897f8e0124df269468f25e4fe21fe72f6edd7a9", "c9399267c926a4e7c418baa5cbe91c7d1cf362d505a1ef898fde44a07c9dd8a5"] tzlocal = ["4ebeb848845ac898da6519b9b31879cf13b6626f7184c496037b818e238f2c4e"] -wcwidth = ["3df37372226d6e63e1b1e1eda15c594bca98a22d33a23832a90998faa96bc65e", "f4ebe71925af7b40a864553f761ed559b43544f8f71746c2d756c7fe788ade7c"] diff --git a/pyproject.toml b/pyproject.toml index a497a3bf..1b84acde 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,6 @@ asteval = "^0.9.14" colorama = {version = "^0.4.1",platform = "win32"} python-dateutil = "^2.8" pyyaml = "^5.1" -PyInquirer = "^1.0" [tool.poetry.dev-dependencies] behave = "^1.2"