| 161 | |
| 162 | |
| 163 | def loop(screen, bpf, peers): |
| 164 | screen.nodelay(1) |
| 165 | cur_list_pos = 0 |
| 166 | win = curses.newwin(30, 70, 2, 7) |
| 167 | win.erase() |
| 168 | win.border(ord("|"), ord("|"), ord("-"), ord("-"), |
| 169 | ord("-"), ord("-"), ord("-"), ord("-")) |
| 170 | info_panel = panel.new_panel(win) |
| 171 | info_panel.hide() |
| 172 | |
| 173 | ROWS_AVALIABLE_FOR_LIST = curses.LINES - 5 |
| 174 | scroll = 0 |
| 175 | |
| 176 | while True: |
| 177 | try: |
| 178 | # BCC: poll the perf buffers for new events or timeout after 50ms |
| 179 | bpf.perf_buffer_poll(timeout=50) |
| 180 | |
| 181 | ch = screen.getch() |
| 182 | if (ch == curses.KEY_DOWN or ch == ord("j")) and cur_list_pos < len( |
| 183 | peers.keys()) -1 and info_panel.hidden(): |
| 184 | cur_list_pos += 1 |
| 185 | if cur_list_pos >= ROWS_AVALIABLE_FOR_LIST: |
| 186 | scroll += 1 |
| 187 | if (ch == curses.KEY_UP or ch == ord("k")) and cur_list_pos > 0 and info_panel.hidden(): |
| 188 | cur_list_pos -= 1 |
| 189 | if scroll > 0: |
| 190 | scroll -= 1 |
| 191 | if ch == ord('\n') or ch == ord(' '): |
| 192 | if info_panel.hidden(): |
| 193 | info_panel.show() |
| 194 | else: |
| 195 | info_panel.hide() |
| 196 | screen.erase() |
| 197 | render(screen, peers, cur_list_pos, scroll, ROWS_AVALIABLE_FOR_LIST, info_panel) |
| 198 | curses.panel.update_panels() |
| 199 | screen.refresh() |
| 200 | except KeyboardInterrupt: |
| 201 | exit() |
| 202 | |
| 203 | |
| 204 | def render(screen, peers, cur_list_pos, scroll, ROWS_AVALIABLE_FOR_LIST, info_panel): |