-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathlog_toggler.py
86 lines (78 loc) · 2.94 KB
/
log_toggler.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
import sublime
import sublime_plugin
###
# Note: The original version of this plugin can be found at:
# https://github.com/STealthy-and-haSTy/SublimeScraps/
#
# This version may not be up to date with any enhancements or changes that may
# have been made since this version was forked for use in this repository.
#
# Plugin by: Terence Martin <https://github.com/OdatNurd>
###
# This plugin provides a command that you can use to toggle the state of the
# three internal Sublime logging commands on and off. It takes as an argument
# the type of logging to toggle, which can be one of "log_commands",
# "log_input", "log_result_regex" or "log_build_systens".
#
# Note that the plugin assumes that you're only using these commands to change
# the state of the logging; since there is no API for getting the current state
# for the log toggles, the command here can't detect if you've changed the
# state of the logging via some external mechanism.
#
# This could be used in a key binding as well as in a sublime-commands or
# sublime-menu file.
#
# In a sublime-menu, the command will display as checked when logging for that
# type of log is enabled if you include the "checkbox" attribute to the menu
# entry. The command also has a default description which displays what command
# it will execute when it's selected.
#
# As an example, you can add the following to a file named Context.sublime-menu
# in your User package to include the commands in the context menu.
#
# [
# { "caption": "-", "id": "end" },
# {
# "command": "toggle_sublime_logging",
# "checkbox": true,
# "caption": "Log Commands",
# "args": {"log_type": "log_commands"},
# },
# {
# "command": "toggle_sublime_logging",
# "checkbox": true,
# "caption": "Log Input",
# "args": {"log_type": "log_input"},
# },
# {
# "command": "toggle_sublime_logging",
# "checkbox": true,
# "caption": "Log Result Regex",
# "args": {"log_type": "log_result_regex"},
# },
# {
# "command": "toggle_sublime_logging",
# "checkbox": true,
# "caption": "Log Build Systems",
# "args": {"log_type": "log_build_systens"},
# }
# ]
_log_state = {
"log_commands": False,
"log_input": False,
"log_result_regex": False,
"log_build_systems": False
}
class ToggleSublimeLoggingCommand(sublime_plugin.ApplicationCommand):
"""
Toggle the state of Sublime's internal logging to the console based on the
log_type parameter, which should be one of the three sublime module API
endpoints, "log_command", "log_input" or "log_result_regex".
"""
def run(self, log_type):
_log_state[log_type] = not _log_state[log_type]
getattr(sublime, log_type)(_log_state[log_type])
def description(self, log_type):
return "sublime.{0}({1})".format(log_type, not _log_state[log_type])
def is_checked(self, log_type):
return _log_state[log_type]