src/fetch/main.c
static int
neologo_present(struct notcurses* nc, const char* nlogo){
  // find the maximum line length in columns by iterating over the logo
  size_t maxlinelen = 0;
  size_t linelen; // length in bytes, including newline
  char** lines = NULL;
  int linecount = 0;
  for(const char* cur = nlogo ; *cur ; cur += linelen){
    const char* nl = strchr(cur, '\n');
    if(nl){
      linelen = (nl + 1) - cur;
    }else{
      linelen = strlen(cur);
    }
    char** tmpl;
    if((tmpl = realloc(lines, sizeof(*lines) * (linecount + 1))) == NULL){
      free(lines);
      return -1;
    }
    lines = tmpl;
    lines[linecount++] = strndup(cur, linelen);
    size_t collen = ncstrwidth(lines[linecount - 1]);
    if(collen > maxlinelen){
      maxlinelen = collen;
    }
  }
  int dimy, dimx;
  struct ncplane* n = notcurses_stddim_yx(nc, &dimy, &dimx);
  const int leftpad = (dimx - maxlinelen) / 2;
  for(int i = 0 ; i < linecount ; ++i){
    ncplane_printf(n, "%*.*s%s", leftpad, leftpad, "", lines[i]);
    free(lines[i]);
  }
  free(lines);
  ncplane_set_fg_default(n);
  ncplane_set_styles(n, NCSTYLE_BOLD | NCSTYLE_ITALIC);
  if(notcurses_canopen_images(nc)){
    ncplane_putstr_aligned(n, -1, NCALIGN_CENTER, "(no image file is known for your distro)");
  }else{
    ncplane_putstr_aligned(n, -1, NCALIGN_CENTER, "(notcurses was compiled without image support)");
  }
  ncplane_off_styles(n, NCSTYLE_BOLD | NCSTYLE_ITALIC);
  return notcurses_render(nc);
}
// present a neofetch-style logo. we want to substitute colors for ${cN} inline
// sequences, and center the logo.
present a neofetch-style logo. we want to substitute colors for ${cN} inline
sequences, and center the logo.
present a neofetch - style logo . we want to substitute colors for $ { cN } inline sequences and center the logo .
static int
neologo_present(struct notcurses* nc, const char* nlogo){
  size_t maxlinelen = 0;
  size_t linelen; 
  char** lines = NULL;
  int linecount = 0;
  for(const char* cur = nlogo ; *cur ; cur += linelen){
    const char* nl = strchr(cur, '\n');
    if(nl){
      linelen = (nl + 1) - cur;
    }else{
      linelen = strlen(cur);
    }
    char** tmpl;
    if((tmpl = realloc(lines, sizeof(*lines) * (linecount + 1))) == NULL){
      free(lines);
      return -1;
    }
    lines = tmpl;
    lines[linecount++] = strndup(cur, linelen);
    size_t collen = ncstrwidth(lines[linecount - 1]);
    if(collen > maxlinelen){
      maxlinelen = collen;
    }
  }
  int dimy, dimx;
  struct ncplane* n = notcurses_stddim_yx(nc, &dimy, &dimx);
  const int leftpad = (dimx - maxlinelen) / 2;
  for(int i = 0 ; i < linecount ; ++i){
    ncplane_printf(n, "%*.*s%s", leftpad, leftpad, "", lines[i]);
    free(lines[i]);
  }
  free(lines);
  ncplane_set_fg_default(n);
  ncplane_set_styles(n, NCSTYLE_BOLD | NCSTYLE_ITALIC);
  if(notcurses_canopen_images(nc)){
    ncplane_putstr_aligned(n, -1, NCALIGN_CENTER, "(no image file is known for your distro)");
  }else{
    ncplane_putstr_aligned(n, -1, NCALIGN_CENTER, "(notcurses was compiled without image support)");
  }
  ncplane_off_styles(n, NCSTYLE_BOLD | NCSTYLE_ITALIC);
  return notcurses_render(nc);
}
static int neologo_present ( struct notcurses * nc , const char * nlogo ) { size_t maxlinelen = 0 ; size_t linelen ; char * * lines = NULL ; int linecount = 0 ; for ( const char * cur = nlogo ; * cur ; cur += linelen ) { const char * nl = strchr ( cur , ' \n ' ) ; if ( nl ) { linelen = ( nl + 1 ) - cur ; } else { linelen = strlen ( cur ) ; } char * * tmpl ; if ( ( tmpl = realloc ( lines , sizeof ( * lines ) * ( linecount + 1 ) ) ) == NULL ) { free ( lines ) ; return -1 ; } lines = tmpl ; lines [ linecount ++ ] = strndup ( cur , linelen ) ; size_t collen = ncstrwidth ( lines [ linecount - 1 ] ) ; if ( collen > maxlinelen ) { maxlinelen = collen ; } } int dimy , dimx ; struct ncplane * n = notcurses_stddim_yx ( nc , & dimy , & dimx ) ; const int leftpad = ( dimx - maxlinelen ) / 2 ; for ( int i = 0 ; i < linecount ; ++ i ) { ncplane_printf ( n , " " , leftpad , leftpad , " " , lines [ i ] ) ; free ( lines [ i ] ) ; } free ( lines ) ; ncplane_set_fg_default ( n ) ; ncplane_set_styles ( n , NCSTYLE_BOLD | NCSTYLE_ITALIC ) ; if ( notcurses_canopen_images ( nc ) ) { ncplane_putstr_aligned ( n , -1 , NCALIGN_CENTER , " " ) ; } else { ncplane_putstr_aligned ( n , -1 , NCALIGN_CENTER , " " ) ; } ncplane_off_styles ( n , NCSTYLE_BOLD | NCSTYLE_ITALIC ) ; return notcurses_render ( nc ) ; }
present a neofetch-style logo.
present a neofetch - style logo .
// find the maximum line length in columns by iterating over the logo // length in bytes, including newline