Skip to content

Commit 979cea6

Browse files
author
Jochen Bauer
committed
Improve output in interactive mode
When in interactive mode, the file name and line number is now printed before the User is asked for confirmation. Also the filename color is applied in the `FIXED: ` printout. Fix #1925
1 parent 4ec53bf commit 979cea6

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

codespell_lib/_codespell.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,12 @@ def ask_for_word_fix(
791791
misspelling: Misspelling,
792792
interactivity: int,
793793
colors: TermColors,
794+
filename: str,
795+
lineno: int,
794796
) -> tuple[bool, str]:
797+
cfilename = f"{colors.FILE}{filename}{colors.DISABLE}"
798+
cline = f"{colors.FILE}{lineno}{colors.DISABLE}"
799+
795800
wrongword = match.group()
796801
if interactivity <= 0:
797802
return misspelling.fix, fix_case(wrongword, misspelling.data)
@@ -806,7 +811,11 @@ def ask_for_word_fix(
806811
r = ""
807812
fixword = fix_case(wrongword, misspelling.data)
808813
while not r:
809-
print(f"{line_ui}\t{wrongword} ==> {fixword} (Y/n) ", end="", flush=True)
814+
print(
815+
f"{cfilename}:{cline}: {line_ui}\t{wrongword} ==> {fixword} (Y/n) ",
816+
end="",
817+
flush=True,
818+
)
810819
r = sys.stdin.readline().strip().upper()
811820
if not r:
812821
r = "Y"
@@ -824,7 +833,10 @@ def ask_for_word_fix(
824833
r = ""
825834
opt = [w.strip() for w in misspelling.data.split(",")]
826835
while not r:
827-
print(f"{line_ui} Choose an option (blank for none): ", end="")
836+
print(
837+
f"{cfilename}:{cline}: {line_ui} Choose an option (blank for none): ",
838+
end="",
839+
)
828840
for i, o in enumerate(opt):
829841
fixword = fix_case(wrongword, o)
830842
print(f" {i}) {fixword}", end="")
@@ -1020,6 +1032,8 @@ def parse_lines(
10201032
misspellings[lword],
10211033
options.interactive,
10221034
colors=colors,
1035+
filename=filename,
1036+
lineno=i + 1,
10231037
)
10241038
asked_for.add(lword)
10251039

@@ -1192,7 +1206,8 @@ def parse_file(
11921206
else:
11931207
if not options.quiet_level & QuietLevels.FIXES:
11941208
print(
1195-
f"{colors.FWORD}FIXED:{colors.DISABLE} {filename}",
1209+
f"{colors.FWORD}FIXED:{colors.DISABLE} "
1210+
f"{colors.FILE}{filename}{colors.DISABLE}",
11961211
file=sys.stderr,
11971212
)
11981213
for line_num, wrong, right in changes_made:

0 commit comments

Comments
 (0)