Skip to content

Instantly share code, notes, and snippets.

@mpentler
Last active July 21, 2025 20:52
Show Gist options
  • Select an option

  • Save mpentler/36e8a504ac09fb9ea79dc1a84557c278 to your computer and use it in GitHub Desktop.

Select an option

Save mpentler/36e8a504ac09fb9ea79dc1a84557c278 to your computer and use it in GitHub Desktop.
CLI Video player Listbox class
# Horrorbox v1.4
# List box used for file panel with bounds checking
import urwid
class SafeListBox(urwid.ListBox):
def keypress(self, size, key):
if key in ('up', 'down'):
focus_pos = self.focus_position
max_pos = len(self.body) - 1
if key == 'up' and focus_pos <= 0:
return None # Prevent going above the top
elif key == 'down' and focus_pos >= max_pos:
return None # Prevent going below the bottom
return super().keypress(size, key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment