From c4250e9341654acea7c563c54f9462de961f13ad Mon Sep 17 00:00:00 2001 From: shv-q3 Date: Fri, 18 Aug 2017 16:07:38 +0200 Subject: [PATCH] Hotfix - implement "Support custom colours" from (#174) # 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" --- README.md | 1 + auto-completion/fish/buku.fish | 2 +- auto-completion/zsh/_buku | 2 +- buku.1 | 69 ++++++++++++++++++++++++++++++++++ buku.py | 31 +++++++-------- 5 files changed, 88 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 7e930d5f..35f90d10 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/auto-completion/fish/buku.fish b/auto-completion/fish/buku.fish index 6389dd16..803ad3eb 100644 --- a/auto-completion/fish/buku.fish +++ b/auto-completion/fish/buku.fish @@ -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' diff --git a/auto-completion/zsh/_buku b/auto-completion/zsh/_buku index 98dd583b..e280add0 100644 --- a/auto-completion/zsh/_buku +++ b/auto-completion/zsh/_buku @@ -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]' diff --git a/buku.1 b/buku.1 index 878ca977..9bb316af 100644 --- a/buku.1 +++ b/buku.1 @@ -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 diff --git a/buku.py b/buku.py index 895f0bfb..068aa8f7 100755 --- a/buku.py +++ b/buku.py @@ -18,6 +18,7 @@ # along with Buku. If not, see . import argparse +import collections import html.parser as HTMLParser import json import logging @@ -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 ' @@ -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 @@ -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) @@ -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 @@ -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)