mirror of
https://github.com/natelandau/obsidian-metadata.git
synced 2025-11-18 18:03:39 -05:00
refactor: use single console instance
This commit is contained in:
@@ -5,12 +5,12 @@ from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import questionary
|
||||
from rich import box, print
|
||||
from rich.console import Console
|
||||
from rich import box
|
||||
from rich.table import Table
|
||||
|
||||
from obsidian_metadata._config import VaultConfig
|
||||
from obsidian_metadata._utils import alerts
|
||||
from obsidian_metadata._utils.console import console
|
||||
from obsidian_metadata.models import Vault, VaultFilter
|
||||
from obsidian_metadata.models.enums import MetadataType
|
||||
from obsidian_metadata.models.questions import Questions
|
||||
@@ -71,7 +71,7 @@ class Application:
|
||||
case _:
|
||||
break
|
||||
|
||||
print("Done!")
|
||||
console.print("Done!")
|
||||
return
|
||||
|
||||
def application_add_metadata(self) -> None:
|
||||
@@ -218,7 +218,7 @@ class Application:
|
||||
alerts.notice("No filters have been applied")
|
||||
return
|
||||
|
||||
print("")
|
||||
console.print("")
|
||||
table = Table(
|
||||
"Opt",
|
||||
"Filter",
|
||||
@@ -254,7 +254,7 @@ class Application:
|
||||
)
|
||||
table.add_row(f"{len(self.filters) + 1}", "Clear All")
|
||||
table.add_row(f"{len(self.filters) + 2}", "Return to Main Menu")
|
||||
Console().print(table)
|
||||
console.print(table)
|
||||
|
||||
num = self.questions.ask_number(
|
||||
question="Enter the number of the filter to clear"
|
||||
@@ -297,25 +297,25 @@ class Application:
|
||||
while True:
|
||||
match self.questions.ask_selection(choices=choices, question="Select a vault action"):
|
||||
case "all_metadata":
|
||||
print("")
|
||||
console.print("")
|
||||
self.vault.metadata.print_metadata(area=MetadataType.ALL)
|
||||
print("")
|
||||
console.print("")
|
||||
case "all_frontmatter":
|
||||
print("")
|
||||
console.print("")
|
||||
self.vault.metadata.print_metadata(area=MetadataType.FRONTMATTER)
|
||||
print("")
|
||||
console.print("")
|
||||
case "all_inline":
|
||||
print("")
|
||||
console.print("")
|
||||
self.vault.metadata.print_metadata(area=MetadataType.INLINE)
|
||||
print("")
|
||||
console.print("")
|
||||
case "all_keys":
|
||||
print("")
|
||||
console.print("")
|
||||
self.vault.metadata.print_metadata(area=MetadataType.KEYS)
|
||||
print("")
|
||||
console.print("")
|
||||
case "all_tags":
|
||||
print("")
|
||||
console.print("")
|
||||
self.vault.metadata.print_metadata(area=MetadataType.TAGS)
|
||||
print("")
|
||||
console.print("")
|
||||
case "export_csv":
|
||||
path = self.questions.ask_path(question="Enter a path for the CSV file")
|
||||
if path is None:
|
||||
@@ -378,7 +378,7 @@ class Application:
|
||||
changed_notes = self.vault.get_changed_notes()
|
||||
|
||||
if len(changed_notes) == 0:
|
||||
print("\n")
|
||||
console.print("\n")
|
||||
alerts.notice("No changes to commit.\n")
|
||||
return False
|
||||
|
||||
|
||||
@@ -4,9 +4,7 @@ import copy
|
||||
import re
|
||||
from io import StringIO
|
||||
|
||||
from rich import print
|
||||
from rich.columns import Columns
|
||||
from rich.console import Console
|
||||
from rich.table import Table
|
||||
from ruamel.yaml import YAML
|
||||
|
||||
@@ -17,6 +15,7 @@ from obsidian_metadata._utils import (
|
||||
merge_dictionaries,
|
||||
remove_markdown_sections,
|
||||
)
|
||||
from obsidian_metadata._utils.console import console
|
||||
from obsidian_metadata.models import Patterns # isort: ignore
|
||||
from obsidian_metadata.models.enums import MetadataType
|
||||
|
||||
@@ -172,7 +171,7 @@ class VaultMetadata:
|
||||
"\n".join(sorted(value)) if isinstance(value, list) else value
|
||||
)
|
||||
table.add_row(f"[bold]{key}[/]", str(values))
|
||||
Console().print(table)
|
||||
console.print(table)
|
||||
|
||||
if list_to_print is not None:
|
||||
columns = Columns(
|
||||
@@ -181,7 +180,7 @@ class VaultMetadata:
|
||||
expand=True,
|
||||
title=header if area != MetadataType.ALL else "All inline tags",
|
||||
)
|
||||
print(columns)
|
||||
console.print(columns)
|
||||
|
||||
def rename(self, key: str, value_1: str, value_2: str = None) -> bool:
|
||||
"""Replace a value in the frontmatter.
|
||||
|
||||
@@ -8,11 +8,11 @@ from pathlib import Path
|
||||
|
||||
import rich.repr
|
||||
import typer
|
||||
from rich.console import Console
|
||||
from rich.table import Table
|
||||
|
||||
from obsidian_metadata._utils import alerts
|
||||
from obsidian_metadata._utils.alerts import logger as log
|
||||
from obsidian_metadata._utils.console import console
|
||||
from obsidian_metadata.models import (
|
||||
Frontmatter,
|
||||
InlineMetadata,
|
||||
@@ -355,7 +355,7 @@ class Note:
|
||||
|
||||
def print_note(self) -> None:
|
||||
"""Print the note to the console."""
|
||||
print(self.file_content)
|
||||
console.print(self.file_content)
|
||||
|
||||
def print_diff(self) -> None:
|
||||
"""Print a diff of the note's original state and it's new state."""
|
||||
@@ -372,7 +372,7 @@ class Note:
|
||||
elif line.startswith("-"):
|
||||
table.add_row(line, style="red")
|
||||
|
||||
Console().print(table)
|
||||
console.print(table)
|
||||
|
||||
def rename_inline_tag(self, tag_1: str, tag_2: str) -> bool:
|
||||
"""Rename an inline tag from the note ONLY if it's not in the metadata as well.
|
||||
|
||||
@@ -9,7 +9,6 @@ from pathlib import Path
|
||||
|
||||
import rich.repr
|
||||
from rich import box
|
||||
from rich.console import Console
|
||||
from rich.progress import Progress, SpinnerColumn, TextColumn
|
||||
from rich.prompt import Confirm
|
||||
from rich.table import Table
|
||||
@@ -17,6 +16,7 @@ from rich.table import Table
|
||||
from obsidian_metadata._config.config import VaultConfig
|
||||
from obsidian_metadata._utils import alerts
|
||||
from obsidian_metadata._utils.alerts import logger as log
|
||||
from obsidian_metadata._utils.console import console
|
||||
from obsidian_metadata.models import InsertLocation, MetadataType, Note, VaultMetadata
|
||||
|
||||
|
||||
@@ -202,7 +202,7 @@ class Vault:
|
||||
log.debug("Backing up vault")
|
||||
if self.dry_run:
|
||||
alerts.dryrun(f"Backup up vault to: {self.backup_path}")
|
||||
print("\n")
|
||||
console.print("\n")
|
||||
return
|
||||
|
||||
try:
|
||||
@@ -357,14 +357,14 @@ class Vault:
|
||||
table.add_row("Active filters", str(len(self.filters)))
|
||||
table.add_row("Notes with changes", str(len(self.get_changed_notes())))
|
||||
|
||||
Console().print(table)
|
||||
console.print(table)
|
||||
|
||||
def list_editable_notes(self) -> None:
|
||||
"""Print a list of notes within the scope that are being edited."""
|
||||
table = Table(title="Notes in current scope", show_header=False, box=box.HORIZONTALS)
|
||||
for _n, _note in enumerate(self.notes_in_scope, start=1):
|
||||
table.add_row(str(_n), str(_note.note_path.relative_to(self.vault_path)))
|
||||
Console().print(table)
|
||||
console.print(table)
|
||||
|
||||
def num_excluded_notes(self) -> int:
|
||||
"""Count number of excluded notes."""
|
||||
|
||||
Reference in New Issue
Block a user