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

Coloured log output #176

Merged
merged 4 commits into from
Dec 13, 2017
Merged

Conversation

MinchinWeb
Copy link
Contributor

At least on Windows click.echo_through_pager() seems to eat the ANSI colour codes. This PR "fixes" that by allowing the pager to be bypassed and use the "regular" click.echo() (which displays colour codes fine). It does this by adding a --pager/--no-pager option to the log sub-command, and a corresponding options.log_pager configuration setting.

image

It also makes a couple other small changes:

  • requires/includes PR Fix setup.py #175 (I can't install watson otherwise...)
  • changes the formatting slightly of the log's daily heading to better match other output
  • removes an extra space that is displayed several places is a frame has no corresponding tags.

An issue has been submitted upstream to click (see pallets/click#901) but this seems like a practical work-around.

Also, the main image on the first page of the documentation should be updated. It purportedly demonstrates the report sub-command, but the output looks like it's actually the log sub-command.

Thirdly, is there a comprehensive list of configuration file settings somewhere in the documentation?

Lastly, thanks for making watson; I'm super excited to have discovered it!

@SpotlightKid
Copy link
Contributor

Thirdly, is there a comprehensive list of configuration file settings somewhere in the documentation?

https://tailordev.github.io/Watson/user-guide/configuration/

@SpotlightKid
Copy link
Contributor

changes the formatting slightly of the log's daily heading to better match other output
removes an extra space that is displayed several places is a frame has no corresponding tags.

Can you please put these into a separate PR (they can go together)?

watson/cli.py Outdated
@@ -833,8 +835,8 @@ def remove(watson, id, force):

if not force:
click.confirm(
"You are about to remove frame "
"{project}{tags_spacer}{tags} from {start} to {stop}, continue?".format(
'You are about to remove frame {project}{tags_spacer}{tags} from '
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for your effort in unifying single/double quotes, but for messages shown to the user, which are (in theory) translatable, we prefer double quotes. This usage might not be consistent in the existing code, but for new code please adhere to this convention.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 903e75f (part of #179)

@SpotlightKid
Copy link
Contributor

Also, the main image on the first page of the documentation should be updated.

See #177.

@MinchinWeb
Copy link
Contributor Author

Ok, the other changes have been split off into separate PR's, and everything here just has to do with making the pager on the log output option. Documentation has also been added.

@SpotlightKid
Copy link
Contributor

I see that the output of the report command is currently not sent through a pager. I think we should do the same there as for the log command and use a config option name that fits for both, e.g. use_pager.

@SpotlightKid
Copy link
Contributor

docs/user-guide/commands.md also needs to be updated by running scripts/gen-cli-docs.py. You should also update the docstrings of the log and report functions and mention the new option.

Copy link
Contributor

@SpotlightKid SpotlightKid left a comment

Choose a reason for hiding this comment

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

Also please rebase on master.

watson/cli.py Outdated
@@ -529,9 +529,11 @@ def report(watson, current, from_, to, projects,
"times")
@click.option('-j', '--json', 'format_json', is_flag=True,
help="Format the log in JSON instead of plain text")
@click.option('--pager/--no-pager', 'pager', default=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

There should be a short form of the option too. I'm open to suggestions for the letters to use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

-v/-V (for 'view' maybe'?) it doesn't seem to be used elsewhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

-v is often used to mean verbose or version, so I don't think it's an ideal choice. How about -l/-L (mnemonic less, but it's rather arbitrary ;))?

watson/cli.py Outdated
click.echo_via_pager('\n'.join(lines))
if pager or (pager is None and
watson.config.getboolean('options', 'log_pager',
default=True)):
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need the default keyword arg name here. Saves you from needing another line break.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made the removal like you suggested, but it does change the default behaviour to now bypass the pager. I've added a note to the changelog to try and make this obvious.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I didn't make my self clear enough. I only meant:

if pager or (pager is None and
                watson.config.getboolean('options', 'log_pager', True)):

@MinchinWeb
Copy link
Contributor Author

Changes have been rebased onto master (and force-pushed here).

Pager selective support has been added to the report command. As a by-product of this, all the lines have to be gathered before they're printed, so this make make the command feel slower to some users.

The configuration option for both has been consolidated to options.pager.

Doc strings for both log and report have been updated. Documentation has also been updated using the script.

watson/cli.py Outdated
click.echo_via_pager('\n'.join(lines))
else:
click.echo('\n'.join(lines))

Copy link
Collaborator

@k4nar k4nar Dec 11, 2017

Choose a reason for hiding this comment

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

I think we should avoid buffering all the lines when in paging mode. The way to do it is not obvious, but maybe something like that would work:

lines = []

if pager or (...):
    def _print(line):
        lines.append(line)
else:
    def _print(line):
        click.echo(line)

...
_print('{project} - {time}'.format(...))
...

if pager or (...):
    click.echo('\n'.join(lines)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 046bf4e

includes documentation updates
`log` and `report` where waiting to gather all lines before deciding what to do with them (either pushing them to the terminal directly or through a pager). This change allows the lines to be gathered to the pager, or printed at once to the terminal, as desired.
@MinchinWeb
Copy link
Contributor Author

Lines are now printed in "real time" if printing is direct to the terminal, rather than waiting until end.

Copy link
Contributor

@SpotlightKid SpotlightKid left a comment

Choose a reason for hiding this comment

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

The comments on the 'reportfunction likewise apply to thelog` function.

@@ -127,6 +127,9 @@ You can also use special shortcut options for easier timespan control:
and `--year`, `--month` and `--week` to the current year, month or week
respectively.

If you are outputting to the terminal, you can selectively enable a pager
through the `--pager`` option.
Copy link
Contributor

Choose a reason for hiding this comment

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

Here's one backtick too many.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed!

@@ -174,6 +177,7 @@ Flag | Help
`-p, --project TEXT` | Logs activity only for the given project. You can add other projects by using this option several times.
`-T, --tag TEXT` | Logs activity only for frames containing the given tag. You can add several tags by using this option multiple times
`-j, --json` | Format the log in JSON instead of plain text
`-v, --pager / -V, --no-pager` | (Don't) view output through a pager.
Copy link
Contributor

Choose a reason for hiding this comment

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

Like I said, I'd rather use another letter for the short option than "v".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

g?

@@ -329,6 +333,9 @@ You can limit the report to a project or a tag using the `--project` and
`--tag` options. They can be specified several times each to add multiple
projects or tags to the report.

If you are outputting to the terminal, you can selectively enable a pager
through the `--pager`` option.
Copy link
Contributor

Choose a reason for hiding this comment

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

Here's one backtick too many.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed!

watson/cli.py Outdated
@@ -374,6 +376,9 @@ def report(watson, current, from_, to, projects,
`--tag` options. They can be specified several times each to add multiple
projects or tags to the report.

If you are outputting to the terminal, you can selectively enable a pager
through the `--pager`` option.
Copy link
Contributor

Choose a reason for hiding this comment

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

Here's the source of the extra backtick.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed!

watson/cli.py Outdated
lines = []
# use the pager, or print directly to the terminal
if pager or (pager is None and
watson.config.getboolean('options', 'pager')):
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be watson.config.getboolean('options', 'pager', True), no?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I'd line up this line with the second pager above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding 'True' maintains the current default (at least for log) of running output through the pager.

You had me remove this earlier because it was bumping it onto a second line, but the indentation is different now, so that's no longer an issue.

Both fixed!

Copy link
Contributor

@SpotlightKid SpotlightKid Dec 12, 2017

Choose a reason for hiding this comment

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

What I was trying to say all the time is that you don't need the argument name, i.e default=, not the argument value itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aaah, that makes more sense. Updated as recommended!

watson/cli.py Outdated
style('date', '{:ddd DD MMMM YYYY}'.format(
arrow.get(report['timespan']['from'])
use_pager = False
def _print(line):
Copy link
Contributor

Choose a reason for hiding this comment

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

There should be a blank line before inline function definitions (see also Travis log).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed!

watson/cli.py Outdated
style('date', '{:ddd DD MMMM YYYY}'.format(
arrow.get(report['timespan']['to'])
))
))
Copy link
Contributor

Choose a reason for hiding this comment

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

Line should be on the same indentation level as _print.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed!

@SpotlightKid
Copy link
Contributor

Regardless of this PR, I really think we should move the logging / reporting functionality into a separate command line script at some point.

@MinchinWeb
Copy link
Contributor Author

All changes as requested have been submitted.

Moving logging/report to a separate module is beyond what I set out to do here, so I'll leave it for a separate PR/refactoring effort.

@SpotlightKid SpotlightKid merged commit 6257e78 into jazzband:master Dec 13, 2017
@SpotlightKid
Copy link
Contributor

@MinchinWeb: Thanks for hanging in there. Great work!

@MinchinWeb MinchinWeb deleted the coloured-log-output branch December 14, 2017 00:03
@MinchinWeb
Copy link
Contributor Author

Thanks! Glad I can do my part to make the world a little nicer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants