コード例 #1
0
ファイル: terminal.py プロジェクト: zmukwa/powerline
class ExpectProcess(threading.Thread):
    def __init__(self, lib, rows, cols, cmd, args, cwd=None, env=None):
        super(ExpectProcess, self).__init__()
        self.vterm = VTerm(lib, rows, cols)
        self.lock = threading.Lock()
        self.rows = rows
        self.cols = cols
        self.cmd = cmd
        self.args = args
        self.cwd = cwd
        self.env = env
        self.buffer = []
        self.child_lock = threading.Lock()

    def run(self):
        child = pexpect.spawn(self.cmd, self.args, cwd=self.cwd, env=self.env)
        sleep(0.5)
        child.setwinsize(self.rows, self.cols)
        sleep(0.5)
        self.child = child
        status = None
        while status is None:
            try:
                with self.child_lock:
                    s = child.read_nonblocking(size=1024, timeout=0)
                    status = child.status
            except pexpect.TIMEOUT:
                pass
            except pexpect.EOF:
                break
            else:
                with self.lock:
                    self.vterm.push(s)
                    self.buffer.append(s)

    def resize(self, rows, cols):
        with self.child_lock:
            self.rows = rows
            self.cols = cols
            self.child.setwinsize(rows, cols)
            self.vterm.resize(rows, cols)

    def __getitem__(self, position):
        with self.lock:
            return self.vterm.vtscreen[position]

    def read(self):
        with self.lock:
            ret = b''.join(self.buffer)
            del self.buffer[:]
            return ret

    def send(self, data):
        with self.child_lock:
            self.child.send(data)
コード例 #2
0
ファイル: terminal.py プロジェクト: 21gunnns/powerline
class ExpectProcess(threading.Thread):
	def __init__(self, lib, rows, cols, cmd, args, cwd=None, env=None):
		super(ExpectProcess, self).__init__()
		self.vterm = VTerm(lib, rows, cols)
		self.lock = threading.Lock()
		self.rows = rows
		self.cols = cols
		self.cmd = cmd
		self.args = args
		self.cwd = cwd
		self.env = env
		self.buffer = []
		self.child_lock = threading.Lock()

	def run(self):
		child = pexpect.spawn(self.cmd, self.args, cwd=self.cwd, env=self.env)
		sleep(0.5)
		child.setwinsize(self.rows, self.cols)
		sleep(0.5)
		self.child = child
		status = None
		while status is None:
			try:
				with self.child_lock:
					s = child.read_nonblocking(size=1024, timeout=0)
					status = child.status
			except pexpect.TIMEOUT:
				pass
			except pexpect.EOF:
				break
			else:
				with self.lock:
					self.vterm.push(s)
					self.buffer.append(s)

	def resize(self, rows, cols):
		with self.child_lock:
			self.rows = rows
			self.cols = cols
			self.child.setwinsize(rows, cols)
			self.vterm.resize(rows, cols)

	def __getitem__(self, position):
		with self.lock:
			return self.vterm.vtscreen[position]

	def read(self):
		with self.lock:
			ret = b''.join(self.buffer)
			del self.buffer[:]
			return ret

	def send(self, data):
		with self.child_lock:
			self.child.send(data)
コード例 #3
0
 def __init__(self, lib, rows, cols, cmd, args, cwd=None, env=None):
     super(ExpectProcess, self).__init__()
     self.vterm = VTerm(lib, rows, cols)
     self.lock = threading.Lock()
     self.rows = rows
     self.cols = cols
     self.cmd = cmd
     self.args = args
     self.cwd = cwd
     self.env = env
     self.buffer = []
     self.child_lock = threading.Lock()
コード例 #4
0
ファイル: terminal.py プロジェクト: 21gunnns/powerline
	def __init__(self, lib, rows, cols, cmd, args, cwd=None, env=None):
		super(ExpectProcess, self).__init__()
		self.vterm = VTerm(lib, rows, cols)
		self.lock = threading.Lock()
		self.rows = rows
		self.cols = cols
		self.cmd = cmd
		self.args = args
		self.cwd = cwd
		self.env = env
		self.buffer = []
		self.child_lock = threading.Lock()