Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ python3 -m pip install .
python3 scripts/demo.py
```

Install from this checkout to use the reviewed source version. The installed tool has no third-party runtime dependencies; cloning and installation can require network access.

## Features

### Choose your diff
Expand Down
10 changes: 7 additions & 3 deletions src/diffnote/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ def build_parser():
help="Print a GitHub PR-body markdown.")
fmt.add_argument("--json", action="store_true",
help="Print machine-readable JSON.")
fmt.add_argument("--no-color", action="store_true",
help="Disable ANSI colors.")
color = fmt.add_mutually_exclusive_group()
color.add_argument("--color", action="store_true", dest="use_color",
help="Force ANSI colors, even when output is redirected.")
color.add_argument("--no-color", action="store_false", dest="use_color",
help="Disable ANSI colors.")
p.set_defaults(use_color=None)
fmt.add_argument("--llm", action="store_true",
help="Enhance with a local Ollama model (needs Ollama running).")
return p
Expand Down Expand Up @@ -87,7 +91,7 @@ def main(argv=None):
elif args.markdown:
print(render.render_markdown(summary, llm_prose))
else:
print(render.render_terminal(summary, use_color=not args.no_color, llm_prose=llm_prose))
print(render.render_terminal(summary, use_color=args.use_color, llm_prose=llm_prose))
return 0


Expand Down
5 changes: 4 additions & 1 deletion src/diffnote/render.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Output renderers: terminal (ANSI), markdown (PR body), json."""

import json as _json
import sys

RESET = "\033[0m"
BOLD = "\033[1m"
Expand All @@ -16,7 +17,9 @@ def _c(text, code, use_color):
return f"{code}{text}{RESET}" if use_color else text


def render_terminal(summary, use_color=True, llm_prose=None):
def render_terminal(summary, use_color=None, llm_prose=None):
if use_color is None:
use_color = sys.stdout.isatty()
out = []
bar = "─" * 42
out.append(_c("diffnote", BOLD + CYAN, use_color) +
Expand Down
21 changes: 21 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import subprocess
import tempfile

import pytest

from diffnote import cli


Expand Down Expand Up @@ -58,6 +60,25 @@ def test_json_output(capsys):
assert "title" in data


@pytest.mark.parametrize("is_tty,args,has_color", [
(True, [], True),
(False, [], False),
(True, ["--color"], True),
(False, ["--color"], True),
(True, ["--no-color"], False),
(False, ["--no-color"], False),
])
def test_terminal_color_selection(capsys, monkeypatch, is_tty, args, has_color):
monkeypatch.chdir(_make_dirty_repo())
monkeypatch.setattr(cli.sys.stdout, "isatty", lambda: is_tty)

assert cli.main(args) == 0

out = capsys.readouterr().out
assert "files changed" in out
assert ("\033[" in out) is has_color


def test_markdown_output(capsys):
import os
d = _make_dirty_repo()
Expand Down