Add option to set minimum number of chars in hints

This commit is contained in:
Samir Benmendil 2015-02-26 00:47:49 +00:00
parent 25b09b60d9
commit 81af41d77f
2 changed files with 13 additions and 3 deletions

View File

@ -187,14 +187,20 @@ class HintManager(QObject):
chars = '0123456789'
else:
chars = config.get('hints', 'chars')
min_chars = config.get('hints', 'min-chars')
# Determine how many digits the link hints will require in the worst
# case. Usually we do not need all of these digits for every link
# single hint, so we can show shorter hints for a few of the links.
needed = math.ceil(math.log(len(elems), len(chars)))
needed = max(min_chars, math.ceil(math.log(len(elems), len(chars))))
# Short hints are the number of hints we can possibly show which are
# (needed - 1) digits in length.
short_count = math.floor((len(chars) ** needed - len(elems)) /
len(chars))
if needed > min_chars:
short_count = math.floor((len(chars) ** needed - len(elems)) /
len(chars))
else:
short_count = 0
long_count = len(elems) - short_count
strings = []

View File

@ -606,6 +606,10 @@ DATA = collections.OrderedDict([
SettingValue(typ.String(minlen=2), 'asdfghjkl'),
"Chars used for hint strings."),
('min-chars',
SettingValue(typ.Int(minval=1), '1'),
"Mininum number of chars used for hint strings."),
('uppercase',
SettingValue(typ.Bool(), 'false'),
"Make chars in hint strings uppercase."),