Ejemplo n.º 1
0
static void color_print_size (void *p, printpkgfn f)
{
	const char *info = f(p, 'r');
	if (info && strcmp (info, "aur") != 0) {
		fprintf (stdout, " [%.2f M]", (double) get_size_pkg (p) / (1024.0 * 1024));
	}
}
Ejemplo n.º 2
0
void color_print_package (void * p, printpkgfn f)
{
	string_t *cstr;
	static int number=0;
	const char *info, *lver;
	char *ver=NULL;
	int aur=(f == aur_get_str);
	int grp=(f == alpm_grp_get_str);
	cstr=string_new ();

	/* Numbering list */
	if (config.numbering)
		cstr = string_fcat (cstr, "%s%d%s ",
		    color (C_NB), ++number, color (C_NO));

	/* repo/name */
	if (config.aur_foreign)
		info = f(p, 'r');
	else
		info = f(p, 's');
	if (info)
	{
		if (config.get_res) dprintf (FD_RES, "%s/", info);
		cstr = string_fcat (cstr, "%s%s/%s",
		    color_repo (info), info, color(C_NO));
	}
	info=f(p, 'n');
	if (config.get_res) dprintf (FD_RES, "%s\n", info);
	cstr = string_fcat (cstr, "%s%s%s ", color(C_PKG), info, color(C_NO));

	if (grp)
	{
		/* no more output for groups */
		fprintf (stdout, "%s\n", string_cstr (cstr));
		string_free (cstr);
		return;
	}

	/* Version
	 * different colors:
	 *   C_ORPHAN if package exists in AUR and is orphaned
	 *   C_OD if package exists and is out of date
	 *   C_VER otherwise
	 */
	lver = alpm_local_pkg_get_str (info, 'l');
	info = f(p, (config.aur_upgrades) ? 'V' : 'v');
	ver = STRDUP (info);
	info = (aur) ? f(p, 'm') : NULL;
	if (config.aur_foreign)
	{
		/* Compare foreign package with AUR */
		if (aur)
		{
			const char *lver_color = NULL;
			if (!info)
				lver_color=color(C_ORPHAN);
			else
			{
				info = f(p, 'o');
				if (info && info[0]=='1')
					lver_color=color(C_OD);
			}
			cstr = string_fcat (cstr, "%s%s%s",
			    (lver_color) ? lver_color : color(C_VER),
			    lver, color (C_NO));
			if (alpm_pkg_vercmp (ver, lver)>0)
				cstr = string_fcat (cstr, " ( aur: %s )", ver);
			fprintf (stdout, "%s\n", string_cstr (cstr));
			FREE (ver);
		}
		else
			fprintf (stdout, "%s %s%s%s\n", string_cstr (cstr),
				color(C_VER), lver, color(C_NO));
		string_free (cstr);
		return;
	}
	if (aur && !info)
		cstr = string_fcat (cstr, "%s%s%s", color(C_ORPHAN), ver, color (C_NO));
	else
		cstr = string_fcat (cstr, "%s%s%s", color(C_VER), ver, color (C_NO));

	/* show size */
	if (config.show_size)
	{
		info = f(p, 'r');
		if (info)
		{
			if (strcmp (info, "aur")!=0)
				cstr = string_fcat (cstr, " [%.2f M]",
				    (double) get_size_pkg (p) / (1024.0 * 1024));
		}
	}

	if (config.aur_upgrades)
	{
		fprintf (stdout, "%s\n", string_cstr (cstr));
		string_free (cstr);
		FREE (ver);
		return;
	}

	/* show groups */
	info = f(p, 'g');
	if (info)
	{
		cstr = string_fcat (cstr, " %s(%s)%s", color(C_GRP), info, color(C_NO));
	}

	/* show install information */
	if (lver)
	{
		info = f(p, 'r');
		if (info && strcmp (info, "local")!=0)
		{
			cstr = string_fcat (cstr, " %s[%s",
			    color(C_INSTALLED), _("installed"));
			if (strcmp (ver, lver)!=0)
			{
				cstr = string_fcat (cstr, ": %s%s%s%s",
				    color(C_LVER), lver, color (C_NO), color(C_INSTALLED));
			}
			cstr = string_fcat (cstr, "]%s", color(C_NO));
		}
	}
	/* ver no more needed */
	FREE (ver);

	/* Out of date status & votes */
	if (aur)
	{
		info = f(p, 'o');
		if (info && info[0]=='1')
		{
			cstr = string_fcat (cstr, " %s(%s)%s",
				color(C_OD), _("Out of Date"), color(C_NO));
		}
		info = f(p, 'w');
		if (info)
		{
			cstr = string_fcat (cstr, " %s(%s)%s",
			    color(C_VOTES), info, color(C_NO));
		}
	}

	/* Display computed string */
	fprintf (stdout, "%s\n", string_cstr (cstr));
	string_free (cstr);

	/* Description
	 * if -Q or -Sl or -Sg <target>, don't display description
	 */
	if (config.op != OP_SEARCH && config.op != OP_LIST_REPO_S) return;
	fprintf (stdout, "%s", color(C_DSC));
	indent (f(p, 'd'));
	fprintf (stdout, "%s", color(C_NO));
}