Handle -ve indices in print_rec
This commit is contained in:
parent
a1e6df2edb
commit
abac8d016b
@ -308,7 +308,7 @@ Copy or select a URL with mouse and press the keyboard shortcut to add it to the
|
|||||||
|
|
||||||
To verify that the bookmark has indeed been added, run:
|
To verify that the bookmark has indeed been added, run:
|
||||||
|
|
||||||
$ buku -p | tail -3
|
$ buku -p -1
|
||||||
and check the entry.
|
and check the entry.
|
||||||
|
|
||||||
##### Tips
|
##### Tips
|
||||||
|
26
buku.py
26
buku.py
@ -1192,6 +1192,17 @@ class BukuDb:
|
|||||||
index is ignored if is_range is True
|
index is ignored if is_range is True
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
if (index < 0):
|
||||||
|
# Show the last n records
|
||||||
|
_id = self.get_max_id()
|
||||||
|
if _id == -1:
|
||||||
|
logerr('Empty database')
|
||||||
|
return False
|
||||||
|
|
||||||
|
low = (1 if _id <= -index else _id + index + 1)
|
||||||
|
high = _id
|
||||||
|
is_range = True
|
||||||
|
|
||||||
if is_range:
|
if is_range:
|
||||||
if low < 0 or high < 0:
|
if low < 0 or high < 0:
|
||||||
logerr('Negative range boundary')
|
logerr('Negative range boundary')
|
||||||
@ -2237,7 +2248,7 @@ def prompt(obj, results, noninteractive=False, deep=False, subprompt=False):
|
|||||||
id_list = nav[2:].split()
|
id_list = nav[2:].split()
|
||||||
try:
|
try:
|
||||||
for id in id_list:
|
for id in id_list:
|
||||||
if is_int(id) and int(id) > 0:
|
if is_int(id):
|
||||||
obj.print_rec(int(id))
|
obj.print_rec(int(id))
|
||||||
elif '-' in id:
|
elif '-' in id:
|
||||||
vals = [int(x) for x in id.split('-')]
|
vals = [int(x) for x in id.split('-')]
|
||||||
@ -3161,18 +3172,7 @@ POSITIONAL ARGUMENTS:
|
|||||||
try:
|
try:
|
||||||
for idx in args.print:
|
for idx in args.print:
|
||||||
if is_int(idx):
|
if is_int(idx):
|
||||||
id = int(idx)
|
bdb.print_rec(int(idx))
|
||||||
if id >= 0:
|
|
||||||
bdb.print_rec(id)
|
|
||||||
else:
|
|
||||||
# Show the last n records
|
|
||||||
_id = bdb.get_max_id()
|
|
||||||
if _id == -1:
|
|
||||||
logerr('Empty database')
|
|
||||||
bdb.close_quit(1)
|
|
||||||
|
|
||||||
bdb.print_rec(0, 1 if _id <= -id else _id + id + 1,
|
|
||||||
_id, True)
|
|
||||||
elif '-' in idx:
|
elif '-' in idx:
|
||||||
vals = [int(x) for x in idx.split('-')]
|
vals = [int(x) for x in idx.split('-')]
|
||||||
bdb.print_rec(0, vals[0], vals[-1], True)
|
bdb.print_rec(0, vals[0], vals[-1], True)
|
||||||
|
Loading…
Reference in New Issue
Block a user