Skip to content

Commit

Permalink
Help: convert to parsable JSON format
Browse files Browse the repository at this point in the history
  • Loading branch information
CarterLi committed Nov 20, 2023
1 parent 5338583 commit 03916b6
Show file tree
Hide file tree
Showing 5 changed files with 1,476 additions and 269 deletions.
19 changes: 10 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,16 @@ function(fastfetch_load_text FILENAME OUTVAR)
set("${OUTVAR}" "${TEMP}" PARENT_SCOPE)
endfunction(fastfetch_load_text)

function(fastfetch_load_raw_text FILENAME OUTVAR)
file(READ "${FILENAME}" TEMP)
string(REGEX REPLACE "\n$" "" TEMP "${TEMP}") # Remove trailing newline
string(REPLACE "\\" "\\\\" TEMP "${TEMP}") # Escape backslashes
string(REPLACE "\n" "\\n" TEMP "${TEMP}") # Replace newlines with \n
string(REPLACE "\"" "\\\"" TEMP "${TEMP}") # Replace quotes with \"
set(${OUTVAR} "\"${TEMP}\"" PARENT_SCOPE)
endfunction(fastfetch_load_raw_text)

fastfetch_load_raw_text(src/data/help.json DATATEXT_JSON_HELP)
fastfetch_load_text(src/data/structure.txt DATATEXT_STRUCTURE)
fastfetch_load_text(src/data/help.txt DATATEXT_HELP)
fastfetch_load_text(src/data/help_color.txt DATATEXT_HELP_COLOR)
Expand All @@ -232,15 +242,6 @@ configure_file(doc/fastfetch.1.in fastfetch.1 @ONLY)
# Ascii image data #
####################

function(fastfetch_load_raw_text FILENAME OUTVAR)
file(READ "${FILENAME}" TEMP)
string(REGEX REPLACE "\n$" "" TEMP "${TEMP}") # Remove trailing newline
string(REPLACE "\\" "\\\\" TEMP "${TEMP}") # Escape backslashes
string(REPLACE "\n" "\\n" TEMP "${TEMP}") # Replace newlines with \n
string(REPLACE "\"" "\\\"" TEMP "${TEMP}") # Replace quotes with \"
set(${OUTVAR} "\"${TEMP}\"" PARENT_SCOPE)
endfunction(fastfetch_load_raw_text)

file(GLOB LOGO_FILES "src/logo/ascii/*.txt")
set(LOGO_BUILTIN_H "#pragma once\n\n")
foreach(file ${LOGO_FILES})
Expand Down
Loading

0 comments on commit 03916b6

Please sign in to comment.