-
Notifications
You must be signed in to change notification settings - Fork 0
/
fluent-logger.py
152 lines (124 loc) · 6.01 KB
/
fluent-logger.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sublime
import sublime_plugin
import os
import sys
from time import time
PLUGIN_DIR = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, os.path.join(PLUGIN_DIR, 'libs'))
from fluent import sender, event
SETTINGS_FILE = 'fluent-logger.sublime-settings'
OP_DICT = {
sublime.OP_EQUAL: 'OP_EQUAL',
sublime.OP_NOT_EQUAL: 'OP_NOT_EQUAL',
sublime.OP_REGEX_MATCH: 'OP_REGEX_MATCH',
sublime.OP_NOT_REGEX_MATCH: 'OP_NOT_REGEX_MATCH',
sublime.OP_REGEX_CONTAINS: 'OP_REGEX_CONTAINS',
sublime.OP_NOT_REGEX_CONTAINS: 'OP_NOT_REGEX_CONTAINS'
}
class FluentLoggerSublimetext(sublime_plugin.EventListener):
def _get_data_from_view(self, view):
window = view.window()
activated = SETTINGS.get('activated_data')
data = {}
if activated["version"]: data["version"] = sublime.version()
if activated["platform"]: data["platform"] = sublime.platform()
if activated["arch"]: data["arch"] = sublime.arch()
if activated["file_name"]: data["file_name"] = view.file_name()
if activated["size"]: data["size"] = view.size()
if activated["viewport_extent"]: data["viewport_extent"] = view.viewport_extent()
if activated["layout_extent"]: data["layout_extent"] = view.layout_extent()
if activated["line_height"]: data["line_height"] = view.line_height()
if activated["em_width"]: data["em_width"] = view.em_width()
if activated["change_count"]: data["change_count"] = view.change_count()
if activated["encoding"]: data["encoding"] = view.encoding()
if activated["line_endings"]: data["line_endings"] = view.line_endings()
if activated["overwrite_status"]: data["overwrite_status"] = view.overwrite_status()
if activated["syntax"]: data["syntax"] = view.settings().get('syntax')
return data
def on_new(self, view):
if not SETTINGS.get('activated_events')['on_new']: return
event.Event('on_new', self._get_data_from_view(view))
def on_clone(self, view):
if not SETTINGS.get('activated_events')['on_clone']: return
event.Event('on_clone', self._get_data_from_view(view))
def on_load(self, view):
if not SETTINGS.get('activated_events')['on_load']: return
event.Event('on_load', self._get_data_from_view(view))
def on_pre_close(self, view):
if not SETTINGS.get('activated_events')['on_pre_close']: return
event.Event('on_pre_close', self._get_data_from_view(view))
def on_close(self, view):
if not SETTINGS.get('activated_events')['on_close']: return
event.Event('on_close', self._get_data_from_view(view))
def on_pre_save(self, view):
if not SETTINGS.get('activated_events')['on_pre_save']: return
event.Event('on_pre_save', self._get_data_from_view(view))
def on_post_save(self, view):
if not SETTINGS.get('activated_events')['on_post_save']: return
event.Event('on_post_save', self._get_data_from_view(view))
def on_modified(self, view):
if not SETTINGS.get('activated_events')['on_modified']: return
event.Event('on_modified', self._get_data_from_view(view))
def on_selection_modified(self, view):
if not SETTINGS.get('activated_events')['on_selection_modified']: return
event.Event('on_selection_modified', self._get_data_from_view(view))
def on_activated(self, view):
self.active_from = time()
if not SETTINGS.get('activated_events')['on_activated']: return
event.Event('on_activated', self._get_data_from_view(view))
def on_deactivated(self, view):
data = self._get_data_from_view(view)
active_time = time() - self.active_from
data['active_time'] = active_time
self.active_from = None
if not SETTINGS.get('activated_events')['on_deactivated']: return
event.Event('on_deactivated', data)
def on_text_command(self, view, command_name, args):
if not SETTINGS.get('activated_events')['on_text_command']: return
data = self._get_data_from_view(view)
data['command_name'] = command_name
data['args'] = args
event.Event('on_text_command', data)
def on_window_command(self, window, command_name, args):
if not SETTINGS.get('activated_events')['on_window_command']: return
view = window.active_view()
data = self._get_data_from_view(view)
data['command_name'] = command_name
data['args'] = args
event.Event('on_window_command', data)
def post_text_command(self, view, command_name, args):
if not SETTINGS.get('activated_events')['post_text_command']: return
data = self._get_data_from_view(view)
data['command_name'] = command_name
data['args'] = args
event.Event('post_text_command', data)
def post_window_command(self, window, command_name, args):
if not SETTINGS.get('activated_events')['post_window_command']: return
data = self._get_data_from_view(view)
data['command_name'] = command_name
data['args'] = args
event.Event('post_window_command', data)
def on_query_context(self, view, key, operator, operand, match_all):
if not SETTINGS.get('activated_events')['on_query_context']: return
data = self._get_data_from_view(view)
data['key'] = key
data['operator'] = OP_DICT[operator]
data['operand'] = operand
data['match_all'] = match_all
event.Event('on_query_context', data)
def on_query_completions(self, view, prefix, locations):
if not SETTINGS.get('activated_events')['on_query_completions']: return
data = self._get_data_from_view(view)
data['prefix'] = prefix
data['locations'] = locations
event.Event('on_query_completions', data)
def plugin_loaded():
global SETTINGS
SETTINGS = sublime.load_settings(SETTINGS_FILE)
sender.setup(
str(SETTINGS.get('tagprefix')),
host=str(SETTINGS.get('host')),
port=int(SETTINGS.get('port'))
)