@@ -61,8 +61,6 @@ def highlight_line(highlight, window, line):
61
61
62
62
pad .chgat (line , 1 , select_len , color | curses .A_REVERSE if highlight else color )
63
63
64
- refresh_pad (window )
65
-
66
64
def add_notification (channel_number ):
67
65
globals .notifications .add (channel_number )
68
66
@@ -197,51 +195,56 @@ def draw_node_list():
197
195
198
196
refresh_pad (2 )
199
197
200
- def select_channels (direction ):
201
- channel_list_length = len (globals .channel_list )
198
+ def select_channel (idx ):
202
199
old_selected_channel = globals .selected_channel
203
- globals .selected_channel += direction
204
-
205
- if globals .selected_channel < 0 :
206
- globals .selected_channel = channel_list_length - 1
207
- elif globals .selected_channel >= channel_list_length :
208
- globals .selected_channel = 0
200
+ globals .selected_channel = max (0 , min (idx , len (globals .channel_list ) - 1 ))
209
201
draw_messages_window (True )
210
202
211
203
# For now just re-draw channel list when clearing notifications, we can probably make this more efficient
212
204
if globals .selected_channel in globals .notifications :
213
205
remove_notification (globals .selected_channel )
214
206
draw_channel_list ()
215
207
return
216
-
217
208
highlight_line (False , 0 , old_selected_channel )
218
209
highlight_line (True , 0 , globals .selected_channel )
219
-
220
210
refresh_pad (0 )
221
211
222
- def select_messages (direction ):
212
+ def scroll_channels (direction ):
213
+ new_selected_channel = globals .selected_channel + direction
214
+
215
+ if new_selected_channel < 0 :
216
+ new_selected_channel = len (globals .channel_list ) - 1
217
+ elif new_selected_channel >= len (globals .channel_list ):
218
+ new_selected_channel = 0
219
+
220
+ select_channel (new_selected_channel )
221
+
222
+ def scroll_messages (direction ):
223
223
globals .selected_message += direction
224
224
225
225
msg_line_count = messages_pad .getmaxyx ()[0 ]
226
226
globals .selected_message = max (0 , min (globals .selected_message , msg_line_count - get_msg_window_lines ()))
227
227
228
228
refresh_pad (1 )
229
229
230
- def select_nodes (direction ):
231
- node_list_length = len (globals .node_list )
230
+ def select_node (idx ):
232
231
old_selected_node = globals .selected_node
233
- globals .selected_node += direction
234
-
235
- if globals .selected_node < 0 :
236
- globals .selected_node = node_list_length - 1
237
- elif globals .selected_node >= node_list_length :
238
- globals .selected_node = 0
232
+ globals .selected_node = max (0 , min (idx , len (globals .node_list ) - 1 ))
239
233
240
234
highlight_line (False , 2 , old_selected_node )
241
235
highlight_line (True , 2 , globals .selected_node )
242
-
243
236
refresh_pad (2 )
244
237
238
+ def scroll_nodes (direction ):
239
+ new_selected_node = globals .selected_node + direction
240
+
241
+ if new_selected_node < 0 :
242
+ new_selected_node = len (globals .node_list ) - 1
243
+ elif new_selected_node >= len (globals .node_list ):
244
+ new_selected_node = 0
245
+
246
+ select_node (new_selected_node )
247
+
245
248
def draw_packetlog_win ():
246
249
247
250
columns = [10 ,10 ,15 ,30 ]
@@ -349,41 +352,57 @@ def main_ui(stdscr):
349
352
350
353
if char == curses .KEY_UP :
351
354
if globals .current_window == 0 :
352
- select_channels (- 1 )
355
+ scroll_channels (- 1 )
353
356
elif globals .current_window == 1 :
354
- select_messages (- 1 )
357
+ scroll_messages (- 1 )
355
358
elif globals .current_window == 2 :
356
- select_nodes (- 1 )
359
+ scroll_nodes (- 1 )
357
360
358
361
elif char == curses .KEY_DOWN :
359
362
if globals .current_window == 0 :
360
- select_channels (1 )
363
+ scroll_channels (1 )
361
364
elif globals .current_window == 1 :
362
- select_messages (1 )
365
+ scroll_messages (1 )
363
366
elif globals .current_window == 2 :
364
- select_nodes (1 )
367
+ scroll_nodes (1 )
365
368
366
369
elif char == curses .KEY_HOME :
367
- if globals .current_window == 1 :
370
+ if globals .current_window == 0 :
371
+ select_channel (0 )
372
+ elif globals .current_window == 1 :
368
373
globals .selected_message = 0
369
374
refresh_pad (1 )
375
+ elif globals .current_window == 2 :
376
+ select_node (0 )
370
377
371
378
elif char == curses .KEY_END :
372
- if globals .current_window == 1 :
379
+ if globals .current_window == 0 :
380
+ select_channel (len (globals .channel_list ) - 1 )
381
+ elif globals .current_window == 1 :
373
382
msg_line_count = messages_pad .getmaxyx ()[0 ]
374
383
globals .selected_message = max (msg_line_count - get_msg_window_lines (), 0 )
375
384
refresh_pad (1 )
385
+ elif globals .current_window == 2 :
386
+ select_node (len (globals .node_list ) - 1 )
376
387
377
388
elif char == curses .KEY_PPAGE :
378
- if globals .current_window == 1 :
389
+ if globals .current_window == 0 :
390
+ select_channel (globals .selected_channel - (channel_box .getmaxyx ()[0 ] - 2 )) # select_channel will bounds check for us
391
+ elif globals .current_window == 1 :
379
392
globals .selected_message = max (globals .selected_message - get_msg_window_lines (), 0 )
380
393
refresh_pad (1 )
394
+ elif globals .current_window == 2 :
395
+ select_node (globals .selected_node - (nodes_box .getmaxyx ()[0 ] - 2 )) # select_node will bounds check for us
381
396
382
397
elif char == curses .KEY_NPAGE :
383
- if globals .current_window == 1 :
398
+ if globals .current_window == 0 :
399
+ select_channel (globals .selected_channel + (channel_box .getmaxyx ()[0 ] - 2 )) # select_channel will bounds check for us
400
+ elif globals .current_window == 1 :
384
401
msg_line_count = messages_pad .getmaxyx ()[0 ]
385
402
globals .selected_message = min (globals .selected_message + get_msg_window_lines (), msg_line_count - get_msg_window_lines ())
386
403
refresh_pad (1 )
404
+ elif globals .current_window == 2 :
405
+ select_node (globals .selected_node + (nodes_box .getmaxyx ()[0 ] - 2 )) # select_node will bounds check for us
387
406
388
407
elif char == curses .KEY_LEFT or char == curses .KEY_RIGHT :
389
408
delta = - 1 if char == curses .KEY_LEFT else 1
@@ -396,6 +415,7 @@ def main_ui(stdscr):
396
415
channel_box .box ()
397
416
channel_box .refresh ()
398
417
highlight_line (False , 0 , globals .selected_channel )
418
+ refresh_pad (0 )
399
419
if old_window == 1 :
400
420
messages_box .attrset (curses .color_pair (0 ))
401
421
messages_box .box ()
@@ -406,13 +426,15 @@ def main_ui(stdscr):
406
426
nodes_box .box ()
407
427
nodes_box .refresh ()
408
428
highlight_line (False , 2 , globals .selected_node )
429
+ refresh_pad (2 )
409
430
410
431
if globals .current_window == 0 :
411
432
channel_box .attrset (curses .color_pair (2 ))
412
433
channel_box .box ()
413
434
channel_box .attrset (curses .color_pair (0 ))
414
435
channel_box .refresh ()
415
436
highlight_line (True , 0 , globals .selected_channel )
437
+ refresh_pad (0 )
416
438
elif globals .current_window == 1 :
417
439
messages_box .attrset (curses .color_pair (2 ))
418
440
messages_box .box ()
@@ -425,6 +447,7 @@ def main_ui(stdscr):
425
447
nodes_box .attrset (curses .color_pair (0 ))
426
448
nodes_box .refresh ()
427
449
highlight_line (True , 2 , globals .selected_node )
450
+ refresh_pad (2 )
428
451
429
452
# Check for Esc
430
453
elif char == chr (27 ):
0 commit comments