-
-
Save carocad/6334a5d457b868e75da55f1b0233151c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use babel' | |
/* global atom:false */ | |
import {CompositeDisposable} from 'atom' | |
export default { | |
subscriptions: null, | |
console: null, | |
modes: [ | |
{name: 'atom-foo', default: true, grammar: 'source.julia'}, | |
{name: 'help', prefix: '?', icon: 'question', grammar: 'source.julia'}, | |
{name: 'shell', prefix: ';', icon: 'terminal', grammar: 'source.shell'} | |
], | |
activate (state) { | |
// Events subscribed to in atom's system can be easily cleaned up with a | |
// CompositeDisposable | |
this.subscriptions = new CompositeDisposable() | |
// this adds an opener for a type of file (uri), which means that when | |
// a file (uri) is opened that matches this condition, the console is returned | |
this.subscriptions.add(atom.workspace.addOpener(uri => { | |
if (uri === 'atom://atom-foo-client/console') { | |
return this.console | |
} | |
})) | |
// Register command that calls this.toggle this view | |
this.subscriptions.add(atom.commands.add('atom-workspace', { | |
'atom-foo:toggle': () => this.toggle() | |
})) | |
console.log('AtomFoo activated!') | |
}, | |
deactivate () { | |
this.subscriptions.dispose() | |
}, | |
// this is called asynchronously, don't trust ink to be present unless you | |
// know that this method was called | |
consumeInk (ink) { | |
this.createConsole(ink) | |
this.toggle() | |
console.log('AtomFoo consumed Ink!') | |
}, | |
serialize () {}, | |
// this is called once the command has been registered and invoked | |
// as ink might not be present, nothing happens here | |
toggle () { | |
if (this.console !== null) { | |
this.openConsole() | |
this.console.stderr('FAKE STDERR') | |
this.console.stdout('look at me I\'m fake output') | |
this.console.info('bad information') | |
// console.result takes an HTML element, not a string as the previous | |
// this is (probably) in order to render data structs in a language | |
// specific way | |
let res = new Text('RESULT') | |
this.console.result(res) | |
let err = new Text('ERROR') | |
this.console.result(err, {error: true}) | |
} | |
console.log('AtomFoo toggled!') | |
}, | |
// this creates the console and puts some hooks on it (I deactivated them) | |
// in order to respond to eval calls and similars | |
createConsole (ink) { | |
this.console = ink.Console.fromId('atom-foo') | |
this.console.setModes(this.modes) | |
this.console.onEval(ed => this.eval(ed)) | |
let view = atom.views.getView(this.console) | |
view.classList.add('atom-foo') | |
atom.views.getView(this.console).classList.add('atom-foo') | |
}, | |
openConsole () { | |
this.console.activate() | |
atom.workspace.open('atom://atom-foo-client/console', | |
{ | |
split: 'right', | |
searchAllPanes: true | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Screenshot
