Changeset 9e596f5
- Timestamp:
- Mar 3, 2018, 5:01:51 AM (7 years ago)
- 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)
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
filter.c
r7dcef03 r9e596f5 16 16 owl_filter *owl_filter_new(const char *name, int argc, const char *const *argv) 17 17 { 18 return owl_filter_new_colored(name, argc, argv, OWL_COLOR_DEFAULT, OWL_COLOR_DEFAULT); 19 } 20 21 owl_filter *owl_filter_new_colored(const char *name, int argc, const char *const *argv, int fgcolor, int bgcolor) 22 { 18 23 owl_filter *f; 19 24 … … 21 26 22 27 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; 45 30 46 31 if (!(f->root = owl_filter_parse_expression(argc, argv, NULL))) { -
functions.c
r4fd3c04 r9e596f5 1980 1980 const owl_view *v; 1981 1981 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; 1982 1987 1983 1988 if (argc < 2) { … … 1996 2001 } 1997 2002 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) { 2000 2020 f=owl_global_get_filter(&g, argv[1]); 2001 2021 if (!f) { … … 2003 2023 return false; 2004 2024 } 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) 2007 2026 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); 2024 2031 owl_mainwin_redisplay(owl_global_get_mainwin(&g)); 2025 2032 return true; … … 2027 2034 2028 2035 /* 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); 2030 2037 if (f == NULL) { 2031 2038 owl_function_error("Invalid filter: %s", argv[1]);
Note: See TracChangeset
for help on using the changeset viewer.