|
1 |
| -# FILE: autoload/conque_term/conque_globals.py {{{ |
| 1 | +# FILE: autoload/conque_term/conque_globals.py |
2 | 2 | # AUTHOR: Nico Raffo <nicoraffo@gmail.com>
|
3 | 3 | # WEBSITE: http://conque.googlecode.com
|
4 |
| -# MODIFIED: 2010-11-15 |
5 |
| -# VERSION: 2.0, for Vim 7.0 |
| 4 | +# MODIFIED: 2011-04-04 |
| 5 | +# VERSION: 2.1, for Vim 7.0 |
6 | 6 | # LICENSE:
|
7 | 7 | # Conque - Vim terminal/console emulator
|
8 |
| -# Copyright (C) 2009-2010 Nico Raffo |
| 8 | +# Copyright (C) 2009-2011 Nico Raffo |
9 | 9 | #
|
10 | 10 | # MIT License
|
11 | 11 | #
|
|
25 | 25 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
26 | 26 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
27 | 27 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
28 |
| -# THE SOFTWARE. }}} |
| 28 | +# THE SOFTWARE. |
29 | 29 |
|
30 | 30 | """Common global constants and functions for Conque."""
|
31 | 31 |
|
32 | 32 | import sys
|
33 |
| -import os |
34 | 33 | import re
|
35 | 34 |
|
36 | 35 |
|
37 | 36 |
|
38 | 37 |
|
| 38 | +# PYTHON VERSION |
| 39 | +CONQUE_PYTHON_VERSION = sys.version_info[0] |
39 | 40 |
|
| 41 | +# Encoding |
40 | 42 |
|
| 43 | +try: |
| 44 | + # Vim's character encoding |
| 45 | + import vim |
| 46 | + CONQUE_VIM_ENCODING = vim.eval('&encoding') |
41 | 47 |
|
| 48 | +except: |
| 49 | + CONQUE_VIM_ENCODING = 'utf-8' |
42 | 50 |
|
43 | 51 |
|
| 52 | +def u(str_val, str_encoding='utf-8', errors='strict'): |
| 53 | + """ Foolhardy attempt to make unicode string syntax compatible with both python 2 and 3. """ |
44 | 54 |
|
| 55 | + if not str_val: |
| 56 | + str_val = '' |
45 | 57 |
|
| 58 | + if CONQUE_PYTHON_VERSION == 3: |
| 59 | + return str_val |
46 | 60 |
|
| 61 | + else: |
| 62 | + return unicode(str_val, str_encoding, errors) |
47 | 63 |
|
| 64 | +def uchr(str): |
| 65 | + """ Foolhardy attempt to make unicode string syntax compatible with both python 2 and 3. """ |
48 | 66 |
|
| 67 | + if CONQUE_PYTHON_VERSION == 3: |
| 68 | + return chr(str) |
49 | 69 |
|
| 70 | + else: |
| 71 | + return unichr(str) |
| 72 | + |
| 73 | + |
| 74 | +# Logging |
50 | 75 |
|
51 | 76 |
|
52 |
| -# shared memory size |
53 |
| -CONQUE_SOLE_BUFFER_LENGTH = 1000 |
54 |
| -CONQUE_SOLE_INPUT_SIZE = 1000 |
55 |
| -CONQUE_SOLE_STATS_SIZE = 1000 |
56 |
| -CONQUE_SOLE_COMMANDS_SIZE = 255 |
57 |
| -CONQUE_SOLE_RESCROLL_SIZE = 255 |
58 |
| -CONQUE_SOLE_RESIZE_SIZE = 255 |
59 | 77 |
|
60 |
| -# interval of screen redraw |
61 |
| -# larger number means less frequent |
62 |
| -CONQUE_SOLE_SCREEN_REDRAW = 100 |
63 | 78 |
|
64 |
| -# interval of full buffer redraw |
65 |
| -# larger number means less frequent |
66 |
| -CONQUE_SOLE_BUFFER_REDRAW = 500 |
67 | 79 |
|
68 |
| -# interval of full output bucket replacement |
69 |
| -# larger number means less frequent, 1 = every time |
70 |
| -CONQUE_SOLE_MEM_REDRAW = 1000 |
71 | 80 |
|
72 |
| -# PYTHON VERSION |
73 |
| -CONQUE_PYTHON_VERSION = sys.version_info[0] |
74 | 81 |
|
75 | 82 |
|
76 |
| -def u(str_val, str_encoding='latin-1', errors='strict'): |
77 |
| - """foolhardy attempt to make unicode string syntax compatible with both python 2 and 3""" |
78 | 83 |
|
79 |
| - if not str_val: |
80 |
| - str_val = '' |
81 | 84 |
|
82 |
| - if CONQUE_PYTHON_VERSION == 3: |
83 |
| - return str_val |
84 | 85 |
|
85 |
| - else: |
86 |
| - return unicode(str_val, str_encoding, errors) |
87 | 86 |
|
88 |
| -# Escape sequence settings {{{ |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | +# Unix escape sequence settings |
89 | 92 |
|
90 | 93 | CONQUE_CTL = {
|
91 | 94 | 1: 'soh', # start of heading
|
@@ -209,7 +212,7 @@ def u(str_val, str_encoding='latin-1', errors='strict'):
|
209 | 212 | 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF
|
210 | 213 | ]
|
211 | 214 |
|
212 |
| -# Font codes {{{ |
| 215 | +# Font codes |
213 | 216 | CONQUE_FONT = {
|
214 | 217 | 0: {'description': 'Normal (default)', 'attributes': {'cterm': 'NONE', 'ctermfg': 'NONE', 'ctermbg': 'NONE', 'gui': 'NONE', 'guifg': 'NONE', 'guibg': 'NONE'}, 'normal': True},
|
215 | 218 | 1: {'description': 'Bold', 'attributes': {'cterm': 'BOLD', 'gui': 'BOLD'}, 'normal': False},
|
@@ -257,31 +260,60 @@ def u(str_val, str_encoding='latin-1', errors='strict'):
|
257 | 260 | 106: {'description': 'Set background color to Cyan', 'attributes': {'ctermbg': '14', 'guibg': '#009999'}, 'normal': False},
|
258 | 261 | 107: {'description': 'Set background color to White', 'attributes': {'ctermbg': '15', 'guibg': '#ffffff'}, 'normal': False}
|
259 | 262 | }
|
260 |
| -# }}} |
| 263 | + |
261 | 264 |
|
262 | 265 | # regular expression matching (almost) all control sequences
|
263 |
| -CONQUE_SEQ_REGEX = re.compile(u("(\x1b\[?\??#?[0-9;]*[a-zA-Z0-9@=>]|\x1b\][0-9];.*?\x07|[\x01-\x0f]|\x1b\([AB0])"), re.UNICODE) |
264 |
| -CONQUE_SEQ_REGEX_CTL = re.compile(u("^[\x01-\x0f]$"), re.UNICODE) |
265 |
| -CONQUE_SEQ_REGEX_CSI = re.compile(u("^\x1b\["), re.UNICODE) |
266 |
| -CONQUE_SEQ_REGEX_TITLE = re.compile(u("^\x1b\]"), re.UNICODE) |
267 |
| -CONQUE_SEQ_REGEX_HASH = re.compile(u("^\x1b#"), re.UNICODE) |
268 |
| -CONQUE_SEQ_REGEX_ESC = re.compile(u("^\x1b.$"), re.UNICODE) |
269 |
| -CONQUE_SEQ_REGEX_CHAR = re.compile(u("^\x1b\("), re.UNICODE) |
| 266 | +CONQUE_SEQ_REGEX = re.compile("(\x1b\[?\??#?[0-9;]*[a-zA-Z0-9@=>]|\x1b\][0-9];.*?\x07|[\x01-\x0f]|\x1b\([AB0])") |
| 267 | +CONQUE_SEQ_REGEX_CTL = re.compile("^[\x01-\x0f]$") |
| 268 | +CONQUE_SEQ_REGEX_CSI = re.compile("^\x1b\[") |
| 269 | +CONQUE_SEQ_REGEX_TITLE = re.compile("^\x1b\]") |
| 270 | +CONQUE_SEQ_REGEX_HASH = re.compile("^\x1b#") |
| 271 | +CONQUE_SEQ_REGEX_ESC = re.compile("^\x1b.$") |
| 272 | +CONQUE_SEQ_REGEX_CHAR = re.compile("^\x1b[()]") |
270 | 273 |
|
271 | 274 | # match table output
|
272 | 275 | CONQUE_TABLE_OUTPUT = re.compile("^\s*\|\s.*\s\|\s*$|^\s*\+[=+-]+\+\s*$")
|
273 | 276 |
|
274 |
| -# }}} |
275 |
| - |
276 |
| -# Windows subprocess config {{{ |
277 |
| - |
278 |
| -CONQUE_SEQ_REGEX_VK = re.compile(u("(\x1b\[\d{1,3}VK)"), re.UNICODE) |
279 |
| - |
280 |
| -# }}} |
281 |
| - |
| 277 | +# basic terminal colors |
282 | 278 | CONQUE_COLOR_SEQUENCE = (
|
283 | 279 | '000', '009', '090', '099', '900', '909', '990', '999',
|
284 | 280 | '000', '00f', '0f0', '0ff', 'f00', 'f0f', 'ff0', 'fff'
|
285 | 281 | )
|
286 | 282 |
|
287 |
| -# vim:foldmethod=marker |
| 283 | + |
| 284 | +# Windows subprocess constants |
| 285 | + |
| 286 | +# shared memory size |
| 287 | +CONQUE_SOLE_BUFFER_LENGTH = 1000 |
| 288 | +CONQUE_SOLE_INPUT_SIZE = 1000 |
| 289 | +CONQUE_SOLE_STATS_SIZE = 1000 |
| 290 | +CONQUE_SOLE_COMMANDS_SIZE = 255 |
| 291 | +CONQUE_SOLE_RESCROLL_SIZE = 255 |
| 292 | +CONQUE_SOLE_RESIZE_SIZE = 255 |
| 293 | + |
| 294 | +# interval of screen redraw |
| 295 | +# larger number means less frequent |
| 296 | +CONQUE_SOLE_SCREEN_REDRAW = 50 |
| 297 | + |
| 298 | +# interval of full buffer redraw |
| 299 | +# larger number means less frequent |
| 300 | +CONQUE_SOLE_BUFFER_REDRAW = 500 |
| 301 | + |
| 302 | +# interval of full output bucket replacement |
| 303 | +# larger number means less frequent, 1 = every time |
| 304 | +CONQUE_SOLE_MEM_REDRAW = 1000 |
| 305 | + |
| 306 | +# maximum number of lines with terminal colors |
| 307 | +# ignored if g:ConqueTerm_Color = 2 |
| 308 | +CONQUE_MAX_SYNTAX_LINES = 200 |
| 309 | + |
| 310 | +# windows input splitting on special keys |
| 311 | +CONQUE_WIN32_REGEX_VK = re.compile("(\x1b\[[0-9;]+VK)") |
| 312 | + |
| 313 | +# windows attribute string splitting |
| 314 | +CONQUE_WIN32_REGEX_ATTR = re.compile("((.)\\2*)", re.DOTALL) |
| 315 | + |
| 316 | +# special key attributes |
| 317 | +CONQUE_VK_ATTR_CTRL_PRESSED = u('1024') |
| 318 | + |
| 319 | + |
0 commit comments