#pragma TextEncoding = "UTF-8" #pragma rtGlobals=3 // Use modern global access method and strict wave access #pragma DefaultTab={3,20,4} // Set default tab width in Igor Pro 9 and later function loadTheme() Variable refnum String fileFilters = "Themes (*.yml,*.yaml):.yml,.yaml;" Open/R/F=(fileFilters) refnum if (strlen(S_fileName) == 0 || refnum == 0) return 0 endif String line = "" String themeName = "" Variable validTheme = 0 Make/FREE/T/N=(0) themeColors do FReadLine refnum, line if (strlen(line) == 0) break endif String key, value SplitString/E="\\s*(.*):\\s*(.*)" line, key, value strswitch (key) case "theme": validTheme = 1 break case "name": themeName = value break case "keyword": case "comment": case "string": case "operation": case "bifunction": case "userfunction": case "directive": case "opkey": STRUCT RGBColor color colorFromHTML(value, color) SetSyntaxColor(key, color) break default: continue endswitch if (validTheme == 0) Print "Invalid theme file" break endif while(1) Close refnum end static function SetSyntaxColor(String key, STRUCT RGBColor& color) String command strswitch (key) case "keyword": sprintf command, "SetIgorOption colorize, keywordColor = (%d, %d, %d)", color.red, color.green, color.blue break case "comment": sprintf command, "SetIgorOption colorize, commentColor = (%d, %d, %d)", color.red, color.green, color.blue break case "string": sprintf command, "SetIgorOption colorize, stringColor = (%d, %d, %d)", color.red, color.green, color.blue break case "operation": sprintf command, "SetIgorOption colorize, operationColor = (%d, %d, %d)", color.red, color.green, color.blue break case "bifunction": sprintf command, "SetIgorOption colorize, functionColor = (%d, %d, %d)", color.red, color.green, color.blue break case "userfunction": sprintf command, "SetIgorOption colorize, userFunctionColor = (%d, %d, %d)", color.red, color.green, color.blue break case "directive": sprintf command, "SetIgorOption colorize, poundColor = (%d, %d, %d)", color.red, color.green, color.blue break case "opkey": sprintf command, "SetIgorOption colorize, specialFunctionColor = (%d, %d, %d)", color.red, color.green, color.blue break default: return 0 endswitch Execute/Z command end static function colorFromHTML(String html, STRUCT RGBColor& color) html = TrimString(html) String r, g, b SplitString/E="^#([[:alnum:]]{2})([[:alnum:]]{2})([[:alnum:]]{2})" html, r, g, b color.red = (str2num("0x" + r) / (0xff)) * 0xffff color.green = (str2num("0x" + g) / (0xff)) * 0xffff color.blue = (str2num("0x" + b) / (0xff)) * 0xffff end