cplay-ng

simple curses audio player
git clone https://git.ce9e.org/cplay-ng.git

commit
ef314c1d64c1f5e13c72f76d8ce41e85d8c60785
parent
9f2be352daaf987bdb6260774b7e1f0931419819
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2020-09-03 08:56
allow to use ctrl key combinations

Diffstat

M cplay.py 18 +++++++++++++++++-

1 files changed, 17 insertions, 1 deletions


diff --git a/cplay.py b/cplay.py

@@ -6,7 +6,9 @@ import select
    6     6 import signal
    7     7 import subprocess
    8     8 import sys
   -1     9 import termios
    9    10 import time
   -1    11 from contextlib import contextmanager
   10    12 
   11    13 AUDIO_EXTENSIONS = [
   12    14     'mp3', 'ogg', 'oga', 'opus', 'flac', 'm4a', 'm4b', 'wav', 'mid', 'wma'
@@ -77,6 +79,19 @@ def resize(*args):
   77    79     app.render()
   78    80 
   79    81 
   -1    82 @contextmanager
   -1    83 def enable_ctrl_keys():
   -1    84     fd = sys.stdin.fileno()
   -1    85     old = termios.tcgetattr(fd)
   -1    86     try:
   -1    87         tcattr = termios.tcgetattr(fd)
   -1    88         tcattr[0] = tcattr[0] & ~(termios.IXON)
   -1    89         termios.tcsetattr(fd, termios.TCSANOW, tcattr)
   -1    90         yield
   -1    91     finally:
   -1    92         termios.tcsetattr(fd, termios.TCSADRAIN, old)
   -1    93 
   -1    94 
   80    95 def listdir(path):
   81    96     with os.scandir(path) as it:
   82    97         for entry in sorted(it, key=lambda e: e.name):
@@ -577,7 +592,8 @@ def main():
  577   592     signal.signal(signal.SIGWINCH, resize)
  578   593 
  579   594     try:
  580    -1         app.run()
   -1   595         with enable_ctrl_keys():
   -1   596             app.run()
  581   597     finally:
  582   598         curses.endwin()
  583   599