Changeset 9e596f5


Ignore:
Timestamp:
Mar 3, 2018, 5:01:51 AM (6 years ago)
Author:
Anders Kaseorg <andersk@mit.edu>
Branches:
master
Children:
396dc2c
Parents:
0480eef
git-author:
Anders Kaseorg <andersk@mit.edu> (03/03/18 04:56:54)
git-committer:
Anders Kaseorg <andersk@mit.edu> (03/03/18 05:01:51)
Message:
Allow changing the fg + bg colors of an existing filter simutaneously

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • filter.c

    r7dcef03 r9e596f5  
    1616owl_filter *owl_filter_new(const char *name, int argc, const char *const *argv)
    1717{
     18  return owl_filter_new_colored(name, argc, argv, OWL_COLOR_DEFAULT, OWL_COLOR_DEFAULT);
     19}
     20
     21owl_filter *owl_filter_new_colored(const char *name, int argc, const char *const *argv, int fgcolor, int bgcolor)
     22{
    1823  owl_filter *f;
    1924
     
    2126
    2227  f->name=g_strdup(name);
    23   f->fgcolor=OWL_COLOR_DEFAULT;
    24   f->bgcolor=OWL_COLOR_DEFAULT;
    25 
    26   /* first take arguments that have to come first */
    27   /* set the color */
    28   while ( argc>=2 && ( !strcmp(argv[0], "-c") ||
    29                        !strcmp(argv[0], "-b") ) ) {
    30     if (owl_util_string_to_color(argv[1])==OWL_COLOR_INVALID) {
    31       owl_function_error("The color '%s' is not available, using default.", argv[1]);
    32     } else {
    33       switch (argv[0][1]) {
    34       case 'c':
    35         f->fgcolor=owl_util_string_to_color(argv[1]);
    36         break;
    37       case 'b':
    38         f->bgcolor=owl_util_string_to_color(argv[1]);
    39         break;
    40       }
    41     }
    42     argc-=2;
    43     argv+=2;
    44   }
     28  f->fgcolor = fgcolor;
     29  f->bgcolor = bgcolor;
    4530
    4631  if (!(f->root = owl_filter_parse_expression(argc, argv, NULL))) {
  • functions.c

    r4fd3c04 r9e596f5  
    19801980  const owl_view *v;
    19811981  int inuse = 0;
     1982  int i = 2;
     1983  int fgcolor = OWL_COLOR_DEFAULT;
     1984  bool set_fgcolor = false;
     1985  int bgcolor = OWL_COLOR_DEFAULT;
     1986  bool set_bgcolor = false;
    19821987
    19831988  if (argc < 2) {
     
    19962001  }
    19972002
    1998   /* deal with the case of trying change the filter color */
    1999   if (argc==4 && !strcmp(argv[2], "-c")) {
     2003  /* set the color */
     2004  while (i + 2 <= argc && (!strcmp(argv[i], "-c") ||
     2005                           !strcmp(argv[i], "-b"))) {
     2006    int color = owl_util_string_to_color(argv[i + 1]);
     2007    if (color == OWL_COLOR_INVALID) {
     2008      owl_function_error("The color '%s' is not available.", argv[i + 1]);
     2009    } else if (argv[i][1] == 'c') {
     2010      fgcolor = color;
     2011      set_fgcolor = true;
     2012    } else {
     2013      bgcolor = color;
     2014      set_bgcolor = true;
     2015    }
     2016    i += 2;
     2017  }
     2018
     2019  if (i > 2 && i == argc) {
    20002020    f=owl_global_get_filter(&g, argv[1]);
    20012021    if (!f) {
     
    20032023      return false;
    20042024    }
    2005     if (owl_util_string_to_color(argv[3])==OWL_COLOR_INVALID) {
    2006       owl_function_error("The color '%s' is not available.", argv[3]);
     2025    if (!set_fgcolor && !set_bgcolor)
    20072026      return false;
    2008     }
    2009     owl_filter_set_fgcolor(f, owl_util_string_to_color(argv[3]));
    2010     owl_mainwin_redisplay(owl_global_get_mainwin(&g));
    2011     return false;
    2012   }
    2013   if (argc==4 && !strcmp(argv[2], "-b")) {
    2014     f=owl_global_get_filter(&g, argv[1]);
    2015     if (!f) {
    2016       owl_function_error("The filter '%s' does not exist.", argv[1]);
    2017       return false;
    2018     }
    2019     if (owl_util_string_to_color(argv[3])==OWL_COLOR_INVALID) {
    2020       owl_function_error("The color '%s' is not available.", argv[3]);
    2021       return false;
    2022     }
    2023     owl_filter_set_bgcolor(f, owl_util_string_to_color(argv[3]));
     2027    if (set_fgcolor)
     2028      owl_filter_set_fgcolor(f, fgcolor);
     2029    if (set_bgcolor)
     2030      owl_filter_set_bgcolor(f, bgcolor);
    20242031    owl_mainwin_redisplay(owl_global_get_mainwin(&g));
    20252032    return true;
     
    20272034
    20282035  /* create the filter and check for errors */
    2029   f = owl_filter_new(argv[1], argc-2, argv+2);
     2036  f = owl_filter_new_colored(argv[1], argc - i, argv + i, fgcolor, bgcolor);
    20302037  if (f == NULL) {
    20312038    owl_function_error("Invalid filter: %s", argv[1]);
Note: See TracChangeset for help on using the changeset viewer.