mirror of
https://github.com/akelge/zsh
synced 2025-07-04 21:49:05 +00:00
Added GetLatestScript update plugin and updated all plugins
This commit is contained in:
@ -1,11 +1,11 @@
|
||||
# FILE: autoload/conque_term/conque_subprocess.py {{{
|
||||
# FILE: autoload/conque_term/conque_subprocess.py
|
||||
# AUTHOR: Nico Raffo <nicoraffo@gmail.com>
|
||||
# WEBSITE: http://conque.googlecode.com
|
||||
# MODIFIED: 2010-11-15
|
||||
# VERSION: 2.0, for Vim 7.0
|
||||
# MODIFIED: 2011-08-12
|
||||
# VERSION: 2.2, for Vim 7.0
|
||||
# LICENSE:
|
||||
# Conque - Vim terminal/console emulator
|
||||
# Copyright (C) 2009-2010 Nico Raffo
|
||||
# Copyright (C) 2009-__YEAR__ Nico Raffo
|
||||
#
|
||||
# MIT License
|
||||
#
|
||||
@ -25,7 +25,7 @@
|
||||
# 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. }}}
|
||||
# THE SOFTWARE.
|
||||
|
||||
"""
|
||||
ConqueSubprocess
|
||||
@ -43,15 +43,15 @@ Usage:
|
||||
p.close()
|
||||
"""
|
||||
|
||||
if CONQUE_PLATFORM == 'nix':
|
||||
import os
|
||||
import signal
|
||||
import pty
|
||||
import tty
|
||||
import select
|
||||
import fcntl
|
||||
import termios
|
||||
import struct
|
||||
import os
|
||||
import signal
|
||||
import pty
|
||||
import tty
|
||||
import select
|
||||
import fcntl
|
||||
import termios
|
||||
import struct
|
||||
import shlex
|
||||
|
||||
|
||||
class ConqueSubprocess:
|
||||
@ -62,16 +62,12 @@ class ConqueSubprocess:
|
||||
# stdout+stderr file descriptor
|
||||
fd = None
|
||||
|
||||
# constructor
|
||||
def __init__(self): # {{{
|
||||
self.pid = 0
|
||||
# }}}
|
||||
|
||||
# create pty + subprocess
|
||||
def open(self, command, env={}): # {{{
|
||||
def open(self, command, env={}):
|
||||
""" Create subprocess using forkpty() """
|
||||
|
||||
# parse command
|
||||
command_arr = command.split()
|
||||
command_arr = shlex.split(command)
|
||||
executable = command_arr[0]
|
||||
args = command_arr
|
||||
|
||||
@ -90,7 +86,7 @@ class ConqueSubprocess:
|
||||
for k in env.keys():
|
||||
os.environ[k] = env[k]
|
||||
|
||||
# set some attributes
|
||||
# set tty attributes
|
||||
try:
|
||||
attrs = tty.tcgetattr(1)
|
||||
attrs[0] = attrs[0] ^ tty.IGNBRK
|
||||
@ -111,14 +107,13 @@ class ConqueSubprocess:
|
||||
else:
|
||||
pass
|
||||
|
||||
# }}}
|
||||
|
||||
# read from pty
|
||||
# XXX - select.poll() doesn't work in OS X!!!!!!!
|
||||
def read(self, timeout=1): # {{{
|
||||
def read(self, timeout=1):
|
||||
""" Read from subprocess and return new output """
|
||||
|
||||
output = ''
|
||||
read_timeout = float(timeout) / 1000
|
||||
read_ct = 0
|
||||
|
||||
try:
|
||||
# read from fd until no more output
|
||||
@ -128,49 +123,59 @@ class ConqueSubprocess:
|
||||
lines = ''
|
||||
for s_fd in s_read:
|
||||
try:
|
||||
lines = os.read(self.fd, 32)
|
||||
# increase read buffer so huge reads don't slow down
|
||||
if read_ct < 10:
|
||||
lines = os.read(self.fd, 32)
|
||||
elif read_ct < 50:
|
||||
lines = os.read(self.fd, 512)
|
||||
else:
|
||||
lines = os.read(self.fd, 2048)
|
||||
read_ct += 1
|
||||
except:
|
||||
pass
|
||||
output = output + lines.decode('utf-8')
|
||||
|
||||
if lines == '':
|
||||
if lines == '' or read_ct > 100:
|
||||
break
|
||||
except:
|
||||
|
||||
pass
|
||||
|
||||
return output
|
||||
# }}}
|
||||
|
||||
# I guess this one's not bad
|
||||
def write(self, input): # {{{
|
||||
|
||||
def write(self, input):
|
||||
""" Write new input to subprocess """
|
||||
|
||||
try:
|
||||
if CONQUE_PYTHON_VERSION == 2:
|
||||
os.write(self.fd, input)
|
||||
os.write(self.fd, input.encode('utf-8', 'ignore'))
|
||||
else:
|
||||
os.write(self.fd, bytes(input, 'utf-8'))
|
||||
except:
|
||||
|
||||
pass
|
||||
# }}}
|
||||
|
||||
# signal process
|
||||
def signal(self, signum): # {{{
|
||||
|
||||
def signal(self, signum):
|
||||
""" signal process """
|
||||
|
||||
try:
|
||||
os.kill(self.pid, signum)
|
||||
except:
|
||||
pass
|
||||
# }}}
|
||||
|
||||
# close process
|
||||
def close(self): # {{{
|
||||
|
||||
def close(self):
|
||||
""" close process with sigterm signal """
|
||||
|
||||
self.signal(15)
|
||||
# }}}
|
||||
|
||||
# get process status
|
||||
def is_alive(self): #{{{
|
||||
|
||||
def is_alive(self):
|
||||
""" get process status """
|
||||
|
||||
p_status = True
|
||||
|
||||
try:
|
||||
if os.waitpid(self.pid, os.WNOHANG)[0]:
|
||||
p_status = False
|
||||
@ -179,17 +184,15 @@ class ConqueSubprocess:
|
||||
|
||||
return p_status
|
||||
|
||||
# }}}
|
||||
|
||||
# update window size in kernel, then send SIGWINCH to fg process
|
||||
def window_resize(self, lines, columns): # {{{
|
||||
def window_resize(self, lines, columns):
|
||||
""" update window size in kernel, then send SIGWINCH to fg process """
|
||||
|
||||
try:
|
||||
fcntl.ioctl(self.fd, termios.TIOCSWINSZ, struct.pack("HHHH", lines, columns, 0, 0))
|
||||
os.kill(self.pid, signal.SIGWINCH)
|
||||
except:
|
||||
pass
|
||||
|
||||
# }}}
|
||||
|
||||
|
||||
# vim:foldmethod=marker
|
||||
|
Reference in New Issue
Block a user