Merge branch 'master' of git.distorted.org.uk:~mdw/publish/public-git/dvdrip
[dvdrip] / multiprogress.c
index aa8e890..0594f37 100644 (file)
@@ -69,6 +69,7 @@ int progress_init(struct progress_state *progress)
   if (setupterm(0, fileno(tty->fp), &err) != OK || err < 1) return (-1);
 
   tty->cap.cr = tigetstr("cr");
+  tty->cap.nw = tigetstr("nel");
   tty->cap.up = tigetstr("cuu1");
   tty->cap.ce = tigetstr("el");
   tty->cap.cd = tigetstr("ed");
@@ -98,6 +99,7 @@ int progress_init(struct progress_state *progress)
 
   capcur = tty->capbuf;
   tty->cap.cr = tgetstr("cr", &capcur);
+  tty->cap.nw = tgetstr("nw", &capcur);
   tty->cap.up = tgetstr("up", &capcur);
   tty->cap.ce = tgetstr("ce", &capcur);
   tty->cap.cd = tgetstr("cd", &capcur);
@@ -129,6 +131,7 @@ int progress_init(struct progress_state *progress)
 #undef SETDIM
 
   if (!tty->cap.cr) tty->cap.cr = "\r";
+  if (!tty->cap.nw) tty->cap.nw = "\r\n";
   if (!tty->cap.up || !tty->cap.ce || !tty->cap.cd)
     { fclose(tty->fp); tty->fp = 0; return (-1); }
   if (!tty->cap.af || !tty->cap.ab || !tty->cap.op) tty->cap.op = 0;
@@ -555,6 +558,7 @@ int progress_clear(struct progress_state *progress)
 int progress_update(struct progress_state *progress)
 {
   struct progress_render_state render;
+  const struct progress_ttyinfo *tty = &progress->tty;
   struct progress_item *item;
   unsigned f = 0;
 #define f_any 1u
@@ -564,12 +568,13 @@ int progress_update(struct progress_state *progress)
   clear_progress(progress, &render, 0);
 
   for (item = progress->items; item; item = item->next) {
-    if (f&f_any) fputs("\r\n", progress->tty.fp);
+    if (f&f_any) put_sequence(tty, tty->cap.nw, 1);
     render.leftsz = render.rightsz = 0;
     render.leftwd = render.rightwd = 0;
     item->render(item, &render); progress->last_lines++; f |= f_any;
     if (progress->last_lines > render.height) break;
   }
+  if (f&f_any) put_sequence(tty, tty->cap.cr, 1);
   free_render_state(&render);
   return (0);
 }