Show and return words in the proper case in interactive mode.
diff --git a/codespell.py b/codespell.py index ace5ec0..2af1992 100755 --- a/codespell.py +++ b/codespell.py
@@ -183,15 +183,24 @@ return True +def fix_case(word, fixword): + if word == word.capitalize(): + return fixword.capitalize() + elif word == word.upper(): + return fixword.upper() + # they are both lower case + # or we don't have any idea + return fixword + def ask_for_word_fix(line, wrongword, misspelling, interactivity): if interactivity <= 0: - return misspelling.fix, misspelling.data + return misspelling.fix, fix_case(wrongword, misspelling.data) if misspelling.fix and interactivity & 1: r = '' + fixword = fix_case(wrongword, misspelling.data) while not r: - print("%s\t%s ==> %s (Y/n) " % (line, wrongword, - misspelling.data), end='') + print("%s\t%s ==> %s (Y/n) " % (line, wrongword, fixword), end='') r = sys.stdin.readline().strip().upper() if not r: r = 'Y' if r != 'Y' and r != 'N': @@ -211,7 +220,8 @@ while not r: print("%s Choose an option (blank for none): " % line, end='') for i in range(len(opt)): - print(" %d) %s" % (i, opt[i]), end='') + fixword = fix_case(wrongword, opt[i]) + print(" %d) %s" % (i, fixword), end='') print(": ", end='') sys.stdout.flush() @@ -229,7 +239,7 @@ misspelling.fix = True misspelling.data = r - return misspelling.fix, misspelling.data + return misspelling.fix, fix_case(wrongword, misspelling.data) def parse_file(filename, colors, summary): lines = None @@ -293,15 +303,7 @@ lword = word.lower() if lword in misspellings: fix = misspellings[lword].fix - - if word == word.capitalize(): - fixword = misspellings[lword].data.capitalize() - elif word == word.upper(): - fixword = misspellings[lword].data.upper() - else: - # even they are the same lower case or - # or we don't have any idea - fixword = misspellings[lword].data + fixword = fix_case(word, misspellings[lword].data) if options.interactive and not lword in fixed_words: fix, fixword = ask_for_word_fix(lines[i - 1], word,