@@ -204,25 +204,31 @@ endif()
204204# Text data #
205205#############
206206
207- function (fastfetch_load_text FILENAME OUTVAR )
208- file (READ "${FILENAME} " TEMP )
209- string (REGEX REPLACE "\n $" "" TEMP "${TEMP} " ) # Remove trailing newline
210- string (REPLACE "\n " "\\ n" TEMP "${TEMP} " ) # Replace newlines with \n
211- string (REPLACE "\" " "\\\" " TEMP "${TEMP} " ) # Replace quotes with \"
212- string (REPLACE "$\\ " "" TEMP "${TEMP} " ) # Remove $\, so we can unescape some things
213- set ("${OUTVAR} " "${TEMP} " PARENT_SCOPE )
214- endfunction (fastfetch_load_text )
215-
216- function (fastfetch_load_raw_text FILENAME OUTVAR )
217- file (READ "${FILENAME} " TEMP )
218- string (REGEX REPLACE "\n $" "" TEMP "${TEMP} " ) # Remove trailing newline
207+ function (fastfetch_encode_c_string STR OUTVAR )
208+ string (REGEX REPLACE "\n $" "" TEMP "${STR} " ) # Remove trailing newline
219209 string (REPLACE "\\ " "\\\\ " TEMP "${TEMP} " ) # Escape backslashes
220210 string (REPLACE "\n " "\\ n" TEMP "${TEMP} " ) # Replace newlines with \n
221211 string (REPLACE "\" " "\\\" " TEMP "${TEMP} " ) # Replace quotes with \"
222212 set (${OUTVAR} "\" ${TEMP} \" " PARENT_SCOPE )
223- endfunction (fastfetch_load_raw_text )
213+ endfunction (fastfetch_encode_c_string )
214+
215+ function (fastfetch_load_text FILENAME OUTVAR )
216+ file (READ "${FILENAME} " TEMP )
217+ fastfetch_encode_c_string ("${TEMP} " TEMP )
218+ set (${OUTVAR} "${TEMP} " PARENT_SCOPE )
219+ endfunction (fastfetch_load_text )
220+
221+ find_package (Python )
222+ if (Python_FOUND)
223+ # Minify JSON string. `io.open(0,encoding='utf-8')` is needed to avoid encoding issues on Windows
224+ execute_process (COMMAND ${Python_EXECUTABLE} -c "import io,json,sys;json.dump(json.load(io.open(0,encoding='utf-8')),sys.stdout,separators=(',', ':'),ensure_ascii=False)"
225+ INPUT_FILE "${CMAKE_CURRENT_SOURCE_DIR} /src/data/help.json"
226+ OUTPUT_VARIABLE DATATEXT_JSON_HELP )
227+ else ()
228+ file (READ "src/data/help.json" TEMP )
229+ endif ()
224230
225- fastfetch_load_raw_text ( src/data/help.json DATATEXT_JSON_HELP )
231+ fastfetch_encode_c_string ( " ${DATATEXT_JSON_HELP} " DATATEXT_JSON_HELP )
226232fastfetch_load_text (src/data/structure.txt DATATEXT_STRUCTURE )
227233fastfetch_load_text (src/data/help.txt DATATEXT_HELP )
228234fastfetch_load_text (src/data/help_color.txt DATATEXT_HELP_COLOR )
@@ -245,7 +251,7 @@ configure_file(doc/fastfetch.1.in fastfetch.1 @ONLY)
245251file (GLOB LOGO_FILES "src/logo/ascii/*.txt" )
246252set (LOGO_BUILTIN_H "#pragma once\n\n " )
247253foreach (file ${LOGO_FILES} )
248- fastfetch_load_raw_text ("${file} " content )
254+ fastfetch_load_text ("${file} " content )
249255 get_filename_component (file "${file} " NAME_WLE )
250256 string (TOUPPER "${file} " file)
251257 string (REGEX REPLACE "\\ $\\ {c([0-9]+)\\ }" "$\\ 1" content "${content} " )
0 commit comments