multiprogress.c: Probe termcap/info for newline sequence.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 6 Mar 2022 01:05:54 +0000 (01:05 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 6 Mar 2022 01:05:54 +0000 (01:05 +0000)
Just to show willing.  Provide the obvious default, because it seems to
be necessary!

multiprogress.c
multiprogress.h

index aa8e890..17ba4c0 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,7 +568,7 @@ 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;
index 1db97a8..752eb8c 100644 (file)
@@ -10,7 +10,7 @@ struct progress_ttyinfo {
   struct {                             /* terminal capabilities */
     unsigned f;                                /*   various flags */
 #define TCF_BCE 1u                     /*   erases to background colour */
-    const char *cr, *up, *ce, *cd;     /*   cursor motion */
+    const char *cr, *nw, *up, *ce, *cd;        /*   cursor motion */
     const char *mr, *md, *me;          /*   reverse video, bold */
     const char *af, *ab, *op;          /*   colour */
   } cap;