-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathterminalwidget.py
39 lines (31 loc) · 1.09 KB
/
terminalwidget.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#coding:utf-8
from gi.repository import Gtk, GtkSource, GObject
try:
from gi.repository import Vte
termtype="vte"
except:
termtype="io"
import io,re
recolor = re.compile(b'\x1b.*?m|\x1b.*?B')
class TerminalBuffer(GtkSource.Buffer):
def __init__(self,*a,**kw):
self.bb = io.BytesIO()
self.text = Gtk.TextBuffer()
return super(TerminalBuffer, self).__init__(*a,**kw)
def feed(self,data):
st = self.bb.tell()
self.bb.seek(0,2)
self.bb.write(data)
self.bb.seek(st)
while True:
st = self.bb.tell()
line = self.bb.readline()
if line and line[-1]==10:
text = recolor.sub(b'',line)
self.feedline(text.decode('utf-8'))
else:
self.bb.seek(st)
break
def feedline(self,text):
self.insert(self.get_end_iter(),text)
GObject.type_register(GtkSource.View)