Skip to content

Commit 48b8da7

Browse files
committed
Add argument to supply key list limit
1 parent a115ec1 commit 48b8da7

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

client/interactive/client.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
# format="%(asctime)s - %(levelname)s: %(message)s",
2323
# )
2424

25-
KEY_LIST_LIMIT = 20
26-
2725

2826
class ListKeysWidget(Widget):
2927
def __init__(self, stub, **kwargs):
@@ -123,14 +121,14 @@ class FossilDBClient(App):
123121
Binding(
124122
"pagedown,j",
125123
"show_next",
126-
f"Show next {KEY_LIST_LIMIT} keys",
124+
f"Show next page of keys",
127125
priority=True,
128126
show=True,
129127
),
130128
Binding(
131129
"pageup,k",
132130
"show_prev",
133-
f"Show previous {KEY_LIST_LIMIT} keys",
131+
f"Show previous page of keys",
134132
priority=True,
135133
show=True,
136134
),
@@ -145,10 +143,11 @@ class FossilDBClient(App):
145143

146144
last_keys = [""]
147145

148-
def __init__(self, stub, collection):
146+
def __init__(self, stub, collection, count):
149147
super().__init__()
150148
self.stub = stub
151149
self.collection = collection
150+
self.key_list_limit = int(count)
152151

153152
def compose(self) -> ComposeResult:
154153
"""Create child widgets for the app."""
@@ -185,11 +184,11 @@ def refresh_data(self) -> None:
185184
self.collection,
186185
self.prefix,
187186
self.after_key,
188-
KEY_LIST_LIMIT,
187+
self.key_list_limit,
189188
)
190189
else:
191190
keys = listKeys(
192-
self.stub, self.collection, self.after_key, KEY_LIST_LIMIT
191+
self.stub, self.collection, self.after_key, self.key_list_limit
193192
)
194193
for i, key in enumerate(keys):
195194
label = Text(str(i), style="#B0FC38 italic")
@@ -212,12 +211,12 @@ def action_refresh(self) -> None:
212211
self.refresh_data()
213212

214213
def action_show_next(self) -> None:
215-
"""An action to show the next KEY_LIST_LIMIT keys."""
214+
"""An action to show the next key_list_limit keys."""
216215
self.after_key = self.last_keys[-1]
217216
self.refresh_data()
218217

219218
def action_show_prev(self) -> None:
220-
"""An action to show the previous KEY_LIST_LIMIT keys."""
219+
"""An action to show the previous key_list_limit keys."""
221220
if len(self.last_keys) > 2:
222221
self.last_keys.pop()
223222
self.last_keys.pop()
@@ -240,24 +239,26 @@ def action_prev_key(self) -> None:
240239
if current_row > 0:
241240
table.cursor_coordinate = (current_row - 1, table.cursor_coordinate.column)
242241
else:
243-
self.action_show_prev()
244-
table.cursor_coordinate = (
245-
len(table.rows) - 1,
246-
table.cursor_coordinate.column,
247-
)
242+
if self.after_key != "":
243+
self.action_show_prev()
244+
table.cursor_coordinate = (
245+
len(table.rows) - 1,
246+
table.cursor_coordinate.column,
247+
)
248248

249249

250250
def init_argument_parser():
251251
parser = argparse.ArgumentParser()
252252
parser.add_argument("-p", "--port", help="fossildb port", default="7155")
253253
parser.add_argument("-i", "--ip", help="fossildb ip", default="localhost")
254254
parser.add_argument("-c", "--collection", help="collection to use", default="")
255+
parser.add_argument("-n", "--count", help="number of keys to list", default=40)
255256
return parser
256257

257258

258259
if __name__ == "__main__":
259260
parser = init_argument_parser()
260261
args = parser.parse_args()
261262
stub = connect(args.ip, args.port)
262-
app = FossilDBClient(stub, args.collection)
263+
app = FossilDBClient(stub, args.collection, args.count)
263264
app.run()

0 commit comments

Comments
 (0)