Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/inkjet/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ def main(
config_app = typer.Typer(help="Manage configuration")
app.add_typer(config_app, name="config")

def decode_cli_escapes(value: str) -> str:
Comment thread
Gnado marked this conversation as resolved.
"""Decode common escaped whitespace without corrupting non-ASCII text."""
return (
value.replace("\\r\\n", "\n")
.replace("\\n", "\n")
.replace("\\t", "\t")
.replace("\\r", "\r")
.replace("\\\\", "\\")
)

def resolve_address(address: Optional[str]) -> Optional[str]:
"""Helper to resolve a UUID/MAC from config, alias, or direct input."""
config = load_config()
Expand Down Expand Up @@ -203,10 +213,7 @@ def print_text(
text = sys.stdin.read().strip()

# Apply escape character handling so \n becomes a real newline
try:
text = text.encode('utf-8').decode('unicode_escape')
except Exception:
pass
text = decode_cli_escapes(text)

if markdown:
image = render_markdown(
Expand Down Expand Up @@ -347,10 +354,7 @@ def print_file(
content = f.read().strip()

# Apply escape character handling
try:
content = content.encode('utf-8').decode('unicode_escape')
except Exception:
pass
content = decode_cli_escapes(content)

if path.endswith(".md"):
img = render_markdown(
Expand Down
Loading