Exemplo n.º 1
0
void
print_style (GtkStyle *style)
{
    print_colors ("fg", style->fg, 5);
    print_colors ("bg", style->bg, 5);
    print_colors ("light", style->light, 5);
    print_colors ("dark", style->dark, 5);
    print_colors ("mid", style->mid, 5);
    print_colors ("text", style->text, 5);
    print_colors ("base", style->base, 5);
}
Exemplo n.º 2
0
int main(void){
	//tests();
	POLYGON temp;
	assert(get_size(&temp.size_points)==TRUE);
	alloc_points(&temp.max_of_x,&temp.points,temp.size_points);
	temp.segments=create_segments(temp.size_points);
	add_segments(temp.points,temp.segments,temp.size_points);
	draw_polygon(temp);
	triangulal_polygol(temp); 
	printf("Potrzeba %d straznikow\n",coloring_sl(temp.points,temp.segments,temp.size_points));
	print_colors(temp.points,temp.size_points);
	draw_polygon(temp);
	free_segments(temp.segments,temp.size_points);
	free_points(temp.points);
	return EXIT_SUCCESS;
}
Exemplo n.º 3
0
void
print_rc_style (GtkRcStyle *rc, GtkStyle *style)
{
    if (print_rc_colors ("fg", rc->fg, 5, rc->color_flags, GTK_RC_FG))
    	print_colors ("fg", style->fg, 5);
    if (print_rc_colors ("bg", rc->bg, 5, rc->color_flags, GTK_RC_BG))
    	print_colors ("bg", style->bg, 5);
    if (print_rc_colors ("text", rc->text, 5, rc->color_flags, GTK_RC_TEXT))
    	print_colors ("text", style->text, 5);
    if (print_rc_colors ("base", rc->base, 5, rc->color_flags, GTK_RC_BASE))
    	print_colors ("base", style->base, 5);
    print_colors ("light", style->light, 5);
    print_colors ("dark", style->dark, 5);
    print_colors ("mid", style->mid, 5);
    print_strings ("bg-pixmap", rc->bg_pixmap_name, 5);
}
Exemplo n.º 4
0
static gchar *
print_rc_style (GtkWidget * win, const gchar * name, const gchar * state,
                GtkStyle * style)
{
    gchar *s;
    gint n, m;

    g_return_val_if_fail (state != NULL, NULL);
    g_return_val_if_fail (name != NULL, NULL);

    n = state_value (state);
    m = name_value (name);

    switch (m)
    {
        case GTKSTYLE_FG:
            s = print_colors (win, style->fg, n);
            break;
        case GTKSTYLE_BG:
            s = print_colors (win, style->bg, n);
            break;
        case GTKSTYLE_TEXT:
            s = print_colors (win, style->text, n);
            break;
        case GTKSTYLE_BASE:
            s = print_colors (win, style->base, n);
            break;
        case GTKSTYLE_LIGHT:
            s = print_colors (win, style->light, n);
            break;
        case GTKSTYLE_DARK:
            s = print_colors (win, style->dark, n);
            break;
        default:
        case GTKSTYLE_MID:
            s = print_colors (win, style->mid, n);
            break;
    }
    return (s);
}
int main(int argc, char** argv)
{
    enum color_t                initial_colors1 [] =
        {color_blue, color_red, color_yellow};

    enum color_t                initial_colors2 [] =
        {color_blue, color_red, color_yellow, color_red, color_yellow,
        color_blue, color_red, color_yellow, color_red, color_blue};

    struct meeting_place_t*     place1;
    struct chameneos_t**        chameneos1;
    size_t                      chameneos_count1;

    struct meeting_place_t*     place2;
    struct chameneos_t**        chameneos2;
    size_t                      chameneos_count2;

    size_t                      meet_count;

    meet_count = 6000000;
    if (argc > 1 && atoi(argv[1]) > 0)
        meet_count = atoi(argv[1]);

    print_colors();

    chameneos_count1 = sizeof(initial_colors1)/sizeof(initial_colors1[0]);
    chameneos_count2 = sizeof(initial_colors2)/sizeof(initial_colors2[0]);

    init_and_start(initial_colors1, chameneos_count1,
                   &place1, &chameneos1, meet_count);
    init_and_start(initial_colors2, chameneos_count2,
                   &place2, &chameneos2, meet_count);
    join_and_output(initial_colors1, chameneos_count1, place1, chameneos1);
    join_and_output(initial_colors2, chameneos_count2, place2, chameneos2);

    return 0;
}
Exemplo n.º 6
0
int main (int ac, char **av)
{
    int rval = 0;
    double  start_time = COLORcpu_time();
    double tot_rtime;


    COLORproblem colorproblem;
    COLORparms* parms = &(colorproblem.parms);
    colordata*  cd = &(colorproblem.root_cd);

    int ncolors;
    COLORset *colorclasses;


    COLORset*  debugcolors = (COLORset*) NULL;

    rval = COLORprogram_header (ac,av);
    COLORcheck_rval(rval, "Failed in COLORprogram_header");

    COLORproblem_init(&colorproblem);
    cd->id = 0;
    colorproblem.ncolordata = 1;

    rval = parseargs (ac, av,parms);
    if (rval) goto CLEANUP;

    cd->upper_bound = parms->initial_upper_bound;
    get_problem_name(cd->pname,parms->edgefile);

    printf ("Rounding strategy: ");
     switch (parms->rounding_strategy) {
     case COLOR_neighbor_rounding:
        printf("neighbor\n");
        break;
     case COLOR_uniform_rounding:
        printf("uniform\n");
        break;
     case COLOR_no_rounding:
        printf("none\n");
        break;
     }

    if (COLORdbg_lvl() > 1) printf ("Debugging turned on\n");
    fflush (stdout);


    rval = COLORread_dimacs (parms->edgefile, &(cd->ncount), &(cd->ecount),
                             &(cd->elist), (int **) NULL);
    COLORcheck_rval (rval, "COLORread_diamcs failed");

    if (cd->upper_bound > cd->ncount) {cd->upper_bound = cd->ncount;}

    if (colorproblem.parms.backupdir) {
       recover_colordata(cd,&colorproblem);
    }

    rval = COLORexact_coloring(&colorproblem,&ncolors, &colorclasses);
    COLORcheck_rval(rval, "Failed to COLORexact_coloring");

    if (cd->nbestcolors == cd->upper_bound) {
       printf ("Opt Colors: %d\n", cd->nbestcolors); fflush (stdout);
       print_colors(colorclasses, ncolors);
    } else if (cd->lower_bound == parms->initial_upper_bound) {
       printf("Lower bound reached predefined upper bound %d.\n",
              parms->initial_upper_bound);
    } else {
       printf("Finished with LB %d and UB %d.\n",
              cd->lower_bound, cd->upper_bound);

    }
    tot_rtime = COLORcpu_time() - start_time;
    printf("Computing coloring took %f seconds.\n",tot_rtime);


CLEANUP:

    COLORproblem_free(&colorproblem);
    COLORfree_sets(&colorclasses, &ncolors);

    COLOR_IFFREE(debugcolors,COLORset);

    return rval;
}
Exemplo n.º 7
0
/**
   set_color builtin
*/
static int builtin_set_color(parser_t &parser, wchar_t **argv)
{
    /** Variables used for parsing the argument list */
    const struct woption long_options[] =
    {
        { L"background", required_argument, 0, 'b'},
        { L"help", no_argument, 0, 'h' },
        { L"bold", no_argument, 0, 'o' },
        { L"underline", no_argument, 0, 'u' },
        { L"version", no_argument, 0, 'v' },
        { L"print-colors", no_argument, 0, 'c' },
        { 0, 0, 0, 0 }
    };

    const wchar_t *short_options = L"b:hvocu";

    int argc = builtin_count_args(argv);

    /* Some code passes variables to set_color that don't exist, like $fish_user_whatever. As a hack, quietly return failure. */
    if (argc <= 1)
    {
        return EXIT_FAILURE;
    }

    const wchar_t *bgcolor = NULL;
    bool bold = false, underline=false;
    int errret;

    /* Parse options to obtain the requested operation and the modifiers */
    woptind = 0;
    while (1)
    {
        int c = wgetopt_long(argc, argv, short_options, long_options, 0);

        if (c == -1)
        {
            break;
        }

        switch (c)
        {
            case 0:
                break;

            case 'b':
                bgcolor = woptarg;
                break;

            case 'h':
                builtin_print_help(parser, argv[0], stdout_buffer);
                return STATUS_BUILTIN_OK;

            case 'o':
                bold = true;
                break;

            case 'u':
                underline = true;
                break;

            case 'c':
                print_colors();
                return STATUS_BUILTIN_OK;

            case '?':
                return STATUS_BUILTIN_ERROR;
        }
    }

    /* Remaining argument is foreground color */
    const wchar_t *fgcolor = NULL;
    if (woptind < argc)
    {
        if (woptind + 1 == argc)
        {
            fgcolor = argv[woptind];
        }
        else
        {
            append_format(stderr_buffer,
                          _(L"%ls: Too many arguments\n"),
                          argv[0]);
            return STATUS_BUILTIN_ERROR;
        }
    }

    if (fgcolor == NULL && bgcolor == NULL && !bold && !underline)
    {
        append_format(stderr_buffer,
                      _(L"%ls: Expected an argument\n"),
                      argv[0]);
        return STATUS_BUILTIN_ERROR;
    }

    const rgb_color_t fg = rgb_color_t(fgcolor ? fgcolor : L"");
    if (fgcolor && (fg.is_none() || fg.is_ignore()))
    {
        append_format(stderr_buffer, _(L"%ls: Unknown color '%ls'\n"), argv[0], fgcolor);
        return STATUS_BUILTIN_ERROR;
    }

    const rgb_color_t bg = rgb_color_t(bgcolor ? bgcolor : L"");
    if (bgcolor && (bg.is_none() || bg.is_ignore()))
    {
        append_format(stderr_buffer, _(L"%ls: Unknown color '%ls'\n"), argv[0], bgcolor);
        return STATUS_BUILTIN_ERROR;
    }

    /* Make sure that the term exists */
    if (cur_term == NULL && setupterm(0, STDOUT_FILENO, &errret) == ERR)
    {
        append_format(stderr_buffer, _(L"%ls: Could not set up terminal\n"), argv[0]);
        return STATUS_BUILTIN_ERROR;
    }

    /*
       Test if we have at least basic support for setting fonts, colors
       and related bits - otherwise just give up...
    */
    if (! exit_attribute_mode)
    {
        return STATUS_BUILTIN_ERROR;
    }


    /* Save old output function so we can restore it */
    int (* const saved_writer_func)(char) = output_get_writer();

    /* Set our output function, which writes to a std::string */
    builtin_set_color_output.clear();
    output_set_writer(set_color_builtin_outputter);

    if (bold)
    {
        if (enter_bold_mode)
            writembs(tparm(enter_bold_mode));
    }

    if (underline)
    {
        if (enter_underline_mode)
            writembs(enter_underline_mode);
    }

    if (bgcolor != NULL)
    {
        if (bg.is_normal())
        {
            write_color(rgb_color_t::black(), false /* not is_fg */);
            writembs(tparm(exit_attribute_mode));
        }
    }

    if (fgcolor != NULL)
    {
        if (fg.is_normal() || fg.is_reset())
        {
            write_color(rgb_color_t::black(), true /* is_fg */);
            writembs(tparm(exit_attribute_mode));
        }
        else
        {
            write_color(fg, true /* is_fg */);
        }
    }

    if (bgcolor != NULL)
    {
        if (! bg.is_normal() && ! bg.is_reset())
        {
            write_color(bg, false /* not is_fg */);
        }
    }

    /* Restore saved writer function */
    output_set_writer(saved_writer_func);

    /* Output the collected string */
    stdout_buffer.append(str2wcstring(builtin_set_color_output));
    builtin_set_color_output.clear();

    return STATUS_BUILTIN_OK;
}
Exemplo n.º 8
0
int main( int argc, char **argv )
{
	char *bgcolor=0;
	char *fgcolor=0;
	bool bold=false;
	bool underline=false;

	while( 1 )
	{
		static struct option
			long_options[] =
			{
				{
					"background", required_argument, 0, 'b' 
				}
				,
				{
					"help", no_argument, 0, 'h' 
				}
				,
				{
					"bold", no_argument, 0, 'o' 
				}
				,
				{
					"underline", no_argument, 0, 'u' 
				}
				,
				{
					"version", no_argument, 0, 'v' 
				}
				,
				{
					"print-colors", no_argument, 0, 'c' 
				}
				,
				{ 
					0, 0, 0, 0 
				}
			}
		;		
		
		int opt_index = 0;
		
		int opt = getopt_long( argc,
							   argv, 
							   GETOPT_STRING, 
							   long_options, 
							   &opt_index );

		if( opt == -1 )
			break;
			
		switch( opt )
		{
			case 0:
				break;
				
			case 'b':				
				bgcolor = optarg;
				break;
			case 'h':
				print_help( argv[0], 1 );
				exit(0);				
								
			case 'o':
				bold=true;
				break;
				
			case 'u':
				underline=true;
				break;
				
			case 'v':
				check_locale_init();
				fprintf( stderr, _("%s, version %s\n"), SET_COLOR, PACKAGE_VERSION );
				exit( 0 );								

			case 'c':
				print_colors();
				exit(0);
				
			case '?':
				return 1;
				
		}
		
	}		
	
	switch( argc-optind)
	{
		case 0:
//			printf( "no fg\n" );
			break;
			
		case 1:
			fgcolor=argv[optind];
//			printf( "fg %s\n", fgcolor );
			break;
			
		default:
			check_locale_init();
			printf( _("%s: Too many arguments\n"), SET_COLOR );
			return 1;
	}
    
    /* Infer term256 support */
    char *fish_term256 = getenv("fish_term256");
    if (fish_term256) {
        support_term256 = from_string<bool>(fish_term256);
    } else {
        const char *term = getenv("TERM");
        support_term256 = term && strstr(term, "256color");
    }

	if( !fgcolor && !bgcolor && !bold && !underline )
	{
		check_locale_init();
		fprintf( stderr, _("%s: Expected an argument\n"), SET_COLOR );
		print_help( argv[0], 2 );		
		return 1;
	}
    
    rgb_color_t fg = rgb_color_t(fgcolor ? fgcolor : "");
	if( fgcolor && fg.is_none())
	{
		check_locale_init();
		fprintf( stderr, _("%s: Unknown color '%s'\n"), SET_COLOR, fgcolor );
		return 1;		
	}

    rgb_color_t bg = rgb_color_t(bgcolor ? bgcolor : "");
	if( bgcolor && bg.is_none())
	{
		check_locale_init();
		fprintf( stderr, _("%s: Unknown color '%s'\n"), SET_COLOR, bgcolor );
		return 1;		
	}

	setupterm( 0, STDOUT_FILENO, 0);

	if( bold )
	{
		if( enter_bold_mode )
			putp( enter_bold_mode );
	}

	if( underline )
	{
		if( enter_underline_mode )
			putp( enter_underline_mode );
	}

	if( bgcolor )
	{
		if( bg.is_normal() )
		{
            write_background_color(0);
			putp( tparm(exit_attribute_mode) );		
		}	
	}

	if( fgcolor )
	{
		if( fg.is_normal() )
		{
            write_foreground_color(0);
			putp( tparm(exit_attribute_mode) );		
		}	
		else
		{
            write_foreground_color(index_for_color(fg));
		}
	}
	
	if( bgcolor )
	{
		if( ! bg.is_normal() )
		{
            write_background_color(index_for_color(bg));
		}
	}

	if( del_curterm( cur_term ) == ERR )
	{
		fprintf( stderr, "%s", _("Error while closing terminfo") );
	}

}
Exemplo n.º 9
0
/*
 * Thanks to the following pages for info about this function:
 * http://css-tricks.com/css3-gradients/
 * http://webdesignerwall.com/tutorials/cross-browser-css-gradient
 * http://hacks.mozilla.org/2009/11/css-gradients-firefox-36/
 * http://www.tankedup-imaging.com/css_dev/css-gradient.html
 */
static void print_css_gradient(const char *fname, gradient g)
{
	char *points[] = { "left", "top", "left top", "right top" };
	char *w3points[] = { "to right", "to bottom", "to right bottom", "to left bottom" };
	char *wk_s_points[] = { "left top", "left top", "left top", "right top" };
	char *wk_e_points[] = { "right top", "left bottom", "right bottom", "left bottom" };
	int  rotations[]   = { 0, 90, 45, 135 };
	char *classname, *c;

	if(g.ncolors == 0) {
		return;
	}

	classname = (char *)calloc(strlen(fname)+1, 1);
	c=strrchr(fname, '/');
	if(c)
		c++;
	else
		c=(char *)fname;

	strcpy(classname, c);
	c=strchr(classname, '.');
	if(c) {
		*c='\0';
	}

	printf(".%s {\n", classname);

	/* Gecko */
	printf("\tbackground-image: -moz-linear-gradient(%s, ", points[g.start]);
	print_colors(&g, CSS3);
	printf(");\n");
	/* Safari 4+, Chrome 1+ */
	printf("\tbackground-image: -webkit-gradient(linear, %s, %s, ", wk_s_points[g.start], wk_e_points[g.start]);
	print_colors(&g, WEBKIT);
	printf(");\n");
	/* Safari 5.1+, Chrome 10+ */
	printf("\tbackground-image: -webkit-linear-gradient(%s, ", points[g.start]);
	print_colors(&g, CSS3);
	printf(");\n");
	/* Opera */
	printf("\tbackground-image: -o-linear-gradient(%s, ", points[g.start]);
	print_colors(&g, CSS3);
	printf(");\n");
	/* Unprefixed */
	printf("\tbackground-image: linear-gradient(%s, ", w3points[g.start]);
	print_colors(&g, CSS3);
	printf(");\n");

	printf("}\n");

	printf("graphics = graphics || {};\n");
	printf("graphics[\"%s\"] = new Y.Graphic({ render: '#%s' });\n", classname, classname);
	printf("graphics[\"%s\"].addShape({\n", classname);
	printf("\ttype: \"rect\",\n");
	printf("\theight: 200, width: 200,\n");
	printf("\tfill: {\n");
	printf("\t\ttype: \"linear\",\n");
	printf("\t\tstops: [\n");
	print_colors(&g, YUI3);
	printf("\t\t],\n");
	printf("\t\trotation: %d\n", rotations[g.start]);
	printf("\t}\n");
	printf("\n});\n");

	free(classname);
	free(g.colors);
	g.colors=NULL;
}
Exemplo n.º 10
0
/// set_color builtin.
int builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
    wgetopter_t w;
    // Variables used for parsing the argument list.
    const struct woption long_options[] = {{L"background", required_argument, 0, 'b'},
                                           {L"help", no_argument, 0, 'h'},
                                           {L"bold", no_argument, 0, 'o'},
                                           {L"underline", no_argument, 0, 'u'},
                                           {L"version", no_argument, 0, 'v'},
                                           {L"print-colors", no_argument, 0, 'c'},
                                           {0, 0, 0, 0}};

    const wchar_t *short_options = L"b:hvocu";

    int argc = builtin_count_args(argv);

    // Some code passes variables to set_color that don't exist, like $fish_user_whatever. As a
    // hack, quietly return failure.
    if (argc <= 1) {
        return EXIT_FAILURE;
    }

    const wchar_t *bgcolor = NULL;
    bool bold = false, underline = false;
    int errret;

    // Parse options to obtain the requested operation and the modifiers.
    w.woptind = 0;
    while (1) {
        int c = w.wgetopt_long(argc, argv, short_options, long_options, 0);

        if (c == -1) {
            break;
        }

        switch (c) {
            case 0: {
                break;
            }
            case 'b': {
                bgcolor = w.woptarg;
                break;
            }
            case 'h': {
                builtin_print_help(parser, streams, argv[0], streams.out);
                return STATUS_BUILTIN_OK;
            }
            case 'o': {
                bold = true;
                break;
            }
            case 'u': {
                underline = true;
                break;
            }
            case 'c': {
                print_colors(streams);
                return STATUS_BUILTIN_OK;
            }
            case '?': {
                return STATUS_BUILTIN_ERROR;
            }
        }
    }

    // Remaining arguments are foreground color.
    std::vector<rgb_color_t> fgcolors;
    for (; w.woptind < argc; w.woptind++) {
        rgb_color_t fg = rgb_color_t(argv[w.woptind]);
        if (fg.is_none()) {
            streams.err.append_format(_(L"%ls: Unknown color '%ls'\n"), argv[0], argv[w.woptind]);
            return STATUS_BUILTIN_ERROR;
        }
        fgcolors.push_back(fg);
    }

    if (fgcolors.empty() && bgcolor == NULL && !bold && !underline) {
        streams.err.append_format(_(L"%ls: Expected an argument\n"), argv[0]);
        return STATUS_BUILTIN_ERROR;
    }

    // #1323: We may have multiple foreground colors. Choose the best one. If we had no foreground
    // color, we'll get none(); if we have at least one we expect not-none.
    const rgb_color_t fg = best_color(fgcolors, output_get_color_support());
    assert(fgcolors.empty() || !fg.is_none());

    const rgb_color_t bg = rgb_color_t(bgcolor ? bgcolor : L"");
    if (bgcolor && bg.is_none()) {
        streams.err.append_format(_(L"%ls: Unknown color '%ls'\n"), argv[0], bgcolor);
        return STATUS_BUILTIN_ERROR;
    }

    // Make sure that the term exists.
    if (cur_term == NULL && setupterm(0, STDOUT_FILENO, &errret) == ERR) {
        streams.err.append_format(_(L"%ls: Could not set up terminal\n"), argv[0]);
        return STATUS_BUILTIN_ERROR;
    }

    // Test if we have at least basic support for setting fonts, colors and related bits - otherwise
    // just give up...
    if (!exit_attribute_mode) {
        return STATUS_BUILTIN_ERROR;
    }

    // Save old output function so we can restore it.
    int (*const saved_writer_func)(char) = output_get_writer();

    // Set our output function, which writes to a std::string.
    builtin_set_color_output.clear();
    output_set_writer(set_color_builtin_outputter);

    if (bold) {
        if (enter_bold_mode) writembs(tparm(enter_bold_mode));
    }

    if (underline) {
        if (enter_underline_mode) writembs(enter_underline_mode);
    }

    if (bgcolor != NULL) {
        if (bg.is_normal()) {
            write_color(rgb_color_t::black(), false /* not is_fg */);
            writembs(tparm(exit_attribute_mode));
        }
    }

    if (!fg.is_none()) {
        if (fg.is_normal() || fg.is_reset()) {
            write_color(rgb_color_t::black(), true /* is_fg */);
            writembs(tparm(exit_attribute_mode));
        } else {
            write_color(fg, true /* is_fg */);
        }
    }

    if (bgcolor != NULL) {
        if (!bg.is_normal() && !bg.is_reset()) {
            write_color(bg, false /* not is_fg */);
        }
    }

    // Restore saved writer function.
    output_set_writer(saved_writer_func);

    // Output the collected string.
    streams.out.append(str2wcstring(builtin_set_color_output));
    builtin_set_color_output.clear();

    return STATUS_BUILTIN_OK;
}
Exemplo n.º 11
0
/// set_color builtin.
int builtin_set_color(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
    // By the time this is called we should have initialized the curses subsystem.
    assert(curses_initialized);

    // Hack in missing italics and dim capabilities omitted from MacOS xterm-256color terminfo
    // Helps Terminal.app/iTerm
    #if __APPLE__
    const auto term_prog = parser.vars().get(L"TERM_PROGRAM");
    if (!term_prog.missing_or_empty() && (term_prog->as_string() == L"Apple_Terminal"
        || term_prog->as_string() == L"iTerm.app")) {
        const auto term = parser.vars().get(L"TERM");
        if (!term.missing_or_empty() && (term->as_string() == L"xterm-256color")) {
            enter_italics_mode = sitm_esc;
            exit_italics_mode = ritm_esc;
            enter_dim_mode = dim_esc;
        }
    }
    #endif

    // Variables used for parsing the argument list.
    wchar_t *cmd = argv[0];
    int argc = builtin_count_args(argv);

    // Some code passes variables to set_color that don't exist, like $fish_user_whatever. As a
    // hack, quietly return failure.
    if (argc <= 1) {
        return EXIT_FAILURE;
    }

    const wchar_t *bgcolor = NULL;
    bool bold = false, underline = false, italics = false, dim = false, reverse = false;

    // Parse options to obtain the requested operation and the modifiers.
    int opt;
    wgetopter_t w;
    while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
        switch (opt) {
            case 'b': {
                bgcolor = w.woptarg;
                break;
            }
            case 'h': {
                builtin_print_help(parser, streams, argv[0], streams.out);
                return STATUS_CMD_OK;
            }
            case 'o': {
                bold = true;
                break;
            }
            case 'i': {
                italics = true;
                break;
            }
            case 'd': {
                dim = true;
                break;
            }
            case 'r': {
                reverse = true;
                break;
            }
            case 'u': {
                underline = true;
                break;
            }
            case 'c': {
                print_colors(streams);
                return STATUS_CMD_OK;
            }
            case ':': {
                builtin_missing_argument(parser, streams, cmd, argv[w.woptind - 1]);
                return STATUS_INVALID_ARGS;
            }
            case '?': {
                return STATUS_INVALID_ARGS;
            }
            default: {
                DIE("unexpected retval from wgetopt_long");
                break;
            }
        }
    }

    // Remaining arguments are foreground color.
    std::vector<rgb_color_t> fgcolors;
    for (; w.woptind < argc; w.woptind++) {
        rgb_color_t fg = rgb_color_t(argv[w.woptind]);
        if (fg.is_none()) {
            streams.err.append_format(_(L"%ls: Unknown color '%ls'\n"), argv[0], argv[w.woptind]);
            return STATUS_INVALID_ARGS;
        }
        fgcolors.push_back(fg);
    }

    if (fgcolors.empty() && bgcolor == NULL && !bold && !underline && !italics && !dim &&
        !reverse) {
        streams.err.append_format(_(L"%ls: Expected an argument\n"), argv[0]);
        return STATUS_INVALID_ARGS;
    }

    // #1323: We may have multiple foreground colors. Choose the best one. If we had no foreground
    // color, we'll get none(); if we have at least one we expect not-none.
    const rgb_color_t fg = best_color(fgcolors, output_get_color_support());
    assert(fgcolors.empty() || !fg.is_none());

    const rgb_color_t bg = rgb_color_t(bgcolor ? bgcolor : L"");
    if (bgcolor && bg.is_none()) {
        streams.err.append_format(_(L"%ls: Unknown color '%ls'\n"), argv[0], bgcolor);
        return STATUS_INVALID_ARGS;
    }

    // Test if we have at least basic support for setting fonts, colors and related bits - otherwise
    // just give up...
    if (cur_term == NULL || !exit_attribute_mode) {
        return STATUS_CMD_ERROR;
    }
    outputter_t outp;

    if (bold && enter_bold_mode) {
        writembs_nofail(outp, tparm((char *)enter_bold_mode));
    }

    if (underline && enter_underline_mode) {
        writembs_nofail(outp, enter_underline_mode);
    }

    if (italics && enter_italics_mode) {
        writembs_nofail(outp, enter_italics_mode);
    }

    if (dim && enter_dim_mode) {
        writembs_nofail(outp, enter_dim_mode);
    }

    if (reverse && enter_reverse_mode) {
        writembs_nofail(outp, enter_reverse_mode);
    } else if (reverse && enter_standout_mode) {
        writembs_nofail(outp, enter_standout_mode);
    }

    if (bgcolor != NULL && bg.is_normal()) {
        writembs_nofail(outp, tparm((char *)exit_attribute_mode));
    }

    if (!fg.is_none()) {
        if (fg.is_normal() || fg.is_reset()) {
            writembs_nofail(outp, tparm((char *)exit_attribute_mode));
        } else {
            if (!outp.write_color(fg, true /* is_fg */)) {
                // We need to do *something* or the lack of any output messes up
                // when the cartesian product here would make "foo" disappear:
                //  $ echo (set_color foo)bar
                outp.set_color(rgb_color_t::reset(), rgb_color_t::none());
            }
        }
    }

    if (bgcolor != NULL && !bg.is_normal() && !bg.is_reset()) {
        outp.write_color(bg, false /* not is_fg */);
    }

    // Output the collected string.
    streams.out.append(str2wcstring(outp.contents()));

    return STATUS_CMD_OK;
}