# HG changeset patch # User Brett Smith # Date 1238725867 14400 # Node ID f76ac41fe061813fc36c0b5e67d5238d50d3c080 # Parent ee9600dac90a365e0fa8746e55467e9d3322b5f4 Make sure prompts with filenames don't break mid-filename. diff -r ee9600dac90a -r f76ac41fe061 NEWS --- a/NEWS Wed Mar 25 22:58:57 2009 -0400 +++ b/NEWS Thu Apr 02 22:31:07 2009 -0400 @@ -12,8 +12,8 @@ instead of "rename the file." This wording has been fixed, along with some other wording adjustments in the prompts generally. - * Perform more reliable detection of the terminal size, and wrap more - prompts accordingly. + * Perform more reliable detection of the terminal size, and improve word + wrapping on prompts. Version 6.4 ----------- diff -r ee9600dac90a -r f76ac41fe061 scripts/dtrx --- a/scripts/dtrx Wed Mar 25 22:58:57 2009 -0400 +++ b/scripts/dtrx Thu Apr 02 22:31:07 2009 -0400 @@ -669,8 +669,8 @@ width = struct.unpack("HHHH", size)[1] except IOError: width = 80 - q_wrapper = textwrap.TextWrapper(width=width - 1, break_long_words=False) - choice_wrapper = textwrap.TextWrapper(width=width - 1, initial_indent=' * ', + width = width - 1 + choice_wrapper = textwrap.TextWrapper(width=width, initial_indent=' * ', subsequent_indent=' ', break_long_words=False) @@ -696,6 +696,19 @@ except KeyError: print + def wrap(self, question, *args): + words = question.split() + for arg in args: + words[words.index('%s')] = arg + result = [words.pop(0)] + for word in words: + extend = '%s %s' % (result[-1], word) + if len(extend) > self.width: + result.append(word) + else: + result[-1] = extend + return result + def __cmp__(self, other): return cmp(self.current_policy, other) @@ -726,9 +739,9 @@ raise ValueError("bad value %s for default policy" % (default,)) def prep(self, archive_filename, extractor): - question = self.q_wrapper.wrap( - "%s contains one %s, but its name doesn't match." % - (archive_filename, extractor.content_type)) + question = self.wrap( + "%s contains one %s but its name doesn't match.", + archive_filename, extractor.content_type) question.append(" Expected: " + extractor.basename()) question.append(" Actual: " + extractor.content_name) choice_vars = (extractor.content_type, extractor.basename()) @@ -763,9 +776,9 @@ if (self.permanent_policy is not None) or (archive_count == 0): self.current_policy = self.permanent_policy or RECURSE_NOT_NOW return - question = self.q_wrapper.wrap( - "%s contains %s other archive file(s), out of %s file(s) total." % - (current_filename, archive_count, extractor.file_count)) + question = self.wrap( + "%s contains %s other archive file(s), out of %s file(s) total.", + current_filename, archive_count, extractor.file_count) if target == '.': target = '' included_root = extractor.included_root