forked from drewdeponte/sublime_guard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added word_wrap and Guard auto termination.
I figured out how to enable native Sublime Text 2 view based word wrapping in the output pane so I enabled that. It is a little strange with respect to autoscrolling because the output is not hard wrapped. I think that can be fixed by actually scrolling to the size of the view like I used to rather than the first char in each line. This will require further testing and will be resolved in another commit. I also added a guard_wrapper command which is now what is executed by the plugin. It simply wraps IO for the guard command and watches for its STDIN to be closed. It does this because when the wrappers STDIN closes that means that Sublime Text 2 has exited either cleanly or by crash and we need to stop Guard.
- Loading branch information
1 parent
ac6692f
commit 9aee4ec
Showing
2 changed files
with
86 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/usr/bin/env python | ||
|
||
import sys | ||
import os | ||
import subprocess | ||
import threading | ||
|
||
|
||
class GuardWrapper: | ||
def __init__(self): | ||
self.running = False | ||
self.proc = None | ||
self.stdout_thread = None | ||
self.stderr_thread = None | ||
self.log = open('/tmp/guard_wrapper.log', 'w') | ||
|
||
def run_cmd(self, cmd_array): | ||
self.proc = subprocess.Popen(cmd_array, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
self.running = True | ||
if self.proc.stdout: | ||
self.stdout_thread = threading.Thread(target=self.read_stdout, args=()) | ||
self.stdout_thread.start() | ||
if self.proc.stderr: | ||
self.stderr_thread = threading.Thread(target=self.read_stderr, args=()) | ||
self.stderr_thread.start() | ||
while True: | ||
self.log.write("read stdin iteration\n") | ||
self.log.flush() | ||
data = sys.stdin.readline() | ||
if data != "": | ||
self.log.write("Received: " + data + "\n") | ||
self.log.flush() | ||
if data == "e\n": | ||
self.proc.stdin.write(data) | ||
self.proc.stdin.flush() | ||
break | ||
else: | ||
self.proc.stdin.write(data) | ||
self.proc.stdin.flush() | ||
else: | ||
self.log.write("got empty string, :-(\n") | ||
self.log.flush() | ||
self.proc.stdin.write("e\n") | ||
self.proc.stdin.flush() | ||
self.proc.stdin.close() | ||
break | ||
self.stdout_thread.join() | ||
self.stderr_thread.join() | ||
|
||
def read_stdout(self): | ||
while True: | ||
data = os.read(self.proc.stdout.fileno(), 2 ** 15) | ||
if data != "": | ||
sys.stdout.write(data) | ||
sys.stdout.flush() | ||
else: | ||
self.proc.stdout.close() | ||
self.running = False | ||
break | ||
|
||
def read_stderr(self): | ||
while True: | ||
data = os.read(self.proc.stderr.fileno(), 2 ** 15) | ||
if data != "": | ||
sys.stderr.write(data) | ||
sys.stderr.flush() | ||
else: | ||
self.proc.stderr.close() | ||
self.running = False | ||
break | ||
|
||
|
||
wrap = GuardWrapper() | ||
wrap.run_cmd(sys.argv[1:]) |