file coloring
- From: Kisel Jan <j kisel rambler ru>
- To: mc-devel gnome org
- Subject: file coloring
- Date: Sun, 13 Aug 2006 03:10:26 +0400
Good day!
I suggest you mc patch to apply file-coloring scheme based on file name pattern.
For using this possibility apply patch, then paste `file_color' variable to [Colors] section of your ~/.mc/ini file, formed like further:
------------
[Colors]
file_color=*.c,*.h,*.cpp=brown,blue:*.gz,*.tar,*.bz2,*.zip,*.rar,*.tgz,*.tbz,*.rpm=cyan,blue:*.avi,*.mpg,*.mp3=green,blue:*.ini,*.conf,*.cfg,*_conf,.*rc,.profile=magenta,blue
-------------
I realize that this patch realization is not well, but I'm sure that idia to inculcate such in mc will please many users.
Patch text (also can be found at ftp://85.21.236.244/pub/patches/mc-4.6.1/patch-fcolors):
--- src/color.orig Fri May 27 18:19:18 2005
+++ src/color.c Mon Jul 10 08:15:40 2006
@@ -165,4 +165,6 @@
"errdhotfocus=yellow,lightgray";
+struct fcolor file_colors[MAX_FILECOLORS];
+
#ifdef HAVE_SLANG
# define color_value(i) color_table [i].name
@@ -250,4 +252,37 @@
}
+/* Configure file-specified colors
+ */
+static void configure_fcolors_string(const char *the_fcolor_string) {
+ char *p, **pf, *scolor;
+ int i = 0;
+ const int start_color = ELEMENTS(color_map);
+ struct colorpair color;
+
+ if (!the_fcolor_string || *the_fcolor_string == 0)
+ return;
+ scolor = (char *)the_fcolor_string;
+
+ while (*scolor && i<MAX_FILECOLORS)
+ {
+ if ((p = strchr(scolor, '=')) != NULL) {
+ /* save mask list */
+ pf = &file_colors[i].fmask[0];
+ *p = 0;
+ *pf = strtok(scolor, ",");
+ while (*pf)
+ *++pf = strtok(NULL, ",");
+
+ scolor = p+1; /* point to color pair (fg,bg) */
+ get_two_colors(&scolor, &color);
+ mc_init_pair (i+start_color, color.fg, color.bg);
+ file_colors[i++].color = i+start_color;
+ } else break;
+ }
+ if (i < MAX_FILECOLORS)
+ file_colors[i].fmask[0] = 0;
+ /*g_free(scolor);*/
+}
+
static void configure_colors (void)
{
@@ -279,4 +314,5 @@
alarm_colors [3] = ERROR_HOT_FOCUS;
}
+static int max_index = 0;
void init_colors (void)
@@ -339,9 +375,9 @@
}
load_dialog_colors ();
+ configure_fcolors_string(setup_fcolor_string);
}
/* Functions necessary to implement syntax highlighting */
-static int max_index = 0;
static int
--- src/color.h.orig Thu Sep 2 02:33:43 2004
+++ src/color.h Mon Jul 10 07:52:37 2006
@@ -95,3 +95,11 @@
int try_alloc_color_pair (const char *fg, const char *bg);
+#define MAX_FILECOLORS 16
+struct fcolor {
+ char *fmask[16];
+ int color;
+};
+
+extern struct fcolor file_colors[];
+
#endif /* __COLOR_H */
--- src/screen.c.orig Fri May 27 18:19:18 2005
+++ src/screen.c Mon Jul 10 08:15:41 2006
@@ -20,4 +20,5 @@
#include <config.h>
+#include <fnmatch.h>
#include <string.h>
#include <stdio.h>
@@ -465,4 +466,6 @@
file_compute_color (int attr, file_entry *fe)
{
+ int setup_fcolor = 1;
+
switch (attr) {
case SELECTED:
@@ -510,4 +513,15 @@
return (CORE_COLOR);
+ if (setup_fcolor) {
+ int i;
+ char **pfm;
+
+ for (i=0; file_colors[i].fmask[0] && i < MAX_FILECOLORS; i++) {
+ pfm = &file_colors[i].fmask[0];
+ for (; *pfm; pfm++)
+ if (!fnmatch(*pfm, fe->fname, FNM_CASEFOLD))
+ return (file_colors[i].color);
+ }
+ }
return (NORMAL_COLOR);
}
--- src/setup.c.orig Fri May 27 18:19:18 2005
+++ src/setup.c Mon Jul 10 05:50:59 2006
@@ -69,4 +69,5 @@
char term_color_string [4096];
char color_terminal_string [512];
+char setup_fcolor_string [4096];
#define load_int(a,b,c) GetPrivateProfileInt(a,b,c,profile_name)
@@ -533,4 +534,7 @@
load_string ("Colors", "color_terminals", "",
color_terminal_string, sizeof (color_terminal_string));
+ /* Load file-specified colors */
+ load_string ("Colors", "file_color", "", setup_fcolor_string,
+ sizeof (setup_fcolor_string));
/* Load the directory history */
--- src/setup.h.orig Sun Aug 29 20:56:16 2004
+++ src/setup.h Mon Jul 10 05:49:43 2006
@@ -21,4 +21,5 @@
extern char term_color_string[];
extern char color_terminal_string[];
+extern char setup_fcolor_string[];
extern int startup_left_mode;
=========================================
Respectfully yours, Kisel Jan aka dkrot (j kisel rambler ru)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]