Skip to content

Commit 077c5ac

Browse files
committed
Initial commit
0 parents  commit 077c5ac

File tree

4 files changed

+188
-0
lines changed

4 files changed

+188
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.cache
2+
*.pyc
3+
*.sublime-project
4+
*.sublime-workspace

Default.sublime-keymap

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
3+
{
4+
"command": "adb_launch",
5+
"keys": ["ctrl+d"]
6+
}
7+
]

adb.tmLanguage

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>name</key>
6+
<string>Android Debug Bridge</string>
7+
<key>patterns</key>
8+
<array>
9+
<dict>
10+
<key>match</key>
11+
<string>^E.*</string>
12+
<key>name</key>
13+
<string>invalid.adb</string>
14+
</dict>
15+
<dict>
16+
<key>match</key>
17+
<string>^W.*</string>
18+
<key>name</key>
19+
<string>keyword</string>
20+
</dict>
21+
<dict>
22+
<key>match</key>
23+
<string>^D.*</string>
24+
<key>name</key>
25+
<string>comment</string>
26+
</dict>
27+
</array>
28+
<key>scopeName</key>
29+
<string>source.adb</string>
30+
<key>uuid</key>
31+
<string>95F39BAA-EBD3-468A-9965-2C47C3B30C11</string>
32+
</dict>
33+
</plist>

adbview.py

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
import sublime, sublime_plugin
2+
import subprocess
3+
import Queue
4+
import threading
5+
import traceback
6+
7+
8+
class ADBView(object):
9+
LINE = 0
10+
FOLD_ALL = 1
11+
CLEAR = 2
12+
SCROLL = 3
13+
VIEWPORT_POSITION = 4
14+
15+
def __init__(self, s=True, settingsprefix=None):
16+
self.queue = Queue.Queue()
17+
self.name = "ADB"
18+
self.closed = True
19+
self.doScroll = s
20+
self.view = None
21+
self.settingsprefix = settingsprefix
22+
23+
def is_open(self):
24+
return not self.closed
25+
26+
def open(self):
27+
if self.view == None or self.view.window() == None:
28+
self.create_view()
29+
30+
def add_line(self, line):
31+
if self.is_open():
32+
self.queue.put((ADBView.LINE, line))
33+
sublime.set_timeout(self.update, 0)
34+
35+
def scroll(self, line):
36+
if self.is_open():
37+
self.queue.put((ADBView.SCROLL, line))
38+
sublime.set_timeout(self.update, 0)
39+
40+
def set_viewport_position(self, pos):
41+
if self.is_open():
42+
self.queue.put((ADBView.VIEWPORT_POSITION, pos))
43+
sublime.set_timeout(self.update, 0)
44+
45+
def clear(self):
46+
if self.is_open():
47+
self.queue.put((ADBView.CLEAR, None))
48+
sublime.set_timeout(self.update, 0)
49+
50+
def create_view(self):
51+
self.view = sublime.active_window().new_file()
52+
self.view.set_name(self.name)
53+
self.view.set_scratch(True)
54+
self.view.set_read_only(True)
55+
self.view.set_syntax_file("Packages/ADBView/adb.tmLanguage")
56+
self.closed = False
57+
58+
def is_closed(self):
59+
return self.closed
60+
61+
def was_closed(self):
62+
self.closed = True
63+
64+
def fold_all(self):
65+
if self.is_open():
66+
self.queue.put((ADBView.FOLD_ALL, None))
67+
68+
def get_view(self):
69+
return self.view
70+
71+
def update(self):
72+
if not self.is_open():
73+
return
74+
insert = ""
75+
try:
76+
while True:
77+
cmd, data = self.queue.get_nowait()
78+
if cmd == ADBView.LINE:
79+
insert += data
80+
elif cmd == ADBView.FOLD_ALL:
81+
self.view.run_command("fold_all")
82+
elif cmd == ADBView.CLEAR:
83+
insert = ""
84+
self.view.set_read_only(False)
85+
e = self.view.begin_edit()
86+
self.view.erase(e, sublime.Region(0, self.view.size()))
87+
self.view.end_edit(e)
88+
self.view.set_read_only(True)
89+
elif cmd == ADBView.SCROLL:
90+
self.view.run_command("goto_line", {"line": data + 1})
91+
elif cmd == ADBView.VIEWPORT_POSITION:
92+
self.view.set_viewport_position(data, True)
93+
self.queue.task_done()
94+
except Queue.Empty:
95+
# get_nowait throws an exception when there's nothing..
96+
pass
97+
except:
98+
traceback.print_exc()
99+
finally:
100+
if len(insert) > 0:
101+
self.view.set_read_only(False)
102+
e = self.view.begin_edit()
103+
self.view.insert(e, self.view.size(), insert)
104+
self.view.end_edit(e)
105+
self.view.set_read_only(True)
106+
if self.doScroll:
107+
self.view.show(self.view.size())
108+
109+
adb_view = ADBView()
110+
adb_process = None
111+
112+
def output(pipe):
113+
while True:
114+
try:
115+
if adb_process.poll() != None:
116+
break
117+
line = pipe.readline().strip()
118+
119+
if len(line) > 0:
120+
adb_view.add_line("%s\n" % line)
121+
except:
122+
traceback.print_exc()
123+
124+
125+
class AdbLaunch(sublime_plugin.WindowCommand):
126+
def run(self):
127+
print "launch"
128+
global adb_process
129+
if adb_process == None or adb_process.poll() != None:
130+
adb_process = subprocess.Popen(["adb", "logcat"], shell=False, stdout=subprocess.PIPE)
131+
adb_view.open()
132+
t = threading.Thread(target=output, args=(adb_process.stdout,))
133+
t.start()
134+
135+
def is_enabled(self):
136+
return True
137+
138+
139+
class AdbEventListener(sublime_plugin.EventListener):
140+
def on_close(self, view):
141+
if adb_view.is_open() and view.id() == adb_view.get_view().id():
142+
adb_view.was_closed()
143+
adb_process.kill()
144+

0 commit comments

Comments
 (0)