-
-
Notifications
You must be signed in to change notification settings - Fork 242
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
Coloured log output #176
Conversation
https://tailordev.github.io/Watson/user-guide/configuration/ |
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 ' |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #177. |
70f1245
to
c9ae6b6
Compare
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. |
I see that the output of the |
|
There was a problem hiding this 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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)):
c9ae6b6
to
ab7f3ed
Compare
Changes have been rebased onto master (and force-pushed here). Pager selective support has been added to the The configuration option for both has been consolidated to Doc strings for both |
watson/cli.py
Outdated
click.echo_via_pager('\n'.join(lines)) | ||
else: | ||
click.echo('\n'.join(lines)) | ||
|
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
ab7f3ed
to
046bf4e
Compare
Lines are now printed in "real time" if printing is direct to the terminal, rather than waiting until end. |
There was a problem hiding this 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 the
log` function.
docs/user-guide/commands.md
Outdated
@@ -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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!
docs/user-guide/commands.md
Outdated
@@ -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. |
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
g?
docs/user-guide/commands.md
Outdated
@@ -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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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')): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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']) | ||
)) | ||
)) |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed!
Regardless of this PR, I really think we should move the logging / reporting functionality into a separate command line script at some point. |
dd09f6f
to
e6aff65
Compare
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. |
e6aff65
to
a713ffa
Compare
@MinchinWeb: Thanks for hanging in there. Great work! |
Thanks! Glad I can do my part to make the world a little nicer! |
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 correspondingoptions.log_pager
configuration setting.It also makes a couple other small changes:
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!