zoukankan      html  css  js  c++  java
  • python | 实现控制台效果

    随便写的

    import sys, time
    import threading
    import os
    import msvcrt
    
    
    class Cmd:
    	def __init__(self):
    		self.buff = b''           # buff string
    		print('''Ready to Start | PYcmd by Mz1
    ========================================================''')
    	def flush(self):
    		sys.stdout.write(('
    >>> ' + self.buff.decode('latin1') + ' '))
    		sys.stdout.flush()
    	def log(self, string):     # use to print on the screen
    		sys.stdout.write(f'
    {string}
    ')
    		sys.stdout.flush()
    		self.flush()
    	def call(self, string):
    		self.log(f'   > call {string}')
    	def run(self):
    		while True:
    			while True:		# read byte
    				self.flush()     # flush the buff
    				c = msvcrt.getch()
    				if c == b'
    ':
    					break
    				elif c == b'x08':     # backspace
    					self.buff = self.buff[:-1]
    				else:
    					self.buff += c
    			if self.buff != b'':
    				threading.Thread(target=self.call, args=(self.buff.decode('latin1'),)).start()
    			self.buff = b''
    			
    if __name__ == '__main__':
    	cmd = Cmd()
    	cmd.run()
    
    
    
  • 相关阅读:
    HUST 1017 Exact cover (Dancing links)
    HDU 1160 FatMouse's Speed (DP)
    HDU 1058 Humble Numbers (DP)
    Kubernetes(k8s)
    linux命令
    入侵检测系统
    lynis检测
    CPU死锁
    检测工具lynis
    Linux表面工作
  • 原文地址:https://www.cnblogs.com/Mz1-rc/p/14393057.html
Copyright © 2011-2022 走看看