Switch to using a color scheme per file.

On Distro's we want to be able to ship color schemes as packages
as such we need an easy way to add and remove them this commit
implements the simplest possible solution of one color scheme per
file.
devs/simotek/colorschemes
Simon Lees 9 months ago
parent 1adc9116f1
commit f73a806868
  1. 9
      data/colorschemes/add_color_scheme.sh
  2. 18
      data/colorschemes/builder.sh
  3. 16
      data/colorschemes/meson.build
  4. 176
      src/bin/colors.c

@ -6,8 +6,6 @@ COMPRESS=1
EET=$1
shift
EET_FILE=$1
shift
INI=$1
shift
@ -22,9 +20,14 @@ TMP_DESC=$(mktemp "$NAME-DESC-XXXXXX")
# trap to avoid creating orphan files
trap 'rm -f "$TMP_DESC"' INT TERM HUP EXIT
NAME=$($GET_NAME "$INI")
mkdir -p "data/colorschemes"
EET_FILE="data/colorschemes/$NAME.eet"
[ ! -w "$EET_FILE" ] && touch "$EET_FILE"
NAME=$($GET_NAME "$INI")
echo "Generating $EET_FILE"
$INI2DESC "$INI" "$TMP_DESC"
$EET -e "$EET_FILE" "$NAME" "$TMP_DESC" "$COMPRESS"

@ -1,26 +1,14 @@
#!/bin/sh
#!/bin/bash
set -e
set -u
EET=$1
shift
OUTPUT=$1
shift
ADD_COLOR_SCHEME=$(dirname "$0")/add_color_scheme.sh
# work on a temporary file till every insertion worked
TMP_EET=$(mktemp "$OUTPUT-XXXXXX")
# trap to avoid creating orphan files
trap 'rm -f "$TMP_EET"' INT TERM HUP EXIT
for INI in "$@"
do
echo "Building $INI"
# use the name, without extension as key in eet
$ADD_COLOR_SCHEME "$EET" "$TMP_EET" "$INI"
$ADD_COLOR_SCHEME "$EET" "$INI"
done
# atomic rename to the expected output file
mv "$TMP_EET" "$OUTPUT"
# file successfully renamed, so need to trap to rename temp file
trap - INT TERM HUP EXIT

@ -21,18 +21,26 @@ colorschemes_desc = [
'Tango Light.ini',
'Tomorrow Night Burns.ini',
]
colorschemes_out = []
foreach c : colorschemes_desc
colorschemes_out += c.replace('ini','eet')
endforeach
cs_builder = [join_paths(meson.source_root(),
'data', 'colorschemes', 'builder.sh'),
eet_bin, '@OUTPUT@', '@INPUT@']
eet_bin, '@INPUT@']
cs_install_dir = join_paths(get_option('datadir'),
meson.project_name())
meson.project_name(),
'colorschemes')
custom_target('colorschemes.eet',
custom_target('colorschemes',
install:true,
install_dir: cs_install_dir,
install_mode: 'rw-r--r--',
depend_files: ['builder.sh', 'ini2desc.py', 'get_name.py', 'add_color_scheme.sh'],
command: cs_builder,
input: colorschemes_desc,
output: 'colorschemes.eet')
output: colorschemes_out)

@ -659,7 +659,7 @@ _color_scheme_get_from_file(const char *path, const char *name)
ef = eet_open(path, EET_FILE_MODE_READ);
if (!ef)
return NULL;
return NULL;
cs = eet_data_read(ef, edd_cs, name);
eet_close(ef);
@ -676,12 +676,12 @@ _color_scheme_get(const char *name)
Color_Scheme *cs_app;
snprintf(path_user, sizeof(path_user) - 1,
"%s/terminology/" COLORSCHEMES_FILENAME,
efreet_config_home_get());
"%s/terminology/colorschemes/%s.eet",
efreet_config_home_get(), name);
snprintf(path_app, sizeof(path_app) - 1,
"%s/" COLORSCHEMES_FILENAME,
elm_app_data_dir_get());
"%s/colorschemes/%s.eet",
elm_app_data_dir_get(), name);
cs_user = _color_scheme_get_from_file(path_user, name);
cs_app = _color_scheme_get_from_file(path_app, name);
@ -699,7 +699,10 @@ _color_scheme_get(const char *name)
else if (cs_app)
return cs_app;
else
return NULL;
{
ERR("failed find colorscheme '%s'", name);
return NULL;
}
}
void
@ -731,104 +734,91 @@ Eina_List *
color_scheme_list(void)
{
Eina_List *l = NULL;
static char path_user[PATH_MAX] = "";
static char path_app[PATH_MAX] = "";
Eet_File *ef_app = NULL;
Eet_File *ef_user = NULL;
Eina_List *dir = NULL;
Eina_List *name_list = NULL;
Eina_List *search_paths = NULL;
static char buf[PATH_MAX] = "";
char *file;
char *sp;
Eet_File *ef = NULL;
Eina_Iterator *it = NULL;
Eet_Entry *entry;
Color_Scheme *cs_user;
Color_Scheme *cs_app;
Color_Scheme *cs;
const char *current_name;
snprintf(path_user, sizeof(path_user) - 1,
"%s/terminology/" COLORSCHEMES_FILENAME,
/* Search homedir first, so color classes there get used */
snprintf(buf, sizeof(buf) - 1,
"%s/terminology/colorchemes",
efreet_config_home_get());
snprintf(path_app, sizeof(path_app) - 1,
"%s/" COLORSCHEMES_FILENAME,
search_paths = eina_list_append(search_paths, eina_stringshare_add(buf));
snprintf(buf, sizeof(buf) - 1,
"%s/colorschemes",
elm_app_data_dir_get());
search_paths = eina_list_append(search_paths, eina_stringshare_add(buf));
/* Add default theme */
cs_app = malloc(sizeof(*cs_app));
if (!cs_app)
cs = malloc(sizeof(*cs));
if (!cs)
return NULL;
memcpy(cs_app, &default_colorscheme, sizeof(*cs_app));
l = eina_list_sorted_insert(l, color_scheme_cmp, cs_app);
ef_app = eet_open(path_app, EET_FILE_MODE_READ);
if (!ef_app)
{
ERR("failed to open '%s'", path_app);
goto end;
memcpy(cs, &default_colorscheme, sizeof(*cs));
l = eina_list_sorted_insert(l, color_scheme_cmp, cs);
/* Make sure default theme is the only theme */
name_list = eina_list_append(name_list, eina_stringshare_add("Default"));
EINA_LIST_FREE(search_paths, sp)
{
dir = ecore_file_ls(sp);
EINA_LIST_FREE(dir, file)
{
snprintf(buf, sizeof(buf), "%s/%s", sp, file);
if ((!ecore_file_is_dir(buf)) && (ecore_file_size(buf) > 0))
{
if (eina_str_has_extension(file, ".eet"))
{
ef = eet_open(buf, EET_FILE_MODE_READ);
if (!ef)
{
ERR("failed to open '%s'", buf);
continue;
}
it = eet_list_entries(ef);
if (!it)
{
ERR("failed to list entries in '%s'", buf);
continue;
}
EINA_ITERATOR_FOREACH(it, entry)
{
/* If we already have a cs with this name skip it */
current_name = eina_stringshare_add(entry->name);
if (eina_list_data_find_list(name_list, current_name))
{
WRN("Skipping loading '%s' from '%s' color scheme exists already",
entry->name, buf);
eina_stringshare_del(entry->name);
continue;
}
cs = eet_data_read(ef, edd_cs, entry->name);
if (!cs)
{
ERR("failed to load color scheme '%s' from '%s'",
entry->name, buf);
eina_stringshare_del(entry->name);
continue;
}
l = eina_list_sorted_insert(l, color_scheme_cmp, cs);
name_list = eina_list_append(name_list, current_name);
}
eet_close(ef);
}
}
free(file);
}
}
ef_user = eet_open(path_user, EET_FILE_MODE_READ);
if (ef_user)
{
it = eet_list_entries(ef_user);
if (!it)
{
ERR("failed to list entries in '%s'", path_user);
goto end;
}
EINA_ITERATOR_FOREACH(it, entry)
{
cs_user = eet_data_read(ef_user, edd_cs, entry->name);
if (!cs_user)
{
ERR("failed to load color scheme '%s' from '%s'",
entry->name, path_user);
continue;
}
cs_app = eet_data_read(ef_app, edd_cs, entry->name);
if (cs_app)
{
/* Prefer user file */
if (cs_user->md.version >= cs_app->md.version)
l = eina_list_sorted_insert(l, color_scheme_cmp, cs_user);
else
free(cs_user);
free(cs_app);
}
else
l = eina_list_sorted_insert(l, color_scheme_cmp, cs_user);
}
}
it = eet_list_entries(ef_app);
if (!it)
{
ERR("failed to list entries in '%s'", path_app);
goto end;
}
EINA_ITERATOR_FOREACH(it, entry)
{
cs_app = eet_data_read(ef_app, edd_cs, entry->name);
if (!cs_app)
{
ERR("failed to load color scheme '%s' from '%s'",
entry->name, path_app);
continue;
}
cs_user = eet_data_read(ef_user, edd_cs, entry->name);
if (cs_user)
{
/* Prefer user file if higher version */
if (cs_user->md.version < cs_app->md.version)
l = eina_list_sorted_insert(l, color_scheme_cmp, cs_app);
else
free(cs_app);
free(cs_user);
}
else
l = eina_list_sorted_insert(l, color_scheme_cmp, cs_app);
}
end:
eina_iterator_free(it);
if (ef_app)
eet_close(ef_app);
if (ef_user)
eet_close(ef_user);
return l;
}

Loading…
Cancel
Save