parent
c36927cda1
commit
7e36a08844
|
@ -5,7 +5,7 @@ import math
|
|||
import traceback
|
||||
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 bufferlist, color, completer, ispell, keyinput, method, minibuffer
|
||||
import mode, util, window
|
||||
|
@ -484,7 +484,7 @@ class Application(object):
|
|||
if self.has_buffer_name(name):
|
||||
b = self.bufferlist.buffer_names[name]
|
||||
self.remove_buffer(b)
|
||||
b = buffer.color.ColorDataBuffer(name, data)
|
||||
b = buffer.colors.ColorDataBuffer(name, data)
|
||||
if modename is not None:
|
||||
b.modename = modename
|
||||
window.Window(b, self, height=0, width=0)
|
||||
|
@ -920,7 +920,7 @@ class Application(object):
|
|||
def _draw_slot(self, i):
|
||||
slot = self.bufferlist.slots[i]
|
||||
w = slot.window
|
||||
redattr = color.build_attr(color.pairs('red', 'default'))
|
||||
redattr = color.build('red', 'default')
|
||||
x, y = w.first.xy()
|
||||
lm, rm = w.mode.lmargin, w.mode.rmargin
|
||||
lines = w.buffer.lines
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from buffer.color import ColorDataBuffer
|
||||
from buffer.colors import ColorDataBuffer
|
||||
|
||||
_data = '''
|
||||
[r:d:*]===============================================================================
|
||||
|
|
|
@ -1,37 +1,14 @@
|
|||
import re
|
||||
import lex
|
||||
|
||||
from buffer import Buffer
|
||||
from buffer.data import DataBuffer
|
||||
import color
|
||||
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):
|
||||
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
|
||||
# be used with read-only buffers like DataBuffer and ColorBuffer
|
||||
|
@ -64,7 +41,8 @@ class ColorHighlighter(Highlighter):
|
|||
if j > i:
|
||||
offset += self.append_token(y, i - offset, line[i:j], c)
|
||||
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
|
||||
i = k
|
||||
else:
|
|
@ -1,5 +1,5 @@
|
|||
from buffer import Buffer, ACT_NORM
|
||||
from buffer.color import ColorDataBuffer
|
||||
from buffer.colors import ColorDataBuffer
|
||||
|
||||
# console is another singleton
|
||||
console = None
|
||||
|
|
151
color.py
151
color.py
|
@ -1,44 +1,9 @@
|
|||
import curses
|
||||
|
||||
inited = False
|
||||
#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 = {}
|
||||
|
||||
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
|
||||
|
||||
index = 1
|
||||
attributes = {
|
||||
'bold': curses.A_BOLD,
|
||||
'reverse': curses.A_REVERSE,
|
||||
|
@ -48,44 +13,98 @@ def init():
|
|||
'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
|
||||
|
||||
def pairs(fg, bg):
|
||||
if not curses.has_colors():
|
||||
return curses.color_pair(0)
|
||||
for i in range(0, 256):
|
||||
name = 'f%02x' % i
|
||||
abbrev = 'f%02x' % i
|
||||
add_color(name, i, abbrev)
|
||||
|
||||
global colors, _colors, _pairs, index
|
||||
key = (fg, bg)
|
||||
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]
|
||||
for i in range(0, 24):
|
||||
color256('grey', curses.COLOR_WHITE, 'G', i, i, i)
|
||||
|
||||
def get_pairs(index):
|
||||
if index == 0:
|
||||
return ('white', 'black')
|
||||
else:
|
||||
return _colors[index-1]
|
||||
for i in range(1, 6):
|
||||
for j in range(0, i):
|
||||
for k in range(0, i):
|
||||
color256('red', curses.COLOR_RED, 'r', i, j, k)
|
||||
color256('green', curses.COLOR_GREEN, 'g', j, i, k)
|
||||
color256('blue', curses.COLOR_BLUE, 'b', j, k, i)
|
||||
|
||||
def reverse_colors(attr):
|
||||
return attr ^ curses.A_REVERSE
|
||||
for i in range(1, 6):
|
||||
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):
|
||||
cattr = pairs(fg, bg)
|
||||
return build_attr(cattr, *attr)
|
||||
|
||||
def build_attr(*attr):
|
||||
v = curses.A_NORMAL
|
||||
v = curses.A_NORMAL | pairs(fg, bg)
|
||||
for x in attr:
|
||||
if type(x) == type(''):
|
||||
x = attributes[x]
|
||||
v = v | x
|
||||
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
|
||||
|
||||
import buffer, completer, default, dirutil, regex, util, window
|
||||
import buffer.color
|
||||
import buffer.colors
|
||||
from point import Point
|
||||
|
||||
class MethodError(Exception):
|
||||
|
@ -1114,7 +1114,7 @@ class ViewTokenColors(Method):
|
|||
l = max(l, len(key))
|
||||
lines = ['Color information for %d tokens:\n' % len(keys), '\n']
|
||||
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]))
|
||||
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
|
||||
from point import Point
|
||||
import buffer.color
|
||||
import buffer.colors
|
||||
from method.vc import VcBlame
|
||||
|
||||
from method import Method, Argument
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from method import Method
|
||||
import buffer.color
|
||||
import buffer.colors
|
||||
import util
|
||||
import lex
|
||||
|
||||
|
@ -46,7 +46,7 @@ class VcBlame(Method):
|
|||
if d['tokens']:
|
||||
suffix = ''
|
||||
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)
|
||||
else:
|
||||
suffix = d['content'] + '\n'
|
||||
|
|
|
@ -5,7 +5,7 @@ class ColortestGrammar(Grammar):
|
|||
rules = []
|
||||
for i in range(0, 256):
|
||||
c = '%02x' % i
|
||||
rules.append(PatternRule(c, c))
|
||||
rules.append(PatternRule('z' + c, c))
|
||||
|
||||
class Colortest(Fundamental):
|
||||
name = 'Colortest'
|
||||
|
@ -13,6 +13,6 @@ class Colortest(Fundamental):
|
|||
colors = {}
|
||||
for i in range(0, 256):
|
||||
c = '%02x' % i
|
||||
colors[c] = ('default', 'f' + c)
|
||||
colors['z' + c] = ('default', 'f' + c)
|
||||
|
||||
install = Colortest.install
|
||||
|
|
|
@ -558,7 +558,8 @@ class Python(mode.Fundamental):
|
|||
closetags = {')': '(', ']': '[', '}': '{'}
|
||||
commentc = '#'
|
||||
colors = {
|
||||
'python.def': ('blue', 'default', 'bold'),
|
||||
#'python.def': ('blue', 'default', 'bold'),
|
||||
'python.def': ('red532', 'default', 'bold'),
|
||||
'python.class': ('yellow', 'default', 'bold'),
|
||||
'python.decorator': ('magenta', 'default'),
|
||||
'python.reserved': ('magenta', 'default', 'bold'),
|
||||
|
|
Loading…
Reference in New Issue