Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep newlines in the text formatter #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
29 changes: 21 additions & 8 deletions phpreport-report
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ from phpreport import TaskFilter
import argparse
import datetime
import multiprocessing
import os
import re
import textwrap
import sys
Expand Down Expand Up @@ -330,11 +331,20 @@ class DetailedReport(Report):

all_stories = [get_story(task) + task.text for task in tasks_for_day]

# Many times people add a lot of duplicate descriptions. Just output one of each.
all_stories = set(all_stories)
# Many times people add a lot of duplicate descriptions. Just output
# one of each, keeping the stories ordering
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: "keeping the stories ordering" should probably read "keeping the stories in the same order."

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, this seems like a separate change. Do you mind opening up a PR just for this? I'd like to commit it apart from preserving the newlines.

all_stories = list(dict.fromkeys(all_stories))

# Strip out duplicated whitespace
return re.compile(r'\s+').sub(' ', " ".join(all_stories)).strip()
def strip_whitespace(line):
return re.compile(r'\s+').sub(' ', line)
stripped_stories = []
for story in all_stories:
stripped = [strip_whitespace(line) for line in story.splitlines()
if line.strip() != '']
stripped_stories.append(os.linesep.join(stripped))

return os.linesep.join(stripped_stories)

def generate_stories_for_user(self, user):
self.formatter.generate_section_header("Stories for %s" % user.login)
Expand Down Expand Up @@ -385,11 +395,14 @@ class TextFormatter(object):
indent = (first_column_size + 2) * ' ' # Enough to account for the day name offset.
width = 80 - len(indent)
for content in contents:
second_column = textwrap.fill(content[1],
break_long_words=False, # Don't break URLs.
width=width,
initial_indent=indent,
subsequent_indent=indent).strip()
second_column = os.linesep.join(
[textwrap.fill(line,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand what is going on here. Are you wrapping each individual line? Is each line really a paragraph?

break_long_words=False, # Don't break URLs.
replace_whitespace=False, # Already done. Don't remove newlines
width=width,
initial_indent=indent,
subsequent_indent=indent)
for line in content[1].splitlines()]).strip()
self.pieces.append(format_string % (content[0], second_column))

def generate_header(self, header):
Expand Down