mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 08:38:32 +02:00
Interactive delete (#850)
* fixup alichtman's implementation * cleanup imports Co-authored-by: Aaron Lichtman <aaronlichtman@gmail.com> Co-authored-by: Jonathan Wren <jonathan@nowandwren.com>
This commit is contained in:
parent
f4fca3e5a4
commit
15429d4f61
4 changed files with 36 additions and 25 deletions
|
@ -93,17 +93,3 @@ Feature: Basic reading and writing to a journal
|
|||
2013-06-10 15:40 Life is good.
|
||||
"""
|
||||
And we should get no error
|
||||
|
||||
# The input for this test is <SPACE><ENTER>y
|
||||
Scenario: --delete flag allows deletion of single entry
|
||||
Given we use the config "deletion.yaml"
|
||||
When we run "jrnl --delete"
|
||||
And we type " "
|
||||
And we type
|
||||
"""
|
||||
|
||||
y
|
||||
"""
|
||||
When we run "jrnl -on 2019-10-29 -s"
|
||||
Then the output should not contain "2019-10-29 11:11 First entry."
|
||||
|
||||
|
|
20
features/delete.feature
Normal file
20
features/delete.feature
Normal file
|
@ -0,0 +1,20 @@
|
|||
Feature: Delete entries from journal
|
||||
|
||||
Scenario: --delete flag allows deletion of single entry
|
||||
Given we use the config "deletion.yaml"
|
||||
When we run "jrnl -n 1"
|
||||
Then the output should contain
|
||||
"""
|
||||
2019-10-29 11:13 Third entry.
|
||||
"""
|
||||
When we run "jrnl --delete" and enter
|
||||
"""
|
||||
N
|
||||
N
|
||||
Y
|
||||
"""
|
||||
When we run "jrnl -n 1"
|
||||
Then the output should contain
|
||||
"""
|
||||
2019-10-29 11:11 Second entry.
|
||||
"""
|
|
@ -1,13 +1,12 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from . import Entry
|
||||
from . import util
|
||||
from . import time
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
|
||||
from datetime import datetime
|
||||
import logging
|
||||
from jrnl import Entry, util, time
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -111,7 +110,8 @@ class Journal:
|
|||
def _load(self, filename):
|
||||
raise NotImplementedError
|
||||
|
||||
def _store(self, filename, text):
|
||||
@classmethod
|
||||
def _store(filename, text):
|
||||
raise NotImplementedError
|
||||
|
||||
def _parse(self, journal_txt):
|
||||
|
@ -236,21 +236,26 @@ class Journal:
|
|||
|
||||
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] = []
|
||||
|
||||
to_delete = []
|
||||
|
||||
def ask_delete(entry):
|
||||
return util.yesno(
|
||||
f"Delete entry '{entry.pprint(short=True)}'?", default=False,
|
||||
)
|
||||
|
||||
for entry in self.entries:
|
||||
response = input("jrnl: Delete entry '{}'? ".format(entry.pprint(short=True)))
|
||||
if response == "y":
|
||||
if ask_delete(entry):
|
||||
to_delete.append(entry)
|
||||
|
||||
self.entries = [entry for entry in self.entries if entry not in to_delete]
|
||||
self.write()
|
||||
|
||||
def new_entry(self, raw, date=None, sort=True):
|
||||
"""Constructs a new entry from some raw text input.
|
||||
If a date is given, it will parse and use this, otherwise scan for a date in the input first."""
|
||||
|
||||
raw = raw.replace("\\n ", "\n").replace("\\n", "\n")
|
||||
starred = False
|
||||
# Split raw text into title and body
|
||||
sep = re.search(r"\n|[?!.]+ +\n?", raw)
|
||||
first_line = raw[: sep.end()].strip() if sep else raw
|
||||
|
|
|
@ -112,7 +112,7 @@ def set_keychain(journal_name, password):
|
|||
def yesno(prompt, default=True):
|
||||
prompt = f"{prompt.strip()} {'[Y/n]' if default else '[y/N]'} "
|
||||
response = input(prompt)
|
||||
return {"y": True, "n": False}.get(response.lower(), default)
|
||||
return {"y": True, "n": False}.get(response.lower().strip(), default)
|
||||
|
||||
|
||||
def load_config(config_path):
|
||||
|
|
Loading…
Add table
Reference in a new issue