cplay-ng

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

commit
9d4b99fdd4d556a14f27a18d77fe946e659eea54
parent
0368417d3f7027ed47e91e19081df119acde0809
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2020-09-05 14:37
self-pipe to avoid concurrency issues with signal

Diffstat

M cplay.py 19 ++++++++++++++-----

1 files changed, 14 insertions, 5 deletions


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

@@ -78,11 +78,7 @@ def set_volume(vol):
   78    78 
   79    79 
   80    80 def resize(*args):
   81    -1     curses.endwin()
   82    -1     screen.refresh()
   83    -1     app.refresh_dimensions()
   84    -1     app.tab.set_cursor(app.tab.cursor)
   85    -1     app.render()
   -1    81     os.write(app.resize_out, b'.')
   86    82 
   87    83 
   88    84 @contextmanager
@@ -582,9 +578,18 @@ class Application:
  582   578         self.input = Input()
  583   579         self.old_lines = []
  584   580 
   -1   581         # self-pipe to avoid concurrency issues with signal
   -1   582         self.resize_in, self.resize_out = os.pipe2(os.O_NONBLOCK)
   -1   583 
  585   584     def refresh_dimensions(self):
  586   585         self.rows, self.cols = screen.getmaxyx()
  587   586 
   -1   587     def on_resize(self):
   -1   588         curses.endwin()
   -1   589         screen.refresh()
   -1   590         self.refresh_dimensions()
   -1   591         self.tab.set_cursor(app.tab.cursor)
   -1   592 
  588   593     @property
  589   594     def tab(self):
  590   595         if self.help:
@@ -669,11 +674,15 @@ class Application:
  669   674             try:
  670   675                 r, _w, _e = select.select([
  671   676                     sys.stdin,
   -1   677                     self.resize_in,
  672   678                     player.stderr_r,
  673   679                 ], [], [], 0.5)
  674   680             except select.error:
  675   681                 continue
  676   682 
   -1   683             if self.resize_in in r:
   -1   684                 os.read(self.resize_in, 8)
   -1   685                 self.on_resize()
  677   686             if sys.stdin in r:
  678   687                 self.process_key(screen.get_wch())
  679   688             if player.stderr_r in r: