Skip to content

Commit

Permalink
ChafaTermDb, ChafaTermInfo: Construct three-part identifiers and ':' …
Browse files Browse the repository at this point in the history
…chains
  • Loading branch information
hpjansson committed Nov 10, 2024
1 parent 682ce3b commit 7a46a7d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
29 changes: 28 additions & 1 deletion chafa/chafa-term-db.c
Original file line number Diff line number Diff line change
Expand Up @@ -866,15 +866,41 @@ match_term_def (const TermDef *term_def, gchar **envp)
return best_pri;
}

/* Terminal identifiers have three parts: name, variant and version.
* Either or both of variant and version can be omitted. If version is
* present but variant isn't, variant is replaced with a "*" placeholder.
*
* Examples of syntactically valid identifiers:
*
* vte
* vte-256color
* mlterm-*-3.9.3
* xterm-256color-XTerm(389)
*/
static gchar *
term_def_to_name (const TermDef *def)
{
const gchar *parts [3];

parts [0] = def->name ? def->name : "unknown";
parts [1] = def->variant ? def->variant : (def->version ? "*" : NULL);
parts [2] = def->version;

return g_strjoin ("-", parts [0], parts [1], parts [2], NULL);
}

static ChafaTermInfo *
new_term_info_from_def (const TermDef *def)
{
const SeqStr * const *seqs = def->seqs;
ChafaTermInfo *ti;
gchar *name;
gint i;

name = term_def_to_name (def);

ti = chafa_term_info_new ();
chafa_term_info_set_name (ti, def->name);
chafa_term_info_set_name (ti, name);
chafa_term_info_set_safe_symbol_tags (ti, def->safe_symbol_tags);

for (i = 0; i < SEQ_LIST_MAX && seqs [i]; i++)
Expand All @@ -893,6 +919,7 @@ new_term_info_from_def (const TermDef *def)
chafa_term_info_set_inherit_seq (ti, def->inherit_seqs [i], TRUE);
}

g_free (name);
return ti;
}

Expand Down
12 changes: 12 additions & 0 deletions chafa/chafa-term-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,8 @@ ChafaTermInfo *
chafa_term_info_chain (ChafaTermInfo *outer, ChafaTermInfo *inner)
{
ChafaTermInfo *chained;
const gchar *outer_name, *inner_name;
gchar *new_name;
gint i;

chained = chafa_term_info_copy (outer);
Expand All @@ -1411,6 +1413,16 @@ chafa_term_info_chain (ChafaTermInfo *outer, ChafaTermInfo *inner)
}
}

outer_name = chafa_term_info_get_name (outer);
inner_name = chafa_term_info_get_name (inner);

new_name = g_strjoin (":",
inner_name ? inner_name : "unknown",
outer_name ? outer_name : "unknown",
NULL);
chafa_term_info_set_name (chained, new_name);
g_free (new_name);

return chained;
}

Expand Down

0 comments on commit 7a46a7d

Please sign in to comment.