Skip to content

Commit

Permalink
Hotfix - implement "Support custom colours" from (jarun#174)
Browse files Browse the repository at this point in the history
# 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"
  • Loading branch information
shv-q3 committed Aug 18, 2017
1 parent d11ba83 commit c4250e9
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 17 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,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 set output colors (see man page for details)
--nc disable color output
--np do not show the prompt, run and exit
-o, --open [...] browse bookmarks by indices and ranges
Expand Down
2 changes: 1 addition & 1 deletion auto-completion/fish/buku.fish
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ complete -c buku -s j -l json --description 'show Json output for print an
complete -c buku -s k -l unlock --description 'decrypt database'
complete -c buku -s l -l lock --description 'encrypt database'
complete -c buku -s m -l merge -r --description 'merge another buku database'
complete -c buku -l colors --description 'custom color output'
complete -c buku -l colors --description 'set output colors (see man page for details)'
complete -c buku -l nc --description 'disable color output'
complete -c buku -l np --description 'non-interactive mode'
complete -c buku -s o -l open --description 'open bookmarks in browser'
Expand Down
2 changes: 1 addition & 1 deletion auto-completion/zsh/_buku
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ args=(
'(-k --unlock)'{-k,--unlock}'[decrypt database]'
'(-l --lock)'{-l,--lock}'[encrypt database]'
'(-m --merge)'{-m,--merge}'[merge another buku database]:buku db file'
'(--colors)--colors[custom color output]'
'(--colors)--colors[set output colors (see man page for details)]'
'(--nc)--nc[disable color output]'
'(--np)--np[noninteractive mode]'
'(-o --open)'{-o,--open}'[open bookmarks in browser]'
Expand Down
69 changes: 69 additions & 0 deletions buku.1
Original file line number Diff line number Diff line change
Expand Up @@ -339,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
\fBgoogler\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
.IP - 2
bookmark's id and title
.PD 0 \" Change paragraph spacing to 0 in the list
.IP - 2
bookmark's url
.IP - 2
bookmark's description
.IP - 2
bookmark's tag
.PD 1 \" Restore paragraph spacing
.TP
respectively. The four-letter string is passed in either as the argument to the \fB--colors\fR option, or as the value of the environment variable \fBBUKU_COLORS\fR.
.TP
We offer the following colors/styles:
.TS
tab(;) box;
l|l
-|-
l|l.
Letter;Color/Style
a;black
b;red
c;green
d;yellow
e;blue
f;magenta
g;cyan
h;white
i;bright black
j;bright red
k;bright green
l;bright yellow
m;bright blue
n;bright magenta
o;bright cyan
p;bright white
A-H;bold version of the lowercase-letter color
I-P;bold version of the lowercase-letter bright color
x;normal
X;bold
y;reverse video
Y;bold reverse video
.TE
.TP
.TP
The default colors string is \fIGKlg\fR, which stands for
.IP - 2
bold bright cyan index and title
.PD 0 \" Change paragraph spacing to 0 in the list
.IP - 2
bold bright green url
.IP - 2
bright yellow description
.IP - 2
cyan tag
.PD 1 \" Restore paragraph spacing
.TP
Note that
.IP - 2
Bright colors (implemented as \\x1b[90m - \\x1b[97m) may not be available in all color-capable terminal emulators;
.IP - 2
Some terminal emulators draw bold text in bright colors instead;
.IP - 2
Some terminal emulators only distinguish between bold and bright colors via a default-off switch.
.TP
Please consult the manual of your terminal emulator as well as \fIhttps://en.wikipedia.org/wiki/ANSI_escape_code\fR for details.

.SH EXAMPLES
.PP
.IP 1. 4
Expand Down
31 changes: 16 additions & 15 deletions buku.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# along with Buku. If not, see <http://www.gnu.org/licenses/>.

import argparse
import collections
import html.parser as HTMLParser
import json
import logging
Expand All @@ -36,7 +37,6 @@
import urllib3
from urllib3.util import parse_url, make_headers
import webbrowser
import collections

__version__ = '3.2'
__author__ = 'Arun Prakash Jana <[email protected]>'
Expand Down Expand Up @@ -2673,30 +2673,30 @@ def print_single_rec(row, idx=0): # NOQA

# Start with index and title
if idx != 0:
idandtitleresult = ID_str % (idx, row[2] if row[2] else 'Untitled', row[0])
id_title_res = ID_str % (idx, row[2] if row[2] else 'Untitled', row[0])
else:
idandtitleresult = ID_DB_str % (row[0], row[2] if row[2] else 'Untitled')
id_title_res = ID_DB_str % (row[0], row[2] if row[2] else 'Untitled')
# Indicate if record is immutable
if row[5] & 1:
idandtitleresult = MUTE_str % (idandtitleresult)
id_title_res = MUTE_str % (id_title_res)
else:
idandtitleresult += '\n'
id_title_res += '\n'

# Append URL
urlresult = ''
urlresult = URL_str % (urlresult, row[1])
url_res = ''
url_res = URL_str % (url_res, row[1])

# Append description
descresult = ''
desc_res = ''
if row[4]:
descresult = DESC_str % (descresult, row[4])
desc_res = DESC_str % (desc_res, row[4])

# Append tags IF not default (delimiter)
tagresult = ''
tag_res = ''
if row[3] != DELIM:
tagresult = TAG_str % (tagresult, row[3][1:-1])
tag_res = TAG_str % (tag_res, row[3][1:-1])

print(idandtitleresult + urlresult + descresult + tagresult)
print(id_title_res + url_res + desc_res + tag_res)

def format_json(resultset, single_record=False, field_filter=0):
'''Return results in Json format
Expand Down Expand Up @@ -3083,6 +3083,7 @@ def main():
tags_in = None
desc_in = None
pipeargs = []
colorstr_env = os.getenv('BUKU_COLORS')

try:
piped_input(sys.argv, pipeargs)
Expand Down Expand Up @@ -3224,8 +3225,8 @@ 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)
--nc disable color output
--colors set output colors (see man page for details
--np do not show the prompt, run and exit
-o, --open [...] browse bookmarks by indices and ranges
open a random bookmark, if no arguments
Expand All @@ -3248,9 +3249,9 @@ 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)
addarg('--nc', action='store_true', help=HIDE)
addarg('--colors', dest='colorstr', type=argparser.is_colorstr, metavar='COLORS',
help=HIDE)
addarg('--np', action='store_true', help=HIDE)
addarg('-o', '--open', nargs='*', help=HIDE)
addarg('--oa', action='store_true', help=HIDE)
Expand Down

0 comments on commit c4250e9

Please sign in to comment.