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

implement feature "Support custom colours" #197

Merged
merged 12 commits into from
Aug 22, 2017
Merged

Conversation

shv-q3
Copy link
Contributor

@shv-q3 shv-q3 commented Aug 18, 2017

  • used idea from googler project to add custom colors support

  • imported collections and used named tuple to store users colors from
    "COLORMAP" which is identical with googler's project

  • separated vars in print_single_rec so color can be changed
    separately for each item: id and title, url, desc, tag

  • add function to check for valid color strings and return error
    msg if string is invalid

  • add check for os env defaults for colors that should be stored in $env:BUKU_COLORS

  • in args.colorstr ID_DB_str, URL_str, DESC_str, TAG_str
    removes default colors and set users colors

  • updated man pages for colors option

  • updated auto-completions

  • updated README file under section "Usage"

shv-q3 added 4 commits August 18, 2017 17:43
# imported collections module for named tuple
# add "colormap" from googler project
# add named tuple for id and title, url, desc, tag
# adjusted print_single_rec so colors can be changed for each item
# add valid color string checker from googler
# adjusted man options
# add autocompletions
# sorted import in alphabetical order
# adjusted var name's
# add colors table to man file
# add color os ENV option
# add --color documentation in README under "Usage"
@@ -26,6 +26,7 @@ _buku () {
-k --unlock
-l --lock
-m --merge
--colors
Copy link
Owner

Choose a reason for hiding this comment

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

The options are in alphabetical order. Same for all the completion scripts.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as well as all completion scripts.

buku.1 Outdated
@@ -218,6 +218,9 @@ Show selective monochrome output with specific fields. Works with --print. Searc
.BI \-j " " \--json
Output data formatted as json, works with --print output and search results.
.TP
.BI "--colors=" COLORS
Copy link
Owner

Choose a reason for hiding this comment

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

Please use the following syntax like it's for other options in this man page:

.BI \--colors " COLORS"

buku.1 Outdated
.TE
.TP
.TP
The default colors string is \fIGKlg\fR, which stands for
Copy link
Owner

@jarun jarun Aug 19, 2017

Choose a reason for hiding this comment

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

This looks awful. See my comment on line 3306 for more details.

buku.py Outdated
DESC_str = '%s + %s\n'
TAG_str = '%s # %s\n'
colors = Colors(*[COLORMAP[c] for c in args.colorstr], reset=COLORMAP['x'])
ID_DB_str = colors.ID_DB_str + ID_DB_str + COLORMAP['x']
Copy link
Owner

Choose a reason for hiding this comment

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

The color for ID+title reflects in buku -p but not for the search results. Please fix.

Copy link
Owner

Choose a reason for hiding this comment

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

I think you have not used ID_str. That's the problem.

Copy link
Owner

Choose a reason for hiding this comment

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

Can we have something similar to googler?
ID - bold cyan (G)
Title - bold bright green (K)
DB Index (within []) - \x1b[2m (keep it hardcoded to dim)
URL - bright yellow (l)
comments/notes/desc - normal (x)
tags - blue (e)

Testing: Add a bookmark with url, title, tags and comment. Then

  1. print it
  2. search for it

to ensure your changes are good.

buku.py Outdated
@@ -3216,6 +3249,8 @@ def main():
addarg('-p', '--print', nargs='*', help=HIDE)
addarg('-f', '--format', type=int, default=0, choices={1, 2, 3, 4}, help=HIDE)
addarg('-j', '--json', action='store_true', help=HIDE)
addarg('--colors', dest='colorstr', type=argparser.is_colorstr,
default=colorstr_env if colorstr_env else 'GKlg', metavar='COLORS', help=HIDE)
Copy link
Owner

@jarun jarun Aug 19, 2017

Choose a reason for hiding this comment

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

Please change. See my comment on line 3306 for more details.

buku.py Outdated
DESC_str = '%s + %s\n'
TAG_str = '%s # %s\n'
colors = Colors(*[COLORMAP[c] for c in args.colorstr], reset=COLORMAP['x'])
ID_DB_str = colors.ID_DB_str + ID_DB_str + COLORMAP['x']
Copy link
Owner

Choose a reason for hiding this comment

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

I think you have not used ID_str. That's the problem.

buku.py Outdated
DESC_str = '%s + %s\n'
TAG_str = '%s # %s\n'
colors = Colors(*[COLORMAP[c] for c in args.colorstr], reset=COLORMAP['x'])
ID_DB_str = colors.ID_DB_str + ID_DB_str + COLORMAP['x']
Copy link
Owner

Choose a reason for hiding this comment

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

Can we have something similar to googler?
ID - bold cyan (G)
Title - bold bright green (K)
DB Index (within []) - \x1b[2m (keep it hardcoded to dim)
URL - bright yellow (l)
comments/notes/desc - normal (x)
tags - blue (e)

Testing: Add a bookmark with url, title, tags and comment. Then

  1. print it
  2. search for it

to ensure your changes are good.

@jarun
Copy link
Owner

jarun commented Aug 19, 2017

Please go through my comments and make the changes accordingly. This is a VERY important feature. Anything odd in default colors can put off all the users and kill the utility.

@jarun
Copy link
Owner

jarun commented Aug 19, 2017

@ALL I would love to keep the defaults similar to googler but am open to suggestions. I would like everyone to review this PR.

README.md Outdated
@@ -206,6 +206,7 @@ POWER TOYS:
N=1: URL, N=2: URL and tag, N=3: title,
N=4: URL, title and tag
-j, --json Json formatted output for -p and search
--colors set output colors (see man page for details)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd make mention of this feature under the Features section as well.

Copy link
Owner

Choose a reason for hiding this comment

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

It has to go in 2 places under features: README and man page.

Copy link
Contributor

Choose a reason for hiding this comment

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

Additions to the examples in both the README and man page may be helpful as well.

Copy link
Owner

@jarun jarun Aug 22, 2017

Choose a reason for hiding this comment

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

Please remove (see man page for details).

Copy link
Contributor

@professorjamesmoriarty professorjamesmoriarty left a comment

Choose a reason for hiding this comment

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

Aside from my comment with regards to Features section addition. I love this.

buku.1 Outdated
@@ -336,6 +339,75 @@ http[s]://[username:password@]proxyhost:proxyport/
can be integrated in a GUI environment with simple tweaks. Refer to:
.br
.I https://github.com/jarun/Buku#gui-integration
.SH COLORS
\buku\fR allows you to customize the color scheme via a four-letter string, reminiscent of BSD \fBLSCOLORS\fR. The four letters represent the colors of
Copy link
Contributor

Choose a reason for hiding this comment

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

\buku\fR should be \fBBuku\fR, I think. It currently displays as k.

buku.py Outdated
DESC_str = colors.DESC_str + DESC_str + COLORMAP['x']
TAG_str = colors.TAG_str + TAG_str + COLORMAP['x']
else:
print('no')
Copy link
Contributor

@mosegontar mosegontar Aug 20, 2017

Choose a reason for hiding this comment

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

Perhaps this should be a more explicit message? I'm not sure of the case that would trigger this, though. It seems like it might not be needed, since args.colorstr has a default value.

Copy link
Collaborator

Choose a reason for hiding this comment

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

at least minimal debug msg

buku.py Outdated
for c in arg:
assert c in COLORMAP
except AssertionError:
raise argparse.ArgumentTypeError('%s is not a valid color string' % arg)
Copy link
Contributor

Choose a reason for hiding this comment

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

If an invalid color string is set as the env variable (e.g., ixejJ), the raised error message is buku.py: error: argument --colors: ixejJ is not a valid color string. Maybe not a problem, but this might be confusing since --colors is not used in that case by the user.

Copy link
Owner

Choose a reason for hiding this comment

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

Please change it to ixejJ is not a valid color string.

Copy link
Contributor

@mosegontar mosegontar left a comment

Choose a reason for hiding this comment

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

I like this feature a lot. I made some suggestions, but the only imperative one on my end would be the typo in the man page.

@rachmadaniHaryono
Copy link
Collaborator

simple test would be helpful for is_colorstr would be helpful for maintenance.

Copy link
Collaborator

@rachmadaniHaryono rachmadaniHaryono left a comment

Choose a reason for hiding this comment

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

need test on is_colorstr

shv-q3 added 4 commits August 22, 2017 01:36
--color reordered in alphabetical order
--color reordered in alphabetical order
--color reordered in alphabetical order
@@ -6,6 +6,7 @@
#
complete -c buku -s a -l add -r --description 'add bookmark'
complete -c buku -l ai --description 'auto-import bookmarks'
complete -c buku -l colors --description 'set output colors (see man page for details)'
Copy link
Owner

Choose a reason for hiding this comment

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

This takes an arg. Add -r.

Copy link
Owner

@jarun jarun Aug 22, 2017

Choose a reason for hiding this comment

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

Please remove (see man page for details).

@@ -11,6 +11,7 @@ local -a args
args=(
'(-a --add)'{-a,--add}'[add bookmark]:URL tags'
'(--ai)--ai[auto-import bookmarks]'
'(--colors)--colors[set output colors (see man page for details)]'
Copy link
Owner

Choose a reason for hiding this comment

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

Please change to:

'(--colors)--colors[set output colors]:color string'

Copy link
Owner

Choose a reason for hiding this comment

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

Please remove (see man page for details).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

@@ -13,6 +13,7 @@ _buku () {
opts=(
-a --add
--ai
--colors
Copy link
Owner

Choose a reason for hiding this comment

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

This should also go into the opts_with_arg group below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

add to opts_with_arg

README.md Outdated
@@ -206,6 +206,7 @@ POWER TOYS:
N=1: URL, N=2: URL and tag, N=3: title,
N=4: URL, title and tag
-j, --json Json formatted output for -p and search
--colors set output colors (see man page for details)
Copy link
Owner

@jarun jarun Aug 22, 2017

Choose a reason for hiding this comment

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

Please remove (see man page for details).

@@ -6,6 +6,7 @@
#
complete -c buku -s a -l add -r --description 'add bookmark'
complete -c buku -l ai --description 'auto-import bookmarks'
complete -c buku -l colors --description 'set output colors (see man page for details)'
Copy link
Owner

@jarun jarun Aug 22, 2017

Choose a reason for hiding this comment

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

Please remove (see man page for details).

@@ -11,6 +11,7 @@ local -a args
args=(
'(-a --add)'{-a,--add}'[add bookmark]:URL tags'
'(--ai)--ai[auto-import bookmarks]'
'(--colors)--colors[set output colors (see man page for details)]'
Copy link
Owner

Choose a reason for hiding this comment

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

Please remove (see man page for details).

buku.py Outdated
@@ -3193,6 +3225,7 @@ def main():
N=1: URL, N=2: URL and tag, N=3: title,
N=4: URL, title and tag
-j, --json Json formatted output for -p and search
--colors set output colors (see man page for details)
Copy link
Owner

Choose a reason for hiding this comment

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

Please remove (see man page for details).

shv-q3 added 2 commits August 22, 2017 20:34
# separated id from ID_str and ID_DB_STR so it can have separate color
# add 5 string color for (id, title, url, desc, tag)
# adjusted print_single_rec for 5 colors result
# fixed syntax .BI \--colors " COLORS" in man page
# replaced four with five letter string for color
# fixed default colors to "GKlxe" and "\x1b[2m" for DB index
# add example to README and man page
# removed check for colorstr_env set by user for the moment
README.md Outdated
@@ -192,6 +193,7 @@ ENCRYPTION OPTIONS:

POWER TOYS:
--ai auto-import from Firefox and Chrome
--colors set output colors
Copy link
Owner

Choose a reason for hiding this comment

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

For help, this was in the right position (just above --nc). My comment was only for the auto-complete scripts.

Also, please change it to:

--colors COLORS set output colors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

misunderstanding no problem

Copy link
Owner

Choose a reason for hiding this comment

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

Sure! Please take your time. This is a big PR, so nothing to hurry about.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Corrected

buku.py Outdated
@@ -3211,6 +3222,7 @@ def main():
power_grp = argparser.add_argument_group(
title='POWER TOYS',
description=''' --ai auto-import from Firefox and Chrome
--colors set output colors
Copy link
Owner

Choose a reason for hiding this comment

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

--colors COLORS set output colors

and please move it back to just before --nc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Corrected

buku.1 Outdated
@@ -340,19 +341,21 @@ can be integrated in a GUI environment with simple tweaks. Refer to:
.br
.I https://github.com/jarun/Buku#gui-integration
.SH COLORS
\buku\fR allows you to customize the color scheme via a four-letter string, reminiscent of BSD \fBLSCOLORS\fR. The four letters represent the colors of
\fBBuku\fR allows you to customize the color scheme via a five-letter string, reminiscent of BSD \fBLSCOLORS\fR. The five letters represent the colors of
Copy link
Owner

Choose a reason for hiding this comment

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

Please change the name to buku i.e., starting with lowercase char.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Corrected

@@ -6,7 +6,7 @@
#
complete -c buku -s a -l add -r --description 'add bookmark'
complete -c buku -l ai --description 'auto-import bookmarks'
complete -c buku -l colors --description 'set output colors (see man page for details)'
complete -c buku -l colors --description 'set output colors'
Copy link
Owner

Choose a reason for hiding this comment

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

Please change to:

complete -c buku -l colors -r --description 'set output colors'

The -r stands for required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Corrected

README.md Outdated
@@ -66,6 +66,7 @@ PRs are welcome. Please visit [#174](https://github.com/jarun/Buku/issues/174) f
- Portable, merge-able database to sync between systems
- Multithreaded full DB refresh
- Shell completion scripts, man page with handy examples
- Colored output
Copy link
Owner

Choose a reason for hiding this comment

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

Please move it to the top point:

Lightweight, clean interface, custom colors

And add this in the man page too (we show the features in man page as well)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Corrected

@jarun
Copy link
Owner

jarun commented Aug 22, 2017

Also, flake8 check in Travis is failing due to some very long line. Please fix.

buku.1 Outdated
@@ -182,6 +183,9 @@ Decrypt (unlock) the DB file with
.BI \--ai
Auto-import bookmarks from Firefox and Google Chrome.
.TP
.BI \--colors " COLORS"
Copy link
Owner

Choose a reason for hiding this comment

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

Please move this to above --nc

@shv-q3
Copy link
Contributor Author

shv-q3 commented Aug 22, 2017

there is only 1 issue I found with the colors, when u search with -t option and don't put any args it displays the amount of bookmarks without color

buku.py Outdated
@@ -48,12 +49,27 @@
colorize = True # Allow color output by default

# Default colour to print records
ID_str = '\x1b[96;1m%d. \x1b[1;92m%s\x1b[0;2m [%s]\x1b[0m\n'
ID_DB_str = '\x1b[96;1m%d. \x1b[1;92m%s\x1b[0m'
ID_srch = '\x1b[36m%d.\x1b[0m'
Copy link
Owner

Choose a reason for hiding this comment

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

The space after . is missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Corrected

buku.py Outdated
ID_str = '\x1b[96;1m%d. \x1b[1;92m%s\x1b[0;2m [%s]\x1b[0m\n'
ID_DB_str = '\x1b[96;1m%d. \x1b[1;92m%s\x1b[0m'
ID_srch = '\x1b[36m%d.\x1b[0m'
ID_str = ID_srch + '\x1b[1;92m%s\x1b[2m [%s]\x1b[0m\n'
Copy link
Owner

Choose a reason for hiding this comment

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

The DB ID is not showing in dim. In

2.GitHub - mewrev/dissection: The dissection of a simple "hello world" ELF binary. [305]

The [305] at the end is the DB id. It is shown in search results. You have to use \x1b[0;2m

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Corrected

README.md Outdated
@@ -66,7 +66,7 @@ PRs are welcome. Please visit [#174](https://github.com/jarun/Buku/issues/174) f
- Portable, merge-able database to sync between systems
- Multithreaded full DB refresh
- Shell completion scripts, man page with handy examples
- Colored output
- Lightweight, clean interface, custom colors
Copy link
Owner

Choose a reason for hiding this comment

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

Lightweight, clean interface is already at the top of the feature list. Please append custom colors to it instead of a new entry at the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah :) did not sleep yes i guess ok np

Copy link
Contributor Author

Choose a reason for hiding this comment

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

corrected in both files

@@ -208,6 +207,7 @@ POWER TOYS:
N=1: URL, N=2: URL and tag, N=3: title,
N=4: URL, title and tag
-j, --json Json formatted output for -p and search
--colors --colors COLORS set output colors
Copy link
Owner

Choose a reason for hiding this comment

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

Please check googler's help on --colors and copy it verbatim.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well googler's is:
--colors COLORS set output colors (see man page for details)
do you what to use this one?

Copy link
Owner

Choose a reason for hiding this comment

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

OK. In that case just use whatever is there in googler.

buku.1 Outdated
@@ -23,7 +23,7 @@ is a command-line utility to store, tag, search and organize bookmarks.
* Portable, merge-able database to sync between systems
* Multithreaded full DB refresh
* Shell completion scripts, man page with handy examples
* Colored output
* Lightweight, clean interface, custom colors
Copy link
Owner

Choose a reason for hiding this comment

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

Should be the topmost line.

buku.py Outdated
@@ -3237,6 +3236,7 @@ def main():
N=1: URL, N=2: URL and tag, N=3: title,
N=4: URL, title and tag
-j, --json Json formatted output for -p and search
--colors --colors COLORS set output colors
Copy link
Owner

Choose a reason for hiding this comment

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

???

@jarun jarun merged commit 9dcbd67 into jarun:master Aug 22, 2017
@jarun
Copy link
Owner

jarun commented Aug 22, 2017

I'll take care of the rest of the changes. Thanks!

@github-actions github-actions bot locked and limited conversation to collaborators Jun 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants