Skip to content

Commit c97d39b

Browse files
committed
Use ini format instead of json for colors configuration
1 parent fc2081b commit c97d39b

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

_wikicurses

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ _wikicurses_name() {
4242
_wikicurses() {
4343
_arguments -s : \
4444
{-h,--help}'[Display help message]'\
45+
'--dumpcolors[Write current color settings to config file]'\
4546
{-w,--wiki}'[Url or name of wiki to use]:wikis:_wikicurses_wiki'\
4647
{-f,--feed}'[Show featured articles (Wikipedia only)]:feeds:_wikicurses_feed'\
4748
'*:pages:_wikicurses_name'

src/wikicurses/main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import argparse
22
import urwid
3-
import json
43
import tempfile
54
import subprocess
65
import os
@@ -514,7 +513,8 @@ def main():
514513
print(*sugestions, sep='\n')
515514
return
516515
elif args.dumpcolors:
517-
print(json.dumps(settings.defcolors, indent=2))
516+
settings.dumpColors()
517+
print("Color settings written to " + settings.configpath + '/colors.')
518518
return
519519

520520
callback = lambda x, y: openPage(args.feed or args.search, bool(args.feed))

src/wikicurses/settings.py

+24-5
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,30 @@
2727
'h2': [['bold', 'underline'], '', ''],
2828
'h': [['bold', 'underline'], '', '']
2929
}
30-
colors = defcolors
31-
if os.path.exists(configpath + '/colors.json'):
32-
with open(configpath + '/colors.json') as file:
33-
# Use colors in colors.json, with defaults as fallbacks
34-
colors.insert(json.load(file))
30+
if os.path.exists(configpath + '/colors'):
31+
colorsconf = configparser.ConfigParser()
32+
colors = {}
33+
colorsconf.read(configpath + '/colors')
34+
for name, (defsettings, deffgcolor, defbgcolor) in defcolors.items():
35+
try:
36+
settings = colorsconf.get(name, 'settings').split()
37+
except (configparser.NoSectionError, configparser.NoOptionError):
38+
settings = defsettings
39+
fgcolor = colorsconf.get(name, 'fgcolor', fallback=deffgcolor)
40+
bgcolor = colorsconf.get(name, 'bgcolor', fallback=defbgcolor)
41+
colors[name] = [settings, fgcolor, bgcolor]
42+
else:
43+
colors = defcolors
44+
45+
def dumpColors():
46+
colorsconf = configparser.ConfigParser()
47+
for name, (settings, fgcolor, bgcolor) in colors.items():
48+
colorsconf.add_section(name)
49+
colorsconf.set(name, 'settings', ' '.join(settings))
50+
colorsconf.set(name, 'fgcolor', fgcolor)
51+
colorsconf.set(name, 'bgcolor', bgcolor)
52+
with open(configpath + '/colors', 'w') as file:
53+
colorsconf.write(file)
3554

3655
class Settings:
3756

wikicurses.1

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH wikicurses 1 2015-04-07
1+
.TH wikicurses 1 2015-04-10
22
.SH NAME
33
wikicurses \- curses interface for MediaWiki
44
.SH SYNOPSIS
@@ -162,10 +162,10 @@ view featured feed
162162
.PP
163163
\-\-dumpcolors
164164
.RS 4
165-
print default color settings
165+
write current color settings to config file
166166
.RE
167167
.SH COLOR SETTINGS
168-
To use colors other than the defaults, you need a file called ~/.config/wikicurses/colors.json. To create this file with the default color settings, run wikicurses --dumpcolors > ~/.config/wikicurses/colors.json. This is a json object containing various things that can be colored. Each has an array containing the foreground color, display settings (bold, underline, or standout), and the background color. The color options are the same as in urwid (see http://urwid.org/manual/displayattributes.html).
168+
To use colors other than the defaults, you need a file called ~/.config/wikicurses/colors. To create this file with the current color settings, run wikicurses --dumpcolors. This is a configuration file containing various things that can be colored. Each has allows setting display settings (bold, underline, or standout), foreground color, and background color. Multiple settings can be set by separating with spaces. The color options are the same as in urwid (see http://urwid.org/manual/displayattributes.html).
169169
.SH ENVIRONMENT VARIABLES
170170
.PP
171171
HOME, XDG_CONFIG_HOME

0 commit comments

Comments
 (0)