Skip to content

fix(snippets): number terminal snippets from their first line - #637

Merged
Bachmann1234 merged 1 commit into
Bachmann1234:mainfrom
Eljees:fix/283-terminal-line-numbers
Sep 25, 2026
Merged

Bachmann1234 merged 1 commit into
Bachmann1234:mainfrom
Eljees:fix/283-terminal-line-numbers

Conversation

@Eljees

@Eljees Eljees commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Fixes #283.

--show-uncovered prints each snippet with line numbers, but in the terminal they always started at 0001, while the HTML and Markdown reports number the same snippet from its real first line. Snippet.terminal() passes linenostart to Pygments' TerminalFormatter, and that formatter ignores the option (it is only honoured by the HTML formatter). Checked with the current Pygments, 2.21.0:

>>> pygments.highlight("a = 1\nb = 2\n", PythonLexer(),
...     TerminalFormatter(linenos=True, colorscheme=None, linenostart=217))
'0001: a = 1\n0002: b = 2\n0003: \n'

This renders the snippet with TerminalFormatter but without line numbers, and adds them in terminal() in the same %04d: form, starting at the snippet's first line. The output is otherwise unchanged, including the trailing numbered empty line that show_uncovered_lines_console.txt expects, so the existing integration test passes as is.

Tests: test_terminal_numbers_lines_from_start_line builds a snippet that starts at line 217 and checks that its lines are 0217:, 0218:, 0219:. On main it fails:

AssertionError: assert ['0001: Line ...03: Line 219'] == ['0217: Line ...19: Line 219']

A second test pins the numbering for a snippet at the top of the file.

Full suite in a clean container: 389 passed with the change and 387 on main. The same 18 TestDiffQualityIntegration tests fail on both, because that environment does not have the quality tools (pylint, pyflakes and so on) installed.

Pygments' TerminalFormatter ignores linenostart, so --show-uncovered
printed every snippet as starting at line 1. Render without line numbers
and add them here, in the same 0001: form.

Fixes Bachmann1234#283
@Bachmann1234

Copy link
Copy Markdown
Owner

Thanks for the fix!

@Bachmann1234
Bachmann1234 merged commit a99a634 into Bachmann1234:main Sep 25, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The option --show-uncovered does not show the correct line numbers

2 participants