parent
c36927cda1
commit
7e36a08844
|
@ -5,7 +5,7 @@ import math
|
||||||
import traceback
|
import traceback
|
||||||
from subprocess import Popen, PIPE, STDOUT
|
from subprocess import Popen, PIPE, STDOUT
|
||||||
|
|
||||||
import buffer, buffer.about, buffer.color, buffer.console, buffer.data
|
import buffer, buffer.about, buffer.colors, buffer.console, buffer.data
|
||||||
import buffer.fs, buffer.aes
|
import buffer.fs, buffer.aes
|
||||||
import bufferlist, color, completer, ispell, keyinput, method, minibuffer
|
import bufferlist, color, completer, ispell, keyinput, method, minibuffer
|
||||||
import mode, util, window
|
import mode, util, window
|
||||||
|
@ -484,7 +484,7 @@ class Application(object):
|
||||||
if self.has_buffer_name(name):
|
if self.has_buffer_name(name):
|
||||||
b = self.bufferlist.buffer_names[name]
|
b = self.bufferlist.buffer_names[name]
|
||||||
self.remove_buffer(b)
|
self.remove_buffer(b)
|
||||||
b = buffer.color.ColorDataBuffer(name, data)
|
b = buffer.colors.ColorDataBuffer(name, data)
|
||||||
if modename is not None:
|
if modename is not None:
|
||||||
b.modename = modename
|
b.modename = modename
|
||||||
window.Window(b, self, height=0, width=0)
|
window.Window(b, self, height=0, width=0)
|
||||||
|
@ -920,7 +920,7 @@ class Application(object):
|
||||||
def _draw_slot(self, i):
|
def _draw_slot(self, i):
|
||||||
slot = self.bufferlist.slots[i]
|
slot = self.bufferlist.slots[i]
|
||||||
w = slot.window
|
w = slot.window
|
||||||
redattr = color.build_attr(color.pairs('red', 'default'))
|
redattr = color.build('red', 'default')
|
||||||
x, y = w.first.xy()
|
x, y = w.first.xy()
|
||||||
lm, rm = w.mode.lmargin, w.mode.rmargin
|
lm, rm = w.mode.lmargin, w.mode.rmargin
|
||||||
lines = w.buffer.lines
|
lines = w.buffer.lines
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from buffer.color import ColorDataBuffer
|
from buffer.colors import ColorDataBuffer
|
||||||
|
|
||||||
_data = '''
|
_data = '''
|
||||||
[r:d:*]===============================================================================
|
[r:d:*]===============================================================================
|
||||||
|
|
|
@ -1,37 +1,14 @@
|
||||||
import re
|
import re
|
||||||
import lex
|
import lex
|
||||||
|
|
||||||
from buffer import Buffer
|
from buffer import Buffer
|
||||||
from buffer.data import DataBuffer
|
from buffer.data import DataBuffer
|
||||||
|
import color
|
||||||
from highlight import Highlighter
|
from highlight import Highlighter
|
||||||
|
|
||||||
color_map = {
|
|
||||||
'B': 'black',
|
|
||||||
'r': 'red',
|
|
||||||
'g': 'green',
|
|
||||||
'y': 'yellow',
|
|
||||||
'b': 'blue',
|
|
||||||
'm': 'magenta',
|
|
||||||
'c': 'cyan',
|
|
||||||
'w': 'white',
|
|
||||||
'd': 'default',
|
|
||||||
'*': 'bold',
|
|
||||||
}
|
|
||||||
|
|
||||||
reverse_map = {
|
|
||||||
'black': 'B',
|
|
||||||
'blue': 'b',
|
|
||||||
'cyan': 'c',
|
|
||||||
'default': 'd',
|
|
||||||
'green': 'g',
|
|
||||||
'magenta': 'm',
|
|
||||||
'red': 'r',
|
|
||||||
'white': 'w',
|
|
||||||
'yellow': 'y',
|
|
||||||
'bold': '*',
|
|
||||||
}
|
|
||||||
|
|
||||||
def get_cbuf_code(*args):
|
def get_cbuf_code(*args):
|
||||||
return '[' + ':'.join([reverse_map[x] for x in args]) + ']'
|
#return '[' + ':'.join([reverse_map.get(x, 'd') for x in args]) + ']'
|
||||||
|
return '[' + ':'.join([color.rev_ascii_map[x] for x in args]) + ']'
|
||||||
|
|
||||||
# NOTE: this highlighter will not reprocess the data given. it is intended to
|
# NOTE: this highlighter will not reprocess the data given. it is intended to
|
||||||
# be used with read-only buffers like DataBuffer and ColorBuffer
|
# be used with read-only buffers like DataBuffer and ColorBuffer
|
||||||
|
@ -64,7 +41,8 @@ class ColorHighlighter(Highlighter):
|
||||||
if j > i:
|
if j > i:
|
||||||
offset += self.append_token(y, i - offset, line[i:j], c)
|
offset += self.append_token(y, i - offset, line[i:j], c)
|
||||||
fields = m.group(1).split(':')
|
fields = m.group(1).split(':')
|
||||||
c = [color_map.get(x, x) for x in fields]
|
#c = [color_map.get(x, x) for x in fields]
|
||||||
|
c = [color.ascii_map.get(x, x) for x in fields]
|
||||||
offset += k - j
|
offset += k - j
|
||||||
i = k
|
i = k
|
||||||
else:
|
else:
|
|
@ -1,5 +1,5 @@
|
||||||
from buffer import Buffer, ACT_NORM
|
from buffer import Buffer, ACT_NORM
|
||||||
from buffer.color import ColorDataBuffer
|
from buffer.colors import ColorDataBuffer
|
||||||
|
|
||||||
# console is another singleton
|
# console is another singleton
|
||||||
console = None
|
console = None
|
||||||
|
|
151
color.py
151
color.py
|
@ -1,44 +1,9 @@
|
||||||
import curses
|
import curses
|
||||||
|
|
||||||
inited = False
|
colors = {}
|
||||||
#default_color = False
|
|
||||||
default_color = True
|
|
||||||
|
|
||||||
def init():
|
|
||||||
global colors, _colors, _pairs, attributes, inited, index
|
|
||||||
if not inited:
|
|
||||||
index = 1
|
|
||||||
|
|
||||||
colors = {
|
|
||||||
'cyan': curses.COLOR_CYAN,
|
|
||||||
'green': curses.COLOR_GREEN,
|
|
||||||
'red': curses.COLOR_RED,
|
|
||||||
'yellow': curses.COLOR_YELLOW,
|
|
||||||
'blue': curses.COLOR_BLUE,
|
|
||||||
'magenta': curses.COLOR_MAGENTA,
|
|
||||||
'black': curses.COLOR_BLACK,
|
|
||||||
'white': curses.COLOR_WHITE,
|
|
||||||
}
|
|
||||||
|
|
||||||
for i in range(0, curses.COLORS):
|
|
||||||
if curses.COLORS == 256:
|
|
||||||
colors['f%02x' % i] = i
|
|
||||||
else:
|
|
||||||
colors['f%02x' % i] = curses.COLOR_WHITE
|
|
||||||
|
|
||||||
if default_color:
|
|
||||||
colors["default"] = -1
|
|
||||||
|
|
||||||
_colors = []
|
_colors = []
|
||||||
_pairs = {}
|
_pairs = {}
|
||||||
|
index = 1
|
||||||
for key in _pairs:
|
|
||||||
fg, bg = key
|
|
||||||
curses.init_pair(index, colors[fg], colors[bg])
|
|
||||||
_pairs[key] = curses.color_pair(index)
|
|
||||||
_colors.append(key)
|
|
||||||
index = len(_colors) + 1
|
|
||||||
|
|
||||||
attributes = {
|
attributes = {
|
||||||
'bold': curses.A_BOLD,
|
'bold': curses.A_BOLD,
|
||||||
'reverse': curses.A_REVERSE,
|
'reverse': curses.A_REVERSE,
|
||||||
|
@ -48,44 +13,98 @@ def init():
|
||||||
'standout': curses.A_STANDOUT,
|
'standout': curses.A_STANDOUT,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inited = False
|
||||||
|
default_color = True
|
||||||
|
|
||||||
|
ascii_map = {
|
||||||
|
'*': 'bold',
|
||||||
|
}
|
||||||
|
rev_ascii_map = {
|
||||||
|
'bold': '*',
|
||||||
|
}
|
||||||
|
|
||||||
|
def add_color(name, value, abbrev):
|
||||||
|
colors[name] = value
|
||||||
|
ascii_map[abbrev] = name
|
||||||
|
rev_ascii_map[name] = abbrev
|
||||||
|
|
||||||
|
def color256(name, fallback, abbrev, r, g, b):
|
||||||
|
name2 = '%s%d%d%d' % (name, r, g, b)
|
||||||
|
abbrev2 = '%s%d%d%d' % (abbrev, r, g, b)
|
||||||
|
if curses.COLORS == 256:
|
||||||
|
value = 16 + r * 36 + g * 6 + b
|
||||||
|
else:
|
||||||
|
value = fallback
|
||||||
|
add_color(name2, value, abbrev2)
|
||||||
|
|
||||||
|
# PUBLIC METHODS
|
||||||
|
def init():
|
||||||
|
global _pairs, inited
|
||||||
|
if inited:
|
||||||
|
return
|
||||||
|
|
||||||
|
add_color('cyan', curses.COLOR_CYAN, 'c')
|
||||||
|
add_color('blue', curses.COLOR_BLUE, 'b')
|
||||||
|
add_color('green', curses.COLOR_GREEN, 'g')
|
||||||
|
add_color('red', curses.COLOR_RED, 'r')
|
||||||
|
add_color('yellow', curses.COLOR_YELLOW, 'y')
|
||||||
|
add_color('magenta', curses.COLOR_MAGENTA, 'm')
|
||||||
|
add_color('black', curses.COLOR_BLACK, 'B')
|
||||||
|
add_color('white', curses.COLOR_WHITE, 'w')
|
||||||
|
|
||||||
inited = True
|
inited = True
|
||||||
|
|
||||||
def pairs(fg, bg):
|
for i in range(0, 256):
|
||||||
if not curses.has_colors():
|
name = 'f%02x' % i
|
||||||
return curses.color_pair(0)
|
abbrev = 'f%02x' % i
|
||||||
|
add_color(name, i, abbrev)
|
||||||
|
|
||||||
global colors, _colors, _pairs, index
|
for i in range(0, 24):
|
||||||
key = (fg, bg)
|
color256('grey', curses.COLOR_WHITE, 'G', i, i, i)
|
||||||
if key not in _pairs:
|
|
||||||
assert index < curses.COLOR_PAIRS
|
|
||||||
if not default_color:
|
|
||||||
if fg == "default":
|
|
||||||
fg = "white"
|
|
||||||
if bg == "default":
|
|
||||||
bg = "black"
|
|
||||||
curses.init_pair(index, colors[fg], colors[bg])
|
|
||||||
_pairs[key] = curses.color_pair(index)
|
|
||||||
_colors.append(key)
|
|
||||||
index = len(_colors) + 1
|
|
||||||
return _pairs[key]
|
|
||||||
|
|
||||||
def get_pairs(index):
|
for i in range(1, 6):
|
||||||
if index == 0:
|
for j in range(0, i):
|
||||||
return ('white', 'black')
|
for k in range(0, i):
|
||||||
else:
|
color256('red', curses.COLOR_RED, 'r', i, j, k)
|
||||||
return _colors[index-1]
|
color256('green', curses.COLOR_GREEN, 'g', j, i, k)
|
||||||
|
color256('blue', curses.COLOR_BLUE, 'b', j, k, i)
|
||||||
|
|
||||||
def reverse_colors(attr):
|
for i in range(1, 6):
|
||||||
return attr ^ curses.A_REVERSE
|
for j in range(0, i):
|
||||||
|
color256('yellow', curses.COLOR_YELLOW, 'y', i, i, j)
|
||||||
|
color256('cyan', curses.COLOR_CYAN, 'c', j, i, i)
|
||||||
|
color256('magenta', curses.COLOR_MAGENTA, 'm', i, j, i)
|
||||||
|
|
||||||
|
if default_color:
|
||||||
|
colors['default'] = -1
|
||||||
|
ascii_map['d'] = 'default'
|
||||||
|
rev_ascii_map['default'] = 'd'
|
||||||
|
|
||||||
def build(fg, bg, *attr):
|
def build(fg, bg, *attr):
|
||||||
cattr = pairs(fg, bg)
|
v = curses.A_NORMAL | pairs(fg, bg)
|
||||||
return build_attr(cattr, *attr)
|
|
||||||
|
|
||||||
def build_attr(*attr):
|
|
||||||
v = curses.A_NORMAL
|
|
||||||
for x in attr:
|
for x in attr:
|
||||||
if type(x) == type(''):
|
if type(x) == type(''):
|
||||||
x = attributes[x]
|
x = attributes[x]
|
||||||
v = v | x
|
v = v | x
|
||||||
return v
|
return v
|
||||||
|
|
||||||
|
return build_attr(cattr, *attr)
|
||||||
|
|
||||||
|
# PRIVATE METHODS
|
||||||
|
def pairs(fg, bg):
|
||||||
|
if not curses.has_colors():
|
||||||
|
return curses.color_pair(0)
|
||||||
|
|
||||||
|
global index
|
||||||
|
fgi = colors.get(fg, colors['white'])
|
||||||
|
bgi = colors.get(bg, colors['black'])
|
||||||
|
key = (fgi, bgi)
|
||||||
|
if key not in _pairs:
|
||||||
|
assert index < curses.COLOR_PAIRS, "too many colors"
|
||||||
|
assert type(fgi) == type(0), "illegal fgi: %r" % fgi
|
||||||
|
assert type(bgi) == type(0), "illegal bgi: %r" % bgi
|
||||||
|
curses.init_pair(index, fgi, bgi)
|
||||||
|
_pairs[key] = curses.color_pair(index)
|
||||||
|
_colors.append(key)
|
||||||
|
index = len(_colors) + 1
|
||||||
|
return _pairs[key]
|
||||||
|
|
|
@ -2,7 +2,7 @@ import os, commands, re, tempfile
|
||||||
from subprocess import Popen, PIPE, STDOUT
|
from subprocess import Popen, PIPE, STDOUT
|
||||||
|
|
||||||
import buffer, completer, default, dirutil, regex, util, window
|
import buffer, completer, default, dirutil, regex, util, window
|
||||||
import buffer.color
|
import buffer.colors
|
||||||
from point import Point
|
from point import Point
|
||||||
|
|
||||||
class MethodError(Exception):
|
class MethodError(Exception):
|
||||||
|
@ -1114,7 +1114,7 @@ class ViewTokenColors(Method):
|
||||||
l = max(l, len(key))
|
l = max(l, len(key))
|
||||||
lines = ['Color information for %d tokens:\n' % len(keys), '\n']
|
lines = ['Color information for %d tokens:\n' % len(keys), '\n']
|
||||||
for key in keys:
|
for key in keys:
|
||||||
c = buffer.color.get_cbuf_code(*a.token_colors[key])
|
c = buffer.colors.get_cbuf_code(*a.token_colors[key])
|
||||||
lines.append('%s%-*s %r\n' % (c, l, key, a.token_colors[key]))
|
lines.append('%s%-*s %r\n' % (c, l, key, a.token_colors[key]))
|
||||||
a.color_data_buffer("*Token-Colors*", ''.join(lines), switch_to=True)
|
a.color_data_buffer("*Token-Colors*", ''.join(lines), switch_to=True)
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ from subprocess import Popen, PIPE, STDOUT
|
||||||
|
|
||||||
import buffer, default, dirutil, lex, regex, util, window
|
import buffer, default, dirutil, lex, regex, util, window
|
||||||
from point import Point
|
from point import Point
|
||||||
import buffer.color
|
import buffer.colors
|
||||||
from method.vc import VcBlame
|
from method.vc import VcBlame
|
||||||
|
|
||||||
from method import Method, Argument
|
from method import Method, Argument
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from method import Method
|
from method import Method
|
||||||
import buffer.color
|
import buffer.colors
|
||||||
import util
|
import util
|
||||||
import lex
|
import lex
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ class VcBlame(Method):
|
||||||
if d['tokens']:
|
if d['tokens']:
|
||||||
suffix = ''
|
suffix = ''
|
||||||
for t in d['tokens']:
|
for t in d['tokens']:
|
||||||
code = buffer.color.get_cbuf_code(*t.color)
|
code = buffer.colors.get_cbuf_code(*t.color)
|
||||||
suffix += code + util.cbuf_escape(t.string)
|
suffix += code + util.cbuf_escape(t.string)
|
||||||
else:
|
else:
|
||||||
suffix = d['content'] + '\n'
|
suffix = d['content'] + '\n'
|
||||||
|
|
|
@ -5,7 +5,7 @@ class ColortestGrammar(Grammar):
|
||||||
rules = []
|
rules = []
|
||||||
for i in range(0, 256):
|
for i in range(0, 256):
|
||||||
c = '%02x' % i
|
c = '%02x' % i
|
||||||
rules.append(PatternRule(c, c))
|
rules.append(PatternRule('z' + c, c))
|
||||||
|
|
||||||
class Colortest(Fundamental):
|
class Colortest(Fundamental):
|
||||||
name = 'Colortest'
|
name = 'Colortest'
|
||||||
|
@ -13,6 +13,6 @@ class Colortest(Fundamental):
|
||||||
colors = {}
|
colors = {}
|
||||||
for i in range(0, 256):
|
for i in range(0, 256):
|
||||||
c = '%02x' % i
|
c = '%02x' % i
|
||||||
colors[c] = ('default', 'f' + c)
|
colors['z' + c] = ('default', 'f' + c)
|
||||||
|
|
||||||
install = Colortest.install
|
install = Colortest.install
|
||||||
|
|
|
@ -558,7 +558,8 @@ class Python(mode.Fundamental):
|
||||||
closetags = {')': '(', ']': '[', '}': '{'}
|
closetags = {')': '(', ']': '[', '}': '{'}
|
||||||
commentc = '#'
|
commentc = '#'
|
||||||
colors = {
|
colors = {
|
||||||
'python.def': ('blue', 'default', 'bold'),
|
#'python.def': ('blue', 'default', 'bold'),
|
||||||
|
'python.def': ('red532', 'default', 'bold'),
|
||||||
'python.class': ('yellow', 'default', 'bold'),
|
'python.class': ('yellow', 'default', 'bold'),
|
||||||
'python.decorator': ('magenta', 'default'),
|
'python.decorator': ('magenta', 'default'),
|
||||||
'python.reserved': ('magenta', 'default', 'bold'),
|
'python.reserved': ('magenta', 'default', 'bold'),
|
||||||
|
|
Loading…
Reference in New Issue