]> Kevux Git Server - fll/commitdiff
Update: Move hardcoded strings into a const static string for f_color.
authorKevin Day <thekevinday@gmail.com>
Thu, 17 Feb 2022 03:52:16 +0000 (21:52 -0600)
committerKevin Day <thekevinday@gmail.com>
Thu, 17 Feb 2022 03:52:16 +0000 (21:52 -0600)
level_0/f_color/c/color.c
level_0/f_color/c/color/common.c
level_0/f_color/c/color/common.h

index 34eea152c9d447f683b441c7f58bd568cc1d2624..6433c35331342afe42501aba54c07d9fd1b03521 100644 (file)
@@ -12,9 +12,9 @@ extern "C" {
 
     // Switch to the appropriate terminal color mode.
     {
-      char *environment = getenv("TERM"); // @todo make these strings static!
+      char *environment = getenv(f_color_terminal_name_s.string);
 
-      if (!environment || strncmp(environment, "linux", 6) == 0) {
+      if (!environment || strncmp(environment, f_color_terminal_value_linux_s.string, f_color_terminal_value_linux_s.used) == 0) {
         macro_f_color_t_set_linux(context->list);
       }
       else {
index bf7c1378772231cc803bcc59f08f81901c34c58d..1a81e3865175d871780af9b2116a14056b3dd350 100644 (file)
@@ -49,6 +49,11 @@ extern "C" {
   const f_string_static_t f_color_string_code_bright_white_bg_s = macro_f_string_static_t_initialize(F_color_string_code_bright_white_bg_s, 0, F_color_string_code_bright_white_bg_s_length);
 #endif // _di_f_color_strings_s_
 
+#ifndef _di_f_color_terminal_s_
+  const f_string_static_t f_color_terminal_name_s = macro_f_string_static_t_initialize(F_color_terminal_name_s, 0, F_color_terminal_name_s_length);
+  const f_string_static_t f_color_terminal_value_linux_s = macro_f_string_static_t_initialize(F_color_terminal_value_linux_s, 0, F_color_terminal_value_linux_s_length);
+#endif // _di_f_color_terminal_s_
+
 #ifndef _di_f_color_set_string_empty_s_
   const f_color_set_t f_color_set_empty_s = macro_f_color_set_t_initialize(&f_string_empty_s, &f_string_empty_s);
 #endif // _di_f_color_set_string_empty_s_
index bd56468657ea83e6d394b850e5161af911ff1ed9..24a399a0bd839b004edf2f54d5033b403c6e7961 100644 (file)
@@ -45,6 +45,24 @@ extern "C" {
 #endif // _di_f_color_code_t_
 
 /**
+ * Terminal environment variable strings that may relate to color processing.
+ *
+ * f_color_terminal_*:
+ *   - name:        The standard terminal environment variable name.
+ *   - value_linux: The value representing the Linux terminal.
+ */
+#ifndef _di_f_color_terminal_s_
+  #define F_color_terminal_name_s        "TERM"
+  #define F_color_terminal_value_linux_s "linux"
+
+  #define F_color_terminal_name_s_length        4
+  #define F_color_terminal_value_linux_s_length 5
+
+  extern const f_string_static_t f_color_terminal_name_s;
+  extern const f_string_static_t f_color_terminal_value_linux_s;
+#endif // _di_f_color_terminal_s_
+
+/**
  * Provide a global color related strings.
  *
  * F_color_string_*: