Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
al3x committed Mar 12, 2014
0 parents commit 9bbab52
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
npm-debug.log
node_modules
20 changes: 20 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2014 <Your name here>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Atom Theme Switcher

Switches between one theme and another when you hit a key. Ideal for themes like Solarized that provide both light and dark versions that you may want to switch to under different lighting conditions.

Mapped to F12 by default.

See also [outdoor-theme](https://github.com/mattapperson/outdoor-theme), which didn't work for me at time of writing but is theoretically automatic and thus much cooler.
11 changes: 11 additions & 0 deletions keymaps/theme-switcher.cson
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Keybindings require three things to be fully defined: A selector that is
# matched against the focused element, the keystroke and the command to
# execute.
#
# Below is a basic keybinding which registers on all platforms by applying to
# the root workspace element.

# For more detailed documentation see
# https://atom.io/docs/latest/advanced/keymaps
'.workspace':
'f12': 'theme-switcher:switch'
22 changes: 22 additions & 0 deletions lib/theme-switcher.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports =
configDefaults: {
themeOne: 'solarized-dark-syntax'
themeTwo: 'solarized-light-syntax'
}

activate: (state) ->
atom.workspaceView.command 'theme-switcher:switch', => @switch()

switch: ->
currentThemes = atom.config.get('core.themes')
currentSyntaxTheme = currentThemes[1]

themeOne = atom.config.get('theme-switcher.themeOne')
themeTwo = atom.config.get('theme-switcher.themeTwo')

if currentSyntaxTheme == themeOne
currentThemes[1] = themeTwo
else
currentThemes[1] = themeOne

atom.config.set('core.themes', currentThemes)
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "theme-switcher",
"main": "./lib/theme-switcher",
"version": "0.0.0",
"description": "Switches between one theme and another. Ideal for light/dark themes like Solarized.",
"activationEvents": ["theme-switcher:switch"],
"repository": "https://github.com/al3x/atom-theme-switcher",
"license": "MIT",
"engines": {
"atom": ">0.50.0"
},
"dependencies": {
}
}
38 changes: 38 additions & 0 deletions spec/theme-switcher-spec.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{WorkspaceView} = require 'atom'

# Use the command `window:run-package-specs` (cmd-alt-ctrl-p) to run specs.
#
# To run a specific `it` or `describe` block add an `f` to the front (e.g. `fit`
# or `fdescribe`). Remove the `f` to unfocus the block.

describe 'ThemeSwitcher', ->
activationPromise = null

beforeEach ->
atom.workspaceView = new WorkspaceView()
atom.workspaceView.attachToDom()
activationPromise = atom.packages.activatePackage('theme-switcher')

describe "when the theme-switcher:switch event is triggered", ->
it "switches the theme", ->
defaultThemes = atom.config.get('core.themes')
defaultSyntaxTheme = defaultThemes[1]

atom.workspaceView.trigger 'theme-switcher:switch'

waitsForPromise ->
activationPromise

runs ->
themesAfterTrigger = atom.config.get('core.themes')
syntaxThemeAfterTrigger = themesAfterTrigger[1]

expect(syntaxThemeAfterTrigger).not.toEqual(defaultSyntaxTheme)

expect(syntaxThemeAfterTrigger)
.toEqual(atom.config.get('theme-switcher.themeOne'))

atom.workspaceView.trigger 'theme-switcher:switch'

expect(atom.config.get('core.themes')[1])
.toEqual(atom.config.get('theme-switcher.themeTwo'))

0 comments on commit 9bbab52

Please sign in to comment.