Skip to content

Commit

Permalink
support custom the input text through input_panel
Browse files Browse the repository at this point in the history
  • Loading branch information
liuhewei committed Apr 10, 2016
1 parent 488ed52 commit 6e14269
Showing 1 changed file with 38 additions and 12 deletions.
50 changes: 38 additions & 12 deletions runapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@
import subprocess

class RunappCommand(sublime_plugin.WindowCommand):
# def __init__(self, *args):
# self.input = ""

def run(self, app="", args=[], type=None, cli=False, input=False):

target = ""
view = None

if self.window.active_view() != None:
view = self.window.active_view()
view = self.window.active_view()

if view.size() > 0:
file = view.file_name()
if file == None:
sublime.error_message("Save the buffer to a local file firstly")
return
dir = os.path.split(file)[0]
proj = ""

Expand Down Expand Up @@ -45,10 +42,21 @@ def run(self, app="", args=[], type=None, cli=False, input=False):
args[i] = arg

# handle input
if input and view.sel() != None:
target = view.substr(view.sel()[0])
if input:
if view.sel()[0].size() > 0:
target = view.substr(view.sel()[0])
else:
self.app, self.args, self.cli = app, args, cli
self.window.show_input_panel("RunApp Input:", "", self.run_app, None, None)
return

# invoke the application: gui or cli
self.run_app(target, app, args, cli)

def run_app(self, target, app="", args=[], cli=False):
if app == "":
app, args, cli = self.app, self.args, self.cli

if cli == True:
stdout, rc = self.run_cli(app, args, target)
if rc == 0:
Expand Down Expand Up @@ -114,8 +122,7 @@ def run(self):
"command": "runapp",
"args":{
"app": "D:\\\\Tools\\\\Git\\\\git-bash.exe",
"args": ["--cd=$DIR$"],
"type": "none"
"args": ["--cd=$DIR$"]
}
},
Expand All @@ -128,8 +135,27 @@ def run(self):
"args": [],
"type": "file"
}
},
{
"caption": "Run: Godoc.org",
"command": "runapp",
"args":{
"app": "C:\\\\Program Files\\\\Google\\\\Chrome\\\\Application\\\\chrome.exe",
"args": ["https://godoc.org/"]
}
},
{
"caption": "Run: Godoc-local",
"command": "runapp",
"args":{
"app": "D:\\Tools\\Go\\bin\\go.exe",
"args": ["doc"],
"input": true,
"cli": true
}
}
]"""
open(cmdFile, 'w+', encoding='utf8', newline='').write(str(content))
sublime.active_window().open_file(cmdFile)
Expand Down

0 comments on commit 6e14269

Please sign in to comment.