11cb0ef41Sopenharmony_ci'use strict' 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_cimodule.exports = function () { 41cb0ef41Sopenharmony_ci return ThemeSetProto.newThemeSet() 51cb0ef41Sopenharmony_ci} 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_civar ThemeSetProto = {} 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciThemeSetProto.baseTheme = require('./base-theme.js') 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciThemeSetProto.newTheme = function (parent, theme) { 121cb0ef41Sopenharmony_ci if (!theme) { 131cb0ef41Sopenharmony_ci theme = parent 141cb0ef41Sopenharmony_ci parent = this.baseTheme 151cb0ef41Sopenharmony_ci } 161cb0ef41Sopenharmony_ci return Object.assign({}, parent, theme) 171cb0ef41Sopenharmony_ci} 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ciThemeSetProto.getThemeNames = function () { 201cb0ef41Sopenharmony_ci return Object.keys(this.themes) 211cb0ef41Sopenharmony_ci} 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ciThemeSetProto.addTheme = function (name, parent, theme) { 241cb0ef41Sopenharmony_ci this.themes[name] = this.newTheme(parent, theme) 251cb0ef41Sopenharmony_ci} 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ciThemeSetProto.addToAllThemes = function (theme) { 281cb0ef41Sopenharmony_ci var themes = this.themes 291cb0ef41Sopenharmony_ci Object.keys(themes).forEach(function (name) { 301cb0ef41Sopenharmony_ci Object.assign(themes[name], theme) 311cb0ef41Sopenharmony_ci }) 321cb0ef41Sopenharmony_ci Object.assign(this.baseTheme, theme) 331cb0ef41Sopenharmony_ci} 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ciThemeSetProto.getTheme = function (name) { 361cb0ef41Sopenharmony_ci if (!this.themes[name]) { 371cb0ef41Sopenharmony_ci throw this.newMissingThemeError(name) 381cb0ef41Sopenharmony_ci } 391cb0ef41Sopenharmony_ci return this.themes[name] 401cb0ef41Sopenharmony_ci} 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ciThemeSetProto.setDefault = function (opts, name) { 431cb0ef41Sopenharmony_ci if (name == null) { 441cb0ef41Sopenharmony_ci name = opts 451cb0ef41Sopenharmony_ci opts = {} 461cb0ef41Sopenharmony_ci } 471cb0ef41Sopenharmony_ci var platform = opts.platform == null ? 'fallback' : opts.platform 481cb0ef41Sopenharmony_ci var hasUnicode = !!opts.hasUnicode 491cb0ef41Sopenharmony_ci var hasColor = !!opts.hasColor 501cb0ef41Sopenharmony_ci if (!this.defaults[platform]) { 511cb0ef41Sopenharmony_ci this.defaults[platform] = { true: {}, false: {} } 521cb0ef41Sopenharmony_ci } 531cb0ef41Sopenharmony_ci this.defaults[platform][hasUnicode][hasColor] = name 541cb0ef41Sopenharmony_ci} 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ciThemeSetProto.getDefault = function (opts) { 571cb0ef41Sopenharmony_ci if (!opts) { 581cb0ef41Sopenharmony_ci opts = {} 591cb0ef41Sopenharmony_ci } 601cb0ef41Sopenharmony_ci var platformName = opts.platform || process.platform 611cb0ef41Sopenharmony_ci var platform = this.defaults[platformName] || this.defaults.fallback 621cb0ef41Sopenharmony_ci var hasUnicode = !!opts.hasUnicode 631cb0ef41Sopenharmony_ci var hasColor = !!opts.hasColor 641cb0ef41Sopenharmony_ci if (!platform) { 651cb0ef41Sopenharmony_ci throw this.newMissingDefaultThemeError(platformName, hasUnicode, hasColor) 661cb0ef41Sopenharmony_ci } 671cb0ef41Sopenharmony_ci if (!platform[hasUnicode][hasColor]) { 681cb0ef41Sopenharmony_ci if (hasUnicode && hasColor && platform[!hasUnicode][hasColor]) { 691cb0ef41Sopenharmony_ci hasUnicode = false 701cb0ef41Sopenharmony_ci } else if (hasUnicode && hasColor && platform[hasUnicode][!hasColor]) { 711cb0ef41Sopenharmony_ci hasColor = false 721cb0ef41Sopenharmony_ci } else if (hasUnicode && hasColor && platform[!hasUnicode][!hasColor]) { 731cb0ef41Sopenharmony_ci hasUnicode = false 741cb0ef41Sopenharmony_ci hasColor = false 751cb0ef41Sopenharmony_ci } else if (hasUnicode && !hasColor && platform[!hasUnicode][hasColor]) { 761cb0ef41Sopenharmony_ci hasUnicode = false 771cb0ef41Sopenharmony_ci } else if (!hasUnicode && hasColor && platform[hasUnicode][!hasColor]) { 781cb0ef41Sopenharmony_ci hasColor = false 791cb0ef41Sopenharmony_ci } else if (platform === this.defaults.fallback) { 801cb0ef41Sopenharmony_ci throw this.newMissingDefaultThemeError(platformName, hasUnicode, hasColor) 811cb0ef41Sopenharmony_ci } 821cb0ef41Sopenharmony_ci } 831cb0ef41Sopenharmony_ci if (platform[hasUnicode][hasColor]) { 841cb0ef41Sopenharmony_ci return this.getTheme(platform[hasUnicode][hasColor]) 851cb0ef41Sopenharmony_ci } else { 861cb0ef41Sopenharmony_ci return this.getDefault(Object.assign({}, opts, { platform: 'fallback' })) 871cb0ef41Sopenharmony_ci } 881cb0ef41Sopenharmony_ci} 891cb0ef41Sopenharmony_ci 901cb0ef41Sopenharmony_ciThemeSetProto.newMissingThemeError = function newMissingThemeError (name) { 911cb0ef41Sopenharmony_ci var err = new Error('Could not find a gauge theme named "' + name + '"') 921cb0ef41Sopenharmony_ci Error.captureStackTrace.call(err, newMissingThemeError) 931cb0ef41Sopenharmony_ci err.theme = name 941cb0ef41Sopenharmony_ci err.code = 'EMISSINGTHEME' 951cb0ef41Sopenharmony_ci return err 961cb0ef41Sopenharmony_ci} 971cb0ef41Sopenharmony_ci 981cb0ef41Sopenharmony_ciThemeSetProto.newMissingDefaultThemeError = 991cb0ef41Sopenharmony_ci function newMissingDefaultThemeError (platformName, hasUnicode, hasColor) { 1001cb0ef41Sopenharmony_ci var err = new Error( 1011cb0ef41Sopenharmony_ci 'Could not find a gauge theme for your platform/unicode/color use combo:\n' + 1021cb0ef41Sopenharmony_ci ' platform = ' + platformName + '\n' + 1031cb0ef41Sopenharmony_ci ' hasUnicode = ' + hasUnicode + '\n' + 1041cb0ef41Sopenharmony_ci ' hasColor = ' + hasColor) 1051cb0ef41Sopenharmony_ci Error.captureStackTrace.call(err, newMissingDefaultThemeError) 1061cb0ef41Sopenharmony_ci err.platform = platformName 1071cb0ef41Sopenharmony_ci err.hasUnicode = hasUnicode 1081cb0ef41Sopenharmony_ci err.hasColor = hasColor 1091cb0ef41Sopenharmony_ci err.code = 'EMISSINGTHEME' 1101cb0ef41Sopenharmony_ci return err 1111cb0ef41Sopenharmony_ci } 1121cb0ef41Sopenharmony_ci 1131cb0ef41Sopenharmony_ciThemeSetProto.newThemeSet = function () { 1141cb0ef41Sopenharmony_ci var themeset = function (opts) { 1151cb0ef41Sopenharmony_ci return themeset.getDefault(opts) 1161cb0ef41Sopenharmony_ci } 1171cb0ef41Sopenharmony_ci return Object.assign(themeset, ThemeSetProto, { 1181cb0ef41Sopenharmony_ci themes: Object.assign({}, this.themes), 1191cb0ef41Sopenharmony_ci baseTheme: Object.assign({}, this.baseTheme), 1201cb0ef41Sopenharmony_ci defaults: JSON.parse(JSON.stringify(this.defaults || {})), 1211cb0ef41Sopenharmony_ci }) 1221cb0ef41Sopenharmony_ci} 123