Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customized run option #74

Merged
merged 27 commits into from
Apr 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a33bc0e
Initial commit to my fork. In this I am mostly playing around with at…
EntilZha Mar 14, 2014
909c41c
Added a framework for storing options which are persistent for the li…
EntilZha Mar 15, 2014
f088d4c
Added the UI for configuring run options. It currently is not linked …
EntilZha Mar 16, 2014
f1074d2
I added better styling to the view using the style guide provided by …
EntilZha Mar 16, 2014
6c9005e
Completed hooking up the backend to the UI. You can now modify the cw…
EntilZha Mar 16, 2014
e9a8426
Made changes on the css names to use all dash style instead of camel …
EntilZha Mar 17, 2014
6c8d01a
Changed .css calls to .show() and .hide(). Also used shorter notation…
EntilZha Mar 17, 2014
ae86934
Removed debugging console.log statements
EntilZha Mar 17, 2014
bad05dd
added myself as a contributor
EntilZha Mar 17, 2014
5be1c21
removed unnecessary return statements
EntilZha Mar 17, 2014
1e85635
renamed script:options to script:run-options
EntilZha Mar 17, 2014
e7e1733
Changed the text from Script Arguments to Program arguments and added…
EntilZha Mar 17, 2014
0bf623f
Simplified the toggle code to use jquery .toggle() and the ability to…
EntilZha Mar 17, 2014
d25dc44
Changed the flow so that running the options doesn't run the program.…
EntilZha Mar 17, 2014
b41aab9
Cleaned up more from last commit removing unnecessary default arguments
EntilZha Mar 17, 2014
f1c5a59
Added the options configuring to the script menu.
EntilZha Mar 17, 2014
8b320e1
Caught a bug where running wouldn't save the options first
EntilZha Mar 17, 2014
ab71393
Changed the naming of options to avoid a name collision
EntilZha Mar 17, 2014
00414e9
collapsed multiple divs into one
EntilZha Mar 17, 2014
ff2a5b9
Refactored the options view to a better name and separated it from th…
EntilZha Mar 25, 2014
44c3a4f
added a script options class
EntilZha Mar 25, 2014
264eae4
Continued refactoring of view. Attempting to get single options objec…
EntilZha Mar 25, 2014
c9f3fd5
Used atom.emit on atom.on to communicate state effectively (options).…
EntilZha Mar 25, 2014
b1a3810
removed unecessary action
EntilZha Apr 1, 2014
b05c9f5
added small documentation note
EntilZha Apr 3, 2014
c9353f4
fixes from the last rebase
EntilZha Apr 3, 2014
8b2e31c
removed uneccesary statement
EntilZha Apr 3, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Select some code and hit `⌘-i` to run just that selection.

`⌘-i` to run your entire file.

`⌘-shift-i` to configure command options and program arguments

`ctrl-c` will kill the process but leaves the pane open.

`ctrl-w` closes the pane and kills the process.
Expand Down
4 changes: 4 additions & 0 deletions examples/cwd-args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import sys, os

print "CWD:{0}".format(os.getcwd())
print "ARGS:{0}".format(sys.argv[1:])
1 change: 1 addition & 0 deletions keymaps/script.cson
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
'cmd-i': 'script:run'
'ctrl-w': 'script:close-view'
'ctrl-c': 'script:kill-process'
'shift-cmd-i': 'script:run-options'
2 changes: 1 addition & 1 deletion lib/header-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports =
class HeaderView extends View

@content: ->
@div class: 'panel-heading padded heading headerView', =>
@div class: 'panel-heading padded heading header-view', =>
@span class: 'heading-title', outlet: 'title'
@span class: 'heading-status', outlet: 'status'
@span class: 'heading-close icon-remove-close pull-right', outlet: 'closeButton', click: 'close'
Expand Down
59 changes: 59 additions & 0 deletions lib/script-options-view.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{View} = require 'atom'

module.exports =
class ScriptOptionsView extends View

@content: ->
@div =>
@div class: 'overlay from-top panel', outlet: 'scriptOptionsView', =>
@div class: 'panel-heading', 'Configure Run Options'
@div class: 'panel-body padded native-key-bindings', =>
@div class: 'block', =>
@label 'Current Working Directory:'
@input type: 'text', class: 'editor mini editor-colors ', outlet: 'inputCwd'
@div class: 'block', =>
@label 'Command Arguments:'
@input type: 'text', class: 'editor mini editor-colors', outlet: 'inputCommandArgs'
@div class: 'block', =>
@label 'Program Arguments:'
@input type: 'text', class: 'editor mini editor-colors', outlet: 'inputScriptArgs'
@div class: 'block', =>
@button class: 'btn btn-primary inline-block-tight', click: 'close', 'Close'
@button class: 'btn btn-success inline-block-tight', click: 'run', 'Run'

initialize: (run_options) ->
atom.workspaceView.command "script:run-options", => @runOptions()
atom.workspaceView.command "script:close-options", => @toggleScriptOptions('hide')
atom.workspaceView.command "script:save-options", => @saveOptions()
atom.workspaceView.prependToTop(this)
@toggleScriptOptions('hide')
@run_options = run_options

runOptions: ->
@toggleScriptOptions()


toggleScriptOptions: (command) ->
if command?
if command == 'show'
@scriptOptionsView.show()
if command == 'hide'
@scriptOptionsView.hide()
else
@scriptOptionsView.toggle()

saveOptions: =>
@run_options.cmd_cwd = @inputCwd.val()
@run_options.cmd_args = (item for item in @inputCommandArgs.val().split(' ') when item != '')
@run_options.script_args = (item for item in @inputScriptArgs.val().split(' ') when item != '')
atom.emit 'script:update-options', run_options: @run_options

close: ->
if @hasParent() then @detach()

close: ->
atom.workspaceView.trigger "script:close-options"
run: ->
atom.workspaceView.trigger "script:save-options"
atom.workspaceView.trigger "script:close-options"
atom.workspaceView.trigger "script:run"
5 changes: 5 additions & 0 deletions lib/script-options.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports =
class ScriptOptions
cmd_cwd: null
cmd_args: []
script_args: []
30 changes: 22 additions & 8 deletions lib/script-view.coffee
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
grammarMap = require './grammars'
{View, BufferedProcess} = require 'atom'
HeaderView = require './header-view'
_ = require 'underscore'

ScriptOptionsView = require './script-options-view'
AnsiFilter = require 'ansi-to-html'
_ = require 'underscore'

# Runs a portion of a script through an interpreter and displays it line by line
module.exports =
class ScriptView extends View
@bufferedProcess: null

@content: ->
@div class: 'outer-scriptView', =>
@div =>
@subview 'headerView', new HeaderView()
# Display layout and outlets
@div class: 'tool-panel panel panel-bottom padding scriptView native-key-bindings', outlet: 'script', tabindex: -1, =>
@div class: 'tool-panel panel panel-bottom padding script-view native-key-bindings', outlet: 'script', tabindex: -1, =>
@div class: 'panel-body padded output', outlet: 'output'

initialize: (serializeState) ->
initialize: (serializeState, run_options) ->
# Bind commands
atom.workspaceView.command "script:run", => @start()
atom.workspaceView.command "script:close-view", => @close()
atom.workspaceView.command "script:kill-process", => @stop()
atom.on 'script:update-options', @updateOptions

@ansiFilter = new AnsiFilter
@run_options = run_options

serialize: ->

updateOptions: (event) =>
console.log(event)
@run_options = event.run_options

start: ->
# Get current editor
editor = atom.workspace.getActiveEditor()
Expand All @@ -39,7 +45,7 @@ class ScriptView extends View
info = @setup(editor)
if info then @run(info.command, info.args)

resetView: ->
resetView: (title='Loading...') ->
# Display window and load message

# First run, create view
Expand All @@ -49,7 +55,7 @@ class ScriptView extends View
# Close any existing process and start a new one
@stop()

@headerView.title.text("Loading...")
@headerView.title.text(title)
@headerView.setStatus("start")

# Get script view ready
Expand Down Expand Up @@ -147,8 +153,9 @@ class ScriptView extends View

# Default to where the user opened atom
options =
cwd: atom.project.getPath()
cwd: @getCwd()
env: process.env
args = (@run_options.cmd_args.concat args).concat @run_options.script_args

stdout = (output) => @display("stdout", output)
stderr = (output) => @display("stderr", output)
Expand All @@ -170,6 +177,13 @@ class ScriptView extends View

)

getCwd: ->
if @run_options.cmd_cwd is null || @run_options.cmd_cwd == ''
atom.project.getPath()
else
@run_options.cmd_cwd


stop: ->
# Kill existing process if available
if @bufferedProcess? and @bufferedProcess.process?
Expand Down
8 changes: 7 additions & 1 deletion lib/script.coffee
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
ScriptView = require './script-view'
ScriptOptionsView = require './script-options-view'
ScriptOptions = require './script-options'

module.exports =
scriptView: null
scriptOptionsView: null

activate: (state) ->
@scriptView = new ScriptView(state.scriptViewState)
@scriptView = new ScriptView(state.scriptViewState, new ScriptOptions())
@scriptOptionsView = new ScriptOptionsView(new ScriptOptions())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused here. Why don't they have the same shared ScriptOptions object?

@scriptOptions = new ScriptOptions()
@scriptView = new ScriptView(state.scriptViewState, @scriptOptions)
@scriptOptionsView = new ScriptOptionsView(@scriptOptions)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is the first thing I tried. My initial thought was to create 1 object as you suggested and pass it around, with both views having access to it and essentially communicating through it.

What I found though was that the object/hash being changed in one place, did not change the other. So I concluded that it must be copying the object/hash (at the same time, the same one) for use in each view, rather than passing a reference to the same object.

To work around this, I used atom.emit and atom.on, but if this could work it would be cleaner

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright. I must have a fundamental misunderstanding about Javascript and CoffeeScript objects then.

I'll work with this for a bit and merge it in tonight.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I thought that passing 1 reference around would work as well. I would be interested in seeing if perhaps I just implemented it wrong


deactivate: ->
@scriptView.close()
@scriptOptionsView.close()

serialize: ->
scriptViewState: @scriptView.serialize()
scriptOptionsViewState: @scriptOptionsView.serialize()
1 change: 1 addition & 0 deletions menus/script.cson
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
'submenu': [
{ 'label': 'Run Script', 'command': 'script:run' },
{ 'label': 'Stop Script', 'command': 'script:kill-process' },
{ 'label': 'Configure Script', 'command': 'script:run-options' }
{ 'label': 'Close Window and Stop Script', 'command': 'script:close-view' }
]
]
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
"version": "2.2.0",
"private": false,
"description": "Run code in Atom!",
"activationEvents": [
"script:run"
],
"author": "Kyle Kelley <rgbkrk@gmail.com>",
"contributors": [
"Kyle Kelley <rgbkrk@gmail.com>",
Expand All @@ -20,7 +17,8 @@
"cormullion <cormullion@mac.com>",
"Andy Hayden <andyhayden1@gmail.com>",
"jbtule <jay+code@tuley.name>",
"Johan Bruning <johan@taquito.nl>"
"Johan Bruning <johan@taquito.nl>",
"Pedro Rodriguez <ski.rodriguez@gmail.com>"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be moving you near the top after this gets merged. 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll actually move you up higher since git shortlog -sne ranks you by commits. 😉

],
"repository": "https://github.com/rgbkrk/atom-script",
"keywords": [
Expand Down
4 changes: 2 additions & 2 deletions stylesheets/script.less
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@import "ui-variables";
@import "ui-mixins";

.headerView {
.header-view {
position: fixed;
width: 100%;
z-index:10;
Expand Down Expand Up @@ -41,7 +41,7 @@
}
}

.scriptView {
.script-view {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for standardizing the CSS class name on the viewer.

overflow: scroll;
height: 300px;
margin-bottom: 0px;
Expand Down