Skip to content

Commit 62725b3

Browse files
committed
Add more keys hint
1 parent 48b8da7 commit 62725b3

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed

client/interactive/client.py

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def sanitize_filename(self, name):
5858
import re
5959

6060
s = str(name).strip().replace(" ", "_")
61-
return re.sub(r"(?u)[^-\w.]", "", s)
61+
return re.sub(r"(?u)[^-\w.]", "_", s)
6262

6363
def update_key(self, key):
6464
self.key = key
@@ -72,6 +72,9 @@ def update_key(self, key):
7272
log.write(Text("Key:", style="bold magenta"))
7373
log.write(key)
7474

75+
if key == "More keys on the next page...":
76+
return
77+
7578
try:
7679
self.versions = listVersions(stub, self.collection, key)
7780
log.write(Text("Versions:", style="bold magenta"))
@@ -119,19 +122,31 @@ class FossilDBClient(App):
119122
("q", "quit", "Quit the client"),
120123
("r", "refresh", "Refresh the data"),
121124
Binding(
122-
"pagedown,j",
125+
"pagedown",
123126
"show_next",
124127
f"Show next page of keys",
125128
priority=True,
126129
show=True,
127130
),
128131
Binding(
129-
"pageup,k",
132+
"j",
133+
"show_next",
134+
f"Show next page of keys",
135+
show=True,
136+
),
137+
Binding(
138+
"pageup",
130139
"show_prev",
131140
f"Show previous page of keys",
132141
priority=True,
133142
show=True,
134143
),
144+
Binding(
145+
"k",
146+
"show_prev",
147+
f"Show previous page of keys",
148+
show=True,
149+
),
135150
Binding("down", "next_key", "Select the next key", priority=True, show=False),
136151
Binding("up", "prev_key", "Select the previous key", priority=True, show=False),
137152
]
@@ -184,15 +199,25 @@ def refresh_data(self) -> None:
184199
self.collection,
185200
self.prefix,
186201
self.after_key,
187-
self.key_list_limit,
202+
self.key_list_limit + 1, # +1 to check if there are more keys
188203
)
189204
else:
190205
keys = listKeys(
191-
self.stub, self.collection, self.after_key, self.key_list_limit
206+
self.stub, self.collection, self.after_key, self.key_list_limit + 1
192207
)
208+
overlength = False
209+
if len(keys) > self.key_list_limit:
210+
keys = keys[:-1]
211+
overlength = True
212+
193213
for i, key in enumerate(keys):
194214
label = Text(str(i), style="#B0FC38 italic")
195215
table.add_row(key, label=label)
216+
if overlength:
217+
table.add_row(
218+
"More keys on the next page...",
219+
label=Text("...", style="#B0FC38 italic"),
220+
)
196221
self.last_keys.append(keys[-1])
197222
table.focus()
198223
except Exception as e:
@@ -227,7 +252,7 @@ def action_next_key(self) -> None:
227252
"""An action to select the next key."""
228253
table = self.query_one(DataTable)
229254
current_row = table.cursor_coordinate.row
230-
if current_row < len(table.rows) - 1:
255+
if current_row < self.key_list_limit - 1:
231256
table.cursor_coordinate = (current_row + 1, table.cursor_coordinate.column)
232257
else:
233258
self.action_show_next()
@@ -242,15 +267,19 @@ def action_prev_key(self) -> None:
242267
if self.after_key != "":
243268
self.action_show_prev()
244269
table.cursor_coordinate = (
245-
len(table.rows) - 1,
270+
len(table.rows) - 2, # -1 for last row, -1 for the More keys row
246271
table.cursor_coordinate.column,
247272
)
248273

249274

250275
def init_argument_parser():
251276
parser = argparse.ArgumentParser()
252-
parser.add_argument("-p", "--port", help="fossildb port", default="7155")
253-
parser.add_argument("-i", "--ip", help="fossildb ip", default="localhost")
277+
parser.add_argument(
278+
"host",
279+
help="fossildb host and ip, e.g. localhost:7155",
280+
default="localhost:7155",
281+
nargs="?",
282+
)
254283
parser.add_argument("-c", "--collection", help="collection to use", default="")
255284
parser.add_argument("-n", "--count", help="number of keys to list", default=40)
256285
return parser
@@ -259,6 +288,6 @@ def init_argument_parser():
259288
if __name__ == "__main__":
260289
parser = init_argument_parser()
261290
args = parser.parse_args()
262-
stub = connect(args.ip, args.port)
291+
stub = connect(args.host)
263292
app = FossilDBClient(stub, args.collection, args.count)
264293
app.run()

client/interactive/db_connection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
MAX_MESSAGE_LENGTH = 1073741824
88

99

10-
def connect(ip, port):
10+
def connect(host):
1111
channel = grpc.insecure_channel(
12-
"{}:{}".format(ip, port),
12+
host,
1313
options=[
1414
("grpc.max_send_message_length", MAX_MESSAGE_LENGTH),
1515
("grpc.max_receive_message_length", MAX_MESSAGE_LENGTH),
1616
],
1717
)
1818
stub = proto_rpc.FossilDBStub(channel)
19-
testHealth(stub, "destination fossildb at {}:{}".format(ip, port))
19+
testHealth(stub, "destination fossildb at {}".format(host))
2020
return stub
2121

2222

0 commit comments

Comments
 (0)