feat: add --plain option to the show command in order to render notes as plaintext

This commit is contained in:
cătălin 2023-11-28 13:49:13 +01:00
commit af9a6d82f4
Signed by: catalin
GPG key ID: 686088EF78EE4083
14 changed files with 318 additions and 473 deletions

View file

@ -1,5 +1,6 @@
from pathlib import Path
from rich import print
from rich.console import Console
from rich.markdown import Markdown
@ -10,11 +11,12 @@ from halig.settings import Settings
class ShowCommand(BaseCommand):
def __init__(self, note_path: Path, settings: Settings):
def __init__(self, note_path: Path, settings: Settings, plain: bool = False):
super().__init__(settings)
self.note_path = self.settings.notebooks_root_path / note_path
self.encryptor = Encryptor(self.settings)
self.plain = plain
self.console = Console()
if self.note_path.is_dir():
self.note_path /= f"{utils.now().date()}.age"
@ -33,5 +35,9 @@ class ShowCommand(BaseCommand):
return self.encryptor.decrypt(data).decode()
def run(self): # pragma: no cover
md_contents = Markdown(self.decrypt())
contents = self.decrypt()
if self.plain:
print(contents)
return
md_contents = Markdown(contents)
self.console.print(md_contents)