Changeset 9e596f5 for functions.c


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>
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.