diff --git a/.gitignore b/.gitignore index b476765..9906f96 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ node_modules .env build/* !build/.gitkeep +styles/terminal-colors.css diff --git a/lib/atom-helper.coffee b/lib/atom-helper.coffee index 6badbdc..363211f 100644 --- a/lib/atom-helper.coffee +++ b/lib/atom-helper.coffee @@ -34,3 +34,7 @@ module.exports = atom.packages.activatePackage(packageName()).then -> atom.menu.sortPackagesMenu() + reloadStylesheets: -> + pkg = atom.packages.getActivePackage(packageName()) + pkg.reloadStylesheets() + diff --git a/lib/colors.coffee b/lib/colors.coffee new file mode 100644 index 0000000..5d58bb5 --- /dev/null +++ b/lib/colors.coffee @@ -0,0 +1,41 @@ +fs = require 'fs' +path = require 'path' +atomHelper = require './atom-helper' +{name} = require '../package.json' + +module.exports = setTerminalColors = -> + # TODO: handle legacy config keys + text = atom.config.get("#{name}.basicColors.text") + background = atom.config.get("#{name}.basicColors.background") + + css = """ + .terminal { + color: #{text.toRGBAString()}; + } + + .terminal .xterm-viewport { + background-color: #{background.toRGBAString()}; + }\n + """ + + for n in [0..15] + color = atom.config.get("#{name}.ansiColors.ansiColor#{n}") + rgba = color.toRGBAString() + + css += """ + \n.terminal .xterm-color-#{n} { + color: #{rgba}; + } + + .terminal .xterm-bg-color-#{n} { + background-color: #{rgba}; + }\n + """ + + file = path.join(__dirname, '..', 'styles', 'terminal-colors.css') + fs.writeFile file, css, (err) -> + if err? + console.warn 'unable to write colors:', err + + atomHelper.reloadStylesheets() + diff --git a/lib/learn-ide.coffee b/lib/learn-ide.coffee index 637e1d2..76b7e83 100644 --- a/lib/learn-ide.coffee +++ b/lib/learn-ide.coffee @@ -14,6 +14,7 @@ config = require './config' updater = require './updater' version = require './version' {name} = require '../package.json' +setTerminalColors = require './colors' ABOUT_URL = 'https://help.learn.co/hc/en-us/categories/204144547-The-Learn-IDE' @@ -25,6 +26,7 @@ module.exports = @checkForV1WindowsInstall() @registerWindowsProtocol() @disableFormerPackage() + setTerminalColors() @subscriptions = new CompositeDisposable @subscribeToLogin() @@ -107,11 +109,11 @@ module.exports = 'learn-ide:decrease-font-size': => @termView.decreaseFontSize() 'learn-ide:clear-terminal': => @term.send(' ') - atom.config.onDidChange "#{name}.terminalFontColor", ({newValue}) => - @termView.updateFontColor(newValue) + atom.config.onDidChange "#{name}.basicColors", => + setTerminalColors() - atom.config.onDidChange "#{name}.terminalBackgroundColor", ({newValue}) => - @termView.updateBackgroundColor(newValue) + atom.config.onDidChange "#{name}.ansiColors", => + setTerminalColors() atom.config.onDidChange "#{name}.notifier", ({newValue}) => if newValue then @activateNotifier() else @notifier.deactivate() diff --git a/package.json b/package.json index 1338777..c389374 100644 --- a/package.json +++ b/package.json @@ -38,26 +38,6 @@ "learn-ide-material-ui": "1.3.14", "learn-ide-tree": "1.0.22" }, - "configSchema": { - "notifier": { - "type": "boolean", - "default": true, - "title": "Learn Status Notifications", - "description": "Receive desktop notifications that correspond to the lights on Learn.co" - }, - "terminalFontColor": { - "type": "color", - "default": "#ffffff", - "title": "Terminal Font Color", - "description": "A valid CSS color value which will be used to style your terminal's font" - }, - "terminalBackgroundColor": { - "type": "color", - "default": "#1A2226", - "title": "Terminal Background Color", - "description": "A valid CSS color value which will be used to style your terminal's background" - } - }, "devDependencies": { "decompress": "4.0.0", "del": "2.2.2", @@ -67,5 +47,136 @@ "run-sequence": "1.2.2", "shelljs": "0.7.3", "ssh2": "0.5.0" + }, + "configSchema": { + "notifier": { + "order": 0, + "type": "boolean", + "default": true, + "title": "Learn Status Notifications", + "description": "Receive desktop notifications that correspond to the lights on Learn.co" + }, + "basicColors": { + "order": 1, + "title": "Terminal: Basic Colors", + "type": "object", + "properties": { + "text": { + "order": 0, + "type": "color", + "default": "#ffffff", + "title": "Text" + }, + "background": { + "order": 1, + "type": "color", + "default": "#1A2226", + "title": "Background" + } + } + }, + "ansiColors": { + "order": 2, + "title": "Terminal: ANSI Colors", + "type": "object", + "properties": { + "ansiColor0": { + "order": 0, + "type": "color", + "default": "#2e3436", + "title": "Black" + }, + "ansiColor1": { + "order": 1, + "type": "color", + "default": "#cc0000", + "title": "Red" + }, + "ansiColor2": { + "order": 2, + "type": "color", + "default": "#4e9a06", + "title": "Green" + }, + "ansiColor3": { + "order": 3, + "type": "color", + "default": "#c4a000", + "title": "Yellow" + }, + "ansiColor4": { + "order": 4, + "type": "color", + "default": "#3465a4", + "title": "Blue" + }, + "ansiColor5": { + "order": 5, + "type": "color", + "default": "#75507b", + "title": "Magenta" + }, + "ansiColor6": { + "order": 6, + "type": "color", + "default": "#06989a", + "title": "Cyan" + }, + "ansiColor7": { + "order": 7, + "type": "color", + "default": "#d3d7cf", + "title": "White" + }, + "ansiColor8": { + "order": 8, + "type": "color", + "default": "#555753", + "title": "Bright Black" + }, + "ansiColor9": { + "order": 9, + "type": "color", + "default": "#ef2929", + "title": "Bright Red" + }, + "ansiColor10": { + "order": 10, + "type": "color", + "default": "#8ae234", + "title": "Bright Green" + }, + "ansiColor11": { + "order": 11, + "type": "color", + "default": "#fce94f", + "title": "Bright Yellow" + }, + "ansiColor12": { + "order": 12, + "type": "color", + "default": "#729fcf", + "title": "Bright Blue" + }, + "ansiColor13": { + "order": 13, + "type": "color", + "default": "#ad7fa8", + "title": "Bright Magenta" + }, + "ansiColor14": { + "order": 14, + "type": "color", + "default": "#34e2e2", + "title": "Bright Cyan" + }, + "ansiColor15": { + "order": 15, + "type": "color", + "default": "#eeeeec", + "title": "Bright White" + } + } + } } }