@ -0,0 +1 @@ | |||
vim/bundle/* |
@ -1 +0,0 @@ | |||
12 |
@ -1 +0,0 @@ | |||
12 |
@ -1,3 +0,0 @@ | |||
snippet ! "!important" | |||
!important | |||
endsnippet |
@ -1,39 +0,0 @@ | |||
snippet for "Boucle for" | |||
{% for item in $1 %} | |||
{% endfor %} | |||
endsnippet | |||
snippet if "If cond" | |||
{% if $1 %} | |||
{% else %} | |||
{% endif %} | |||
endsnippet | |||
snippet dump "Dump function" | |||
{{ dump($1) }} | |||
endsnippet | |||
snippet trans "Trans function" | |||
{{ '$1'|trans }} | |||
endsnippet | |||
snippet macro "Macro function" | |||
{% import _self as macros %} | |||
{% macro $1() %} | |||
{% endmacro %} | |||
{{ macros.$1() }} | |||
endsnippet | |||
snippet {{ "Print" | |||
{{ $1 }} | |||
endsnippet | |||
snippet {% "Function" | |||
{% $1 %} | |||
endsnippet |
@ -1,77 +0,0 @@ | |||
snippet pf "Create a public function" b | |||
public function $1() | |||
{ | |||
return $this; | |||
} | |||
endsnippet | |||
snippet ppf "Create a private function" b | |||
public function $1() | |||
{ | |||
return $this; | |||
} | |||
endsnippet | |||
snippet ptf "Create a protected function" b | |||
public function $1() | |||
{ | |||
return $this; | |||
} | |||
endsnippet | |||
snippet sf2:c "Create a symfony2 controller function" b | |||
/** | |||
* @param $request | |||
* @return \Symfony\Bundle\FrameworkBundle\Controller\Response | |||
*/ | |||
public function $1Action(Request $request) | |||
{ | |||
return $this->defaultRender(); | |||
} | |||
endsnippet | |||
snippet page "Create trinity page" | |||
<?php | |||
`!p snip.rv = os.popen('/home/simon/bin/namespace ' + path).readline().strip()` | |||
use Trinity\Bundle\ContentManagerBundle\Model\Page; | |||
use Trinity\Bundle\ContentManagerBundle\Model\Block; | |||
class `!p snip.rv = snip.basename` extends Page | |||
{ | |||
public function __construct($template = '$1') | |||
{ | |||
parent::__construct($template); | |||
} | |||
public function getConfiguration() | |||
{ | |||
return $this->configuration | |||
->setDefaultController('FooBarBundle:MyController:bob') | |||
->setDefaultControllerClass('Foo\Bundle\BarBundle::bobAction') | |||
->setBlock('title', 'Trinity\Bundle\ContentManagerBundle\Form\Type\BlockType') | |||
->setBlock('content', 'Trinity\Bundle\ContentManagerBundle\Form\Type\TinymceAdvancedBlockType') | |||
} | |||
public function getBlockTitle() | |||
{ | |||
return $this->getBlock('title'); | |||
} | |||
public function getBlockTitle(Block $block) | |||
{ | |||
return $this->setBlock($block); | |||
} | |||
public function getBlockContent() | |||
{ | |||
return $this->getBlock('content'); | |||
} | |||
public function setBlockContent(Block $block) | |||
{ | |||
return $this->setBlock($block); | |||
} | |||
} | |||
endsnippet |
@ -1,34 +0,0 @@ | |||
snippet trans "trans" | |||
<trans-unit id="$1"> | |||
<source><![CDATA[$2]]></source> | |||
<target><![CDATA[$3]]></target> | |||
</trans-unit> | |||
endsnippet | |||
snippet schema "schema" | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<database defaultIdMethod="native" name="default" namespace="$1"> | |||
$2 | |||
</database> | |||
endsnippet | |||
snippet table "table" | |||
<table name="$1" isCrossRef="$2"> | |||
<column name="id" type="INTEGER" primaryKey="true" required="true" autoIncrement="true"/> | |||
<behavior name="timestampable"/> | |||
<!-- | |||
<foreign-key foreignTable="foo" onDelete="none" onUpdate="cascade"> | |||
<reference local="foo_id" foreign="id"/> | |||
</foreign-key> | |||
<behavior name="sortable"/> | |||
<behavior name="uploadable"> | |||
<parameter name="fields" value="picture"/> | |||
<parameter name="paths" value="uploads/post/"/> | |||
</behavior> | |||
--> | |||
</table> | |||
endsnippet |
@ -1,20 +0,0 @@ | |||
# vim-twig | |||
## About | |||
Supports Twig PHP templates [http://www.twig-project.org/][1] | |||
Based on Jinja2 syntax highlighting by [Armin Ronacher][2] | |||
----- | |||
## Installation | |||
This scripts bundles is compatible with [vim-addon-manager][3] | |||
## Changes | |||
### 2011-07-29 | |||
- Re-based the syntax highlighting to properly support all tags | |||
- Added support for .html.twig files | |||
[1]: http://www.twig-project.org/ | |||
[2]: http://www.vim.org/scripts/script.php?script_id=1856 | |||
[3]: https://github.com/MarcWeber/vim-addon-manager |
@ -1,5 +0,0 @@ | |||
" Twig | |||
autocmd BufNewFile,BufRead *.twig set filetype=twig | |||
" HTML Twig | |||
autocmd BufNewFile,BufRead *.html.twig set filetype=html.twig |
@ -1,18 +0,0 @@ | |||
" Vim filetype plugin | |||
" Language: Twig | |||
" Maintainer: F. Gabriel Gosselin <gabrielNOSPAM@evidens.ca> | |||
if exists("b:did_ftplugin") | |||
finish | |||
endif | |||
runtime! ftplugin/html.vim ftplugin/html*.vim ftplugin/html/*.vim | |||
unlet! b:did_ftplugin | |||
setlocal comments=s:{#,ex:#} | |||
setlocal formatoptions+=tcqln | |||
" setlocal formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\|^[-*+]\\s\\+ | |||
let b:undo_ftplugin .= "|setl cms< com< fo<" | |||
" vim:set sw=2: |
@ -1,46 +0,0 @@ | |||
# Basic Twig snippets | |||
# Maintainer: F. Gabriel Gosselin <gabrielNOSPAM@evidens.ca> | |||
# include | |||
snippet inc | |||
{% include '${1}' %} | |||
# extend | |||
snippet ext | |||
{% extends '${1:template.html.twig}' %} | |||
# extends | |||
snippet extends | |||
{% extends '${1:template}' %}${2} | |||
# if | |||
snippet if | |||
{% if ${1} %} | |||
${2} | |||
{% endif %} | |||
# else | |||
snippet else | |||
{% else %} | |||
${1} | |||
# for | |||
snippet for | |||
{% for ${2:} in ${1} %} | |||
${3}{{ $2 }} | |||
{% endfor %} | |||
# Set | |||
snippet set | |||
{% set ${1:var} = ${2:value} %}${3} | |||
# Print variable | |||
snippet }} | |||
{{ ${1} }}${2} | |||
# Single Regular execution block | |||
snippet %% | |||
{% ${1} %}${2} | |||
# Comment block | |||
snippet ## | |||
{# ${1} #}${2} | |||
# Open/close block | |||
snippet %end | |||
{% ${1:block} %}${2}{% end$1 %} | |||
# Named block | |||
snippet block | |||
{% block ${1:name} %}${2}{% endblock %} | |||
snippet f_date | |||
{{ ${1:a_date}|date("${2:m/d/Y}") }} |
@ -1,109 +0,0 @@ | |||
" Vim syntax file | |||
" Language: Twig template | |||
" Maintainer: Gabriel Gosselin <gabrielNOSPAM@evidens.ca> | |||
" Last Change: 2011 July 27 | |||
" Version: 1.0 | |||
" | |||
" Based Jinja syntax by: Armin Ronacher <armin.ronacher@active-4.com> | |||
" | |||
" Known Bugs: | |||
" because of odd limitations dicts and the modulo operator | |||
" appear wrong in the template. | |||
" | |||
" Changes: | |||
" | |||
" 2008 May 9: Added support for Jinja2 changes (new keyword rules) | |||
" 2011 July 27: Changed all references of jinja tp twig | |||
syntax case match | |||
" Jinja template built-in tags and parameters (without filter, macro, is and raw, they | |||
" have special threatment) | |||
syn keyword twigStatement containedin=twigVarBlock,twigTagBlock,twigNested contained and if else in not or recursive as import | |||
syn keyword twigStatement containedin=twigVarBlock,twigTagBlock,twigNested contained is filter skipwhite nextgroup=twigFilter | |||
syn keyword twigStatement containedin=twigTagBlock contained macro skipwhite nextgroup=twigFunction | |||
syn keyword twigStatement containedin=twigTagBlock contained block skipwhite nextgroup=twigBlockName | |||
" Variable Names | |||
syn match twigVariable containedin=twigVarBlock,twigTagBlock,twigNested contained skipwhite /[a-zA-Z_][a-zA-Z0-9_]*/ | |||
syn keyword twigSpecial containedin=twigVarBlock,twigTagBlock,twigNested contained false true none loop super caller varargs kwargs | |||
" Filters | |||
syn match twigOperator "|" containedin=twigVarBlock,twigTagBlock,twigNested contained nextgroup=twigFilter | |||
syn match twigFilter contained skipwhite /[a-zA-Z_][a-zA-Z0-9_]*/ | |||
syn match twigFunction contained skipwhite /[a-zA-Z_][a-zA-Z0-9_]*/ | |||
syn match twigBlockName contained skipwhite /[a-zA-Z_][a-zA-Z0-9_]*/ | |||
" Jinja template constants | |||
syn region twigString containedin=twigVarBlock,twigTagBlock,twigNested contained start=/"/ skip=/\\"/ end=/"/ | |||
syn region twigString containedin=twigVarBlock,twigTagBlock,twigNested contained start=/'/ skip=/\\'/ end=/'/ | |||
syn match twigNumber containedin=twigVarBlock,twigTagBlock,twigNested contained /[0-9]\+\(\.[0-9]\+\)\?/ | |||
" Operators | |||
syn match twigOperator containedin=twigVarBlock,twigTagBlock,twigNested contained /[+\-*\/<>=!,:]/ | |||
syn match twigPunctuation containedin=twigVarBlock,twigTagBlock,twigNested contained /[()\[\]]/ | |||
syn match twigOperator containedin=twigVarBlock,twigTagBlock,twigNested contained /\./ nextgroup=twigAttribute | |||
syn match twigAttribute contained /[a-zA-Z_][a-zA-Z0-9_]*/ | |||
" Jinja template tag and variable blocks | |||
syn region twigNested matchgroup=twigOperator start="(" end=")" transparent display containedin=twigVarBlock,twigTagBlock,twigNested contained | |||
syn region twigNested matchgroup=twigOperator start="\[" end="\]" transparent display containedin=twigVarBlock,twigTagBlock,twigNested contained | |||
syn region twigNested matchgroup=twigOperator start="{" end="}" transparent display containedin=twigVarBlock,twigTagBlock,twigNested contained | |||
syn region twigTagBlock matchgroup=twigTagDelim start=/{%-\?/ end=/-\?%}/ skipwhite containedin=ALLBUT,twigTagBlock,twigVarBlock,twigRaw,twigString,twigNested,twigComment | |||
syn region twigVarBlock matchgroup=twigVarDelim start=/{{-\?/ end=/-\?}}/ containedin=ALLBUT,twigTagBlock,twigVarBlock,twigRaw,twigString,twigNested,twigComment | |||
" Jinja template 'raw' tag | |||
syn region twigRaw matchgroup=twigRawDelim start="{%\s*raw\s*%}" end="{%\s*endraw\s*%}" containedin=ALLBUT,twigTagBlock,twigVarBlock,twigString,twigComment | |||
" Jinja comments | |||
syn region twigComment matchgroup=twigCommentDelim start="{#" end="#}" containedin=ALLBUT,twigTagBlock,twigVarBlock,twigString | |||
" Block start keywords. A bit tricker. We only highlight at the start of a | |||
" tag block and only if the name is not followed by a comma or equals sign | |||
" which usually means that we have to deal with an assignment. | |||
syn match twigStatement containedin=twigTagBlock contained skipwhite /\({%-\?\s*\)\@<=\<[a-zA-Z_][a-zA-Z0-9_]*\>\(\s*[,=]\)\@!/ | |||
" and context modifiers | |||
syn match twigStatement containedin=twigTagBlock contained /\<with\(out\)\?\s\+context\>/ skipwhite | |||
" Define the default highlighting. | |||
" For version 5.7 and earlier: only when not done already | |||
" For version 5.8 and later: only when an item doesn't have highlighting yet | |||
if version >= 508 || !exists("did_twig_syn_inits") | |||
if version < 508 | |||
let did_twig_syn_inits = 1 | |||
command -nargs=+ HiLink hi link <args> | |||
else | |||
command -nargs=+ HiLink hi def link <args> | |||
endif | |||
HiLink twigPunctuation twigOperator | |||
HiLink twigAttribute twigVariable | |||
HiLink twigFunction twigFilter | |||
HiLink twigTagDelim twigTagBlock | |||
HiLink twigVarDelim twigVarBlock | |||
HiLink twigCommentDelim twigComment | |||
HiLink twigRawDelim twig | |||
HiLink twigSpecial Special | |||
HiLink twigOperator Normal | |||
HiLink twigRaw Normal | |||
HiLink twigTagBlock PreProc | |||
HiLink twigVarBlock PreProc | |||
HiLink twigStatement Statement | |||
HiLink twigFilter Function | |||
HiLink twigBlockName Function | |||
HiLink twigVariable Identifier | |||
HiLink twigString Constant | |||
HiLink twigNumber Constant | |||
HiLink twigComment Comment | |||
delcommand HiLink | |||
endif | |||
let b:current_syntax = "twig" | |||
@ -1,9 +0,0 @@ | |||
{ | |||
"name" : "vim-twig", | |||
"version" : "0.1", | |||
"author" : "F. Gabriel Gosselin <gabriel@evidens.ca>", | |||
"maintainer" : "F. Gabriel Gosselin <gabriel@evidens.ca>", | |||
"repository": { "type" : "git", "url" : "git://github.com/beyondwords/vim-twig.git"}, | |||
"dependencies" : {}, | |||
"description" : "Support Twig template language" | |||
} |
@ -1,377 +0,0 @@ | |||
" colorizer.vim Colorize all text in the form #rrggbb or #rgb; autoload functions | |||
" Maintainer: lilydjwg <lilydjwg@gmail.com> | |||
" Version: 1.4.1 | |||
" License: Vim License (see vim's :help license) | |||
" | |||
" See plugin/colorizer.vim for more info. | |||
let s:keepcpo = &cpo | |||
set cpo&vim | |||
function! s:FGforBG(bg) "{{{1 | |||
" takes a 6hex color code and returns a matching color that is visible | |||
let pure = substitute(a:bg,'^#','','') | |||
let r = eval('0x'.pure[0].pure[1]) | |||
let g = eval('0x'.pure[2].pure[3]) | |||
let b = eval('0x'.pure[4].pure[5]) | |||
let fgc = g:colorizer_fgcontrast | |||
if r*30 + g*59 + b*11 > 12000 | |||
return s:predefined_fgcolors['dark'][fgc] | |||
else | |||
return s:predefined_fgcolors['light'][fgc] | |||
end | |||
endfunction | |||
function! s:Rgb2xterm(color) "{{{1 | |||
" selects the nearest xterm color for a rgb value like #FF0000 | |||
let best_match=0 | |||
let smallest_distance = 10000000000 | |||
let r = eval('0x'.a:color[1].a:color[2]) | |||
let g = eval('0x'.a:color[3].a:color[4]) | |||
let b = eval('0x'.a:color[5].a:color[6]) | |||
let colortable = s:GetXterm2rgbTable() | |||
for c in range(0,254) | |||
let d = pow(colortable[c][0]-r,2) + pow(colortable[c][1]-g,2) + pow(colortable[c][2]-b,2) | |||
if d<smallest_distance | |||
let smallest_distance = d | |||
let best_match = c | |||
endif | |||
endfor | |||
return best_match | |||
endfunction | |||
"" the 6 value iterations in the xterm color cube {{{1 | |||
let s:valuerange = [0x00, 0x5F, 0x87, 0xAF, 0xD7, 0xFF] | |||
"" 16 basic colors {{{1 | |||
let s:basic16 = [ | |||
\ [0x00, 0x00, 0x00], [0xCD, 0x00, 0x00], | |||
\ [0x00, 0xCD, 0x00], [0xCD, 0xCD, 0x00], | |||
\ [0x00, 0x00, 0xEE], [0xCD, 0x00, 0xCD], | |||
\ [0x00, 0xCD, 0xCD], [0xE5, 0xE5, 0xE5], | |||
\ [0x7F, 0x7F, 0x7F], [0xFF, 0x00, 0x00], | |||
\ [0x00, 0xFF, 0x00], [0xFF, 0xFF, 0x00], | |||
\ [0x5C, 0x5C, 0xFF], [0xFF, 0x00, 0xFF], | |||
\ [0x00, 0xFF, 0xFF], [0xFF, 0xFF, 0xFF]] | |||
function! s:Xterm2rgb(color) "{{{1 | |||
" 16 basic colors | |||
let r = 0 | |||
let g = 0 | |||
let b = 0 | |||
if a:color<16 | |||
let r = s:basic16[a:color][0] | |||
let g = s:basic16[a:color][1] | |||
let b = s:basic16[a:color][2] | |||
endif | |||
" color cube color | |||
if a:color>=16 && a:color<=232 | |||
let l:color=a:color-16 | |||
let r = s:valuerange[(l:color/36)%6] | |||
let g = s:valuerange[(l:color/6)%6] | |||
let b = s:valuerange[l:color%6] | |||
endif | |||
" gray tone | |||
if a:color>=233 && a:color<=253 | |||
let r=8+(a:color-232)*0x0a | |||
let g=r | |||
let b=r | |||
endif | |||
let rgb=[r,g,b] | |||
return rgb | |||
endfunction | |||
function! s:SetMatcher(color, pat) "{{{1 | |||
" "color" is the converted color and "pat" is what to highlight | |||
let group = 'Color' . strpart(a:color, 1) | |||
if !hlexists(group) || s:force_group_update | |||
let fg = g:colorizer_fgcontrast < 0 ? a:color : s:FGforBG(a:color) | |||
if &t_Co == 256 | |||
exe 'hi '.group.' ctermfg='.s:Rgb2xterm(fg).' ctermbg='.s:Rgb2xterm(a:color) | |||
endif | |||
" Always set gui* as user may switch to GUI version and it's cheap | |||
exe 'hi '.group.' guifg='.fg.' guibg='.a:color | |||
endif | |||
if !exists("w:colormatches[a:pat]") | |||
let w:colormatches[a:pat] = matchadd(group, a:pat) | |||
endif | |||
endfunction | |||
"ColorFinders {{{1 | |||
function! s:HexCode(str, lineno) "{{{2 | |||
let ret = [] | |||
let place = 0 | |||
let colorpat = '#[0-9A-Fa-f]\{3\}\>\|#[0-9A-Fa-f]\{6\}\>' | |||
while 1 | |||
let foundcolor = matchstr(a:str, colorpat, place) | |||
if foundcolor == '' | |||
break | |||
endif | |||
let place = matchend(a:str, colorpat, place) | |||
let pat = foundcolor . '\>' | |||
if len(foundcolor) == 4 | |||
let foundcolor = substitute(foundcolor, '[[:xdigit:]]', '&&', 'g') | |||
endif | |||
call add(ret, [foundcolor, pat]) | |||
endwhile | |||
return ret | |||
endfunction | |||
function! s:RgbColor(str, lineno) "{{{2 | |||
let ret = [] | |||
let place = 0 | |||
let colorpat = '\<rgb(\v\s*(\d+(\%)?)\s*,\s*(\d+%(\2))\s*,\s*(\d+%(\2))\s*\)' | |||
while 1 | |||
let foundcolor = matchlist(a:str, colorpat, place) | |||
if empty(foundcolor) | |||
break | |||
endif | |||
let place = matchend(a:str, colorpat, place) | |||
if foundcolor[2] == '%' | |||
let r = foundcolor[1] * 255 / 100 | |||
let g = foundcolor[3] * 255 / 100 | |||
let b = foundcolor[4] * 255 / 100 | |||
else | |||
let r = foundcolor[1] | |||
let g = foundcolor[3] | |||
let b = foundcolor[4] | |||
endif | |||
if r > 255 || g > 255 || b > 255 | |||
break | |||
endif | |||
let pat = printf('\<rgb(\v\s*%s\s*,\s*%s\s*,\s*%s\s*\)', foundcolor[1], foundcolor[3], foundcolor[4]) | |||
if foundcolor[2] == '%' | |||
let pat = substitute(pat, '%', '\\%', 'g') | |||
endif | |||
let l:color = printf('#%02x%02x%02x', r, g, b) | |||
call add(ret, [l:color, pat]) | |||
endwhile | |||
return ret | |||
endfunction | |||
function! s:RgbaColor(str, lineno) "{{{2 | |||
if has("gui_running") | |||
let bg = synIDattr(synIDtrans(hlID("Normal")), "bg") | |||
let bg_r = str2nr(bg[1].bg[2], 16) | |||
let bg_g = str2nr(bg[3].bg[4], 16) | |||
let bg_b = str2nr(bg[5].bg[6], 16) | |||
else | |||
" translucent colors would display incorrectly, so ignore the alpha value | |||
return s:RgbaColorForTerm(a:str, a:lineno) | |||
endif | |||
let ret = [] | |||
let place = 0 | |||
let colorpat = '\<rgba(\v\s*(\d+(\%)?)\s*,\s*(\d+%(\2))\s*,\s*(\d+%(\2))\s*,\s*(-?[.[:digit:]]+)\s*\)' | |||
while 1 | |||
let foundcolor = matchlist(a:str, colorpat, place) | |||
if empty(foundcolor) | |||
break | |||
endif | |||
let place = matchend(a:str, colorpat, place) | |||
if foundcolor[2] == '%' | |||
let ar = foundcolor[1] * 255 / 100 | |||
let ag = foundcolor[3] * 255 / 100 | |||
let ab = foundcolor[4] * 255 / 100 | |||
else | |||
let ar = foundcolor[1] | |||
let ag = foundcolor[3] | |||
let ab = foundcolor[4] | |||
endif | |||
if ar > 255 || ag > 255 || ab > 255 | |||
break | |||
endif | |||
let alpha = str2float(foundcolor[5]) | |||
if alpha < 0 | |||
let alpha = 0.0 | |||
elseif alpha > 1 | |||
let alpha = 1.0 | |||
endif | |||
let pat = printf('\<rgba(\v\s*%s\s*,\s*%s\s*,\s*%s\s*,\s*%s0*\s*\)', foundcolor[1], foundcolor[3], foundcolor[4], foundcolor[5]) | |||
if foundcolor[2] == '%' | |||
let pat = substitute(pat, '%', '\\%', 'g') | |||
endif | |||
let r = float2nr(ceil(ar * alpha) + ceil(bg_r * (1 - alpha))) | |||
let g = float2nr(ceil(ag * alpha) + ceil(bg_g * (1 - alpha))) | |||
let b = float2nr(ceil(ab * alpha) + ceil(bg_b * (1 - alpha))) | |||
if r > 255 | |||
let r = 255 | |||
endif | |||
if g > 255 | |||
let g = 255 | |||
endif | |||
if b > 255 | |||
let b = 255 | |||
endif | |||
let l:color = printf('#%02x%02x%02x', r, g, b) | |||
call add(ret, [l:color, pat]) | |||
endwhile | |||
return ret | |||
endfunction | |||
function! s:RgbaColorForTerm(str, lineno) "{{{2 | |||
let ret = [] | |||
let place = 0 | |||
let colorpat = '\<rgba(\v\s*(\d+(\%)?)\s*,\s*(\d+%(\2))\s*,\s*(\d+%(\2))\s*,\s*(-?[.[:digit:]]+)\s*\)' | |||
while 1 | |||
let foundcolor = matchlist(a:str, colorpat, place) | |||
if empty(foundcolor) | |||
break | |||
endif | |||
let place = matchend(a:str, colorpat, place) | |||
if foundcolor[2] == '%' | |||
let ar = foundcolor[1] * 255 / 100 | |||
let ag = foundcolor[3] * 255 / 100 | |||
let ab = foundcolor[4] * 255 / 100 | |||
else | |||
let ar = foundcolor[1] | |||
let ag = foundcolor[3] | |||
let ab = foundcolor[4] | |||
endif | |||
if ar > 255 || ag > 255 || ab > 255 | |||
break | |||
endif | |||
let pat = printf('\<rgba(\v\s*%s\s*,\s*%s\s*,\s*%s\s*,\ze\s*(-?[.[:digit:]]+)\s*\)', foundcolor[1], foundcolor[3], foundcolor[4]) | |||
if foundcolor[2] == '%' | |||
let pat = substitute(pat, '%', '\\%', 'g') | |||
endif | |||
let l:color = printf('#%02x%02x%02x', ar, ag, ab) | |||
call add(ret, [l:color, pat]) | |||
endwhile | |||
return ret | |||
endfunction | |||
function! s:PreviewColorInLine(where) "{{{1 | |||
let line = getline(a:where) | |||
for Func in s:ColorFinder | |||
let ret = Func(line, a:where) | |||
" returned a list of a list: color as #rrggbb, text pattern to highlight | |||
for r in ret | |||
call s:SetMatcher(r[0], r[1]) | |||
endfor | |||
endfor | |||
endfunction | |||
function! s:CursorMoved() "{{{1 | |||
if !exists('w:colormatches') | |||
return | |||
endif | |||
if exists('b:colorizer_last_update') | |||
if b:colorizer_last_update == b:changedtick | |||
" Nothing changed | |||
return | |||
endif | |||
endif | |||
call s:PreviewColorInLine('.') | |||
let b:colorizer_last_update = b:changedtick | |||
endfunction | |||
function! s:TextChanged() "{{{1 | |||
if !exists('w:colormatches') | |||
return | |||
endif | |||
echomsg "TextChanged" | |||
call s:PreviewColorInLine('.') | |||
endfunction | |||
function! colorizer#ColorHighlight(update, ...) "{{{1 | |||
if exists('w:colormatches') | |||
if !a:update | |||
return | |||
endif | |||
call s:ClearMatches() | |||
endif | |||
let w:colormatches = {} | |||
if g:colorizer_fgcontrast != s:saved_fgcontrast || (exists("a:1") && a:1 == '!') | |||
let s:force_group_update = 1 | |||
endif | |||
for i in range(1, line("$")) | |||
call s:PreviewColorInLine(i) | |||
endfor | |||
let s:force_group_update = 0 | |||
let s:saved_fgcontrast = g:colorizer_fgcontrast | |||
augroup Colorizer | |||
au! | |||
if exists('##TextChanged') | |||
autocmd TextChanged * silent call s:TextChanged() | |||
if v:version > 704 || v:version == 704 && has('patch143') | |||
autocmd TextChangedI * silent call s:TextChanged() | |||
else | |||
" TextChangedI does not work as expected | |||
autocmd CursorMovedI * silent call s:CursorMoved() | |||
endif | |||
else | |||
autocmd CursorMoved,CursorMovedI * silent call s:CursorMoved() | |||
endif | |||
" rgba handles differently, so need updating | |||
autocmd GUIEnter * silent call colorizer#ColorHighlight(1) | |||
autocmd BufRead * silent call colorizer#ColorHighlight(1) | |||
autocmd WinEnter * silent call colorizer#ColorHighlight(1) | |||
autocmd ColorScheme * let s:force_group_update=1 | silent call colorizer#ColorHighlight(1) | |||
augroup END | |||
endfunction | |||
function! colorizer#ColorClear() "{{{1 | |||
augroup Colorizer | |||
au! | |||
augroup END | |||
let save_tab = tabpagenr() | |||
let save_win = winnr() | |||
tabdo windo call s:ClearMatches() | |||
exe 'tabn '.save_tab | |||
exe save_win . 'wincmd w' | |||
endfunction | |||
function! s:ClearMatches() "{{{1 | |||
if !exists('w:colormatches') | |||
return | |||
endif | |||
for i in values(w:colormatches) | |||
call matchdelete(i) | |||
endfor | |||
unlet w:colormatches | |||
endfunction | |||
function! colorizer#ColorToggle() "{{{1 | |||
if exists('#Colorizer#BufRead') | |||
call colorizer#ColorClear() | |||
echomsg 'Disabled color code highlighting.' | |||
else | |||
call colorizer#ColorHighlight(0) | |||
echomsg 'Enabled color code highlighting.' | |||
endif | |||
endfunction | |||
function! s:GetXterm2rgbTable() | |||
if !exists('s:table_xterm2rgb') | |||
let s:table_xterm2rgb = [] | |||
for c in range(0, 254) | |||
let s:color = s:Xterm2rgb(c) | |||
call add(s:table_xterm2rgb, s:color) | |||
endfor | |||
endif | |||
return s:table_xterm2rgb | |||
endfun | |||
" Setups {{{1 | |||
let s:ColorFinder = [function('s:HexCode'), function('s:RgbColor'), function('s:RgbaColor')] | |||
let s:force_group_update = 0 | |||
let s:predefined_fgcolors = {} | |||
let s:predefined_fgcolors['dark'] = ['#444444', '#222222', '#000000'] | |||
let s:predefined_fgcolors['light'] = ['#bbbbbb', '#dddddd', '#ffffff'] | |||
if !exists("g:colorizer_fgcontrast") | |||
" Default to black / white | |||
let g:colorizer_fgcontrast = len(s:predefined_fgcolors['dark']) - 1 | |||
elseif g:colorizer_fgcontrast >= len(s:predefined_fgcolors['dark']) | |||
echohl WarningMsg | |||
echo "g:colorizer_fgcontrast value invalid, using default" | |||
echohl None | |||
let g:colorizer_fgcontrast = len(s:predefined_fgcolors['dark']) - 1 | |||
endif | |||
let s:saved_fgcontrast = g:colorizer_fgcontrast | |||
" Restoration and modelines {{{1 | |||
let &cpo = s:keepcpo | |||
unlet s:keepcpo | |||
" vim:ft=vim:fdm=marker:fmr={{{,}}}: |
@ -1,319 +0,0 @@ | |||
# FILE: autoload/conque_term/conque_globals.py | |||
# AUTHOR: Nico Raffo <nicoraffo@gmail.com> | |||
# WEBSITE: http://conque.googlecode.com | |||
# MODIFIED: 2011-04-04 | |||
# VERSION: 2.1, for Vim 7.0 | |||
# LICENSE: | |||
# Conque - Vim terminal/console emulator | |||
# Copyright (C) 2009-2011 Nico Raffo | |||
# | |||
# MIT License | |||
# | |||
# Permission is hereby granted, free of charge, to any person obtaining a copy | |||
# of this software and associated documentation files (the "Software"), to deal | |||
# in the Software without restriction, including without limitation the rights | |||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
# copies of the Software, and to permit persons to whom the Software is | |||
# furnished to do so, subject to the following conditions: | |||
# | |||
# The above copyright notice and this permission notice shall be included in | |||
# all copies or substantial portions of the Software. | |||
# | |||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||
# THE SOFTWARE. | |||
"""Common global constants and functions for Conque.""" | |||
import sys | |||
import re | |||
# PYTHON VERSION | |||
CONQUE_PYTHON_VERSION = sys.version_info[0] | |||
# Encoding | |||
try: | |||
# Vim's character encoding | |||
import vim | |||
CONQUE_VIM_ENCODING = vim.eval('&encoding') | |||
except: | |||
CONQUE_VIM_ENCODING = 'utf-8' | |||
def u(str_val, str_encoding='utf-8', errors='strict'): | |||
""" Foolhardy attempt to make unicode string syntax compatible with both python 2 and 3. """ | |||
if not str_val: | |||
str_val = '' | |||
if CONQUE_PYTHON_VERSION == 3: | |||
return str_val | |||
else: | |||
return unicode(str_val, str_encoding, errors) | |||
def uchr(str): | |||
""" Foolhardy attempt to make unicode string syntax compatible with both python 2 and 3. """ | |||
if CONQUE_PYTHON_VERSION == 3: | |||
return chr(str) | |||
else: | |||
return unichr(str) | |||
# Logging | |||
# Unix escape sequence settings | |||
CONQUE_CTL = { | |||
1: 'soh', # start of heading | |||
2: 'stx', # start of text | |||
7: 'bel', # bell | |||
8: 'bs', # backspace | |||
9: 'tab', # tab | |||
10: 'nl', # new line | |||
13: 'cr', # carriage return | |||
14: 'so', # shift out | |||
15: 'si' # shift in | |||
} | |||
# 11 : 'vt', # vertical tab | |||
# 12 : 'ff', # form feed | |||
# Escape sequences | |||
CONQUE_ESCAPE = { | |||
'm': 'font', | |||
'J': 'clear_screen', | |||
'K': 'clear_line', | |||
'@': 'add_spaces', | |||
'A': 'cursor_up', | |||
'B': 'cursor_down', | |||
'C': 'cursor_right', | |||
'D': 'cursor_left', | |||
'G': 'cursor_to_column', | |||
'H': 'cursor', | |||
'P': 'delete_chars', | |||
'f': 'cursor', | |||
'g': 'tab_clear', | |||
'r': 'set_coords', | |||
'h': 'set', | |||
'l': 'reset' | |||
} | |||
# 'L': 'insert_lines', | |||
# 'M': 'delete_lines', | |||
# 'd': 'cusor_vpos', | |||
# Alternate escape sequences, no [ | |||
CONQUE_ESCAPE_PLAIN = { | |||
'D': 'scroll_up', | |||
'E': 'next_line', | |||
'H': 'set_tab', | |||
'M': 'scroll_down' | |||
} | |||
# 'N': 'single_shift_2', | |||
# 'O': 'single_shift_3', | |||
# '=': 'alternate_keypad', | |||
# '>': 'numeric_keypad', | |||
# '7': 'save_cursor', | |||
# '8': 'restore_cursor', | |||
# Character set escape sequences, with "(" | |||
CONQUE_ESCAPE_CHARSET = { | |||
'A': 'uk', | |||
'B': 'us', | |||
'0': 'graphics' | |||
} | |||
# Uber alternate escape sequences, with # or ? | |||
CONQUE_ESCAPE_QUESTION = { | |||
'1h': 'new_line_mode', | |||
'3h': '132_cols', | |||
'4h': 'smooth_scrolling', | |||
'5h': 'reverse_video', | |||
'6h': 'relative_origin', | |||
'7h': 'set_auto_wrap', | |||
'8h': 'set_auto_repeat', | |||
'9h': 'set_interlacing_mode', | |||
'1l': 'set_cursor_key', | |||
'2l': 'set_vt52', | |||
'3l': '80_cols', | |||
'4l': 'set_jump_scrolling', | |||
'5l': 'normal_video', | |||
'6l': 'absolute_origin', | |||
'7l': 'reset_auto_wrap', | |||
'8l': 'reset_auto_repeat', | |||
'9l': 'reset_interlacing_mode' | |||
} | |||
CONQUE_ESCAPE_HASH = { | |||
'8': 'screen_alignment_test' | |||
} | |||
# '3': 'double_height_top', | |||
# '4': 'double_height_bottom', | |||
# '5': 'single_height_single_width', | |||
# '6': 'single_height_double_width', | |||
CONQUE_GRAPHICS_SET = [ | |||
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, | |||
0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F, | |||
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, | |||
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F, | |||
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, | |||
0x0028, 0x0029, 0x002A, 0x2192, 0x2190, 0x2191, 0x2193, 0x002F, | |||
0x2588, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, | |||
0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F, | |||
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, | |||
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, | |||
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, | |||
0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x00A0, | |||
0x25C6, 0x2592, 0x2409, 0x240C, 0x240D, 0x240A, 0x00B0, 0x00B1, | |||
0x2591, 0x240B, 0x2518, 0x2510, 0x250C, 0x2514, 0x253C, 0xF800, | |||
0xF801, 0x2500, 0xF803, 0xF804, 0x251C, 0x2524, 0x2534, 0x252C, | |||
0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00B7, 0x007F, | |||
0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, | |||
0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F, | |||
0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, | |||
0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E, 0x009F, | |||
0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7, | |||
0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, | |||
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7, | |||
0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF, | |||
0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7, | |||
0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF, | |||
0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7, | |||
0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF, | |||
0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7, | |||
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF, | |||
0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, | |||
0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF | |||
] | |||
# Font codes | |||
CONQUE_FONT = { | |||
0: {'description': 'Normal (default)', 'attributes': {'cterm': 'NONE', 'ctermfg': 'NONE', 'ctermbg': 'NONE', 'gui': 'NONE', 'guifg': 'NONE', 'guibg': 'NONE'}, 'normal': True}, | |||
1: {'description': 'Bold', 'attributes': {'cterm': 'BOLD', 'gui': 'BOLD'}, 'normal': False}, | |||
4: {'description': 'Underlined', 'attributes': {'cterm': 'UNDERLINE', 'gui': 'UNDERLINE'}, 'normal': False}, | |||
5: {'description': 'Blink (appears as Bold)', 'attributes': {'cterm': 'BOLD', 'gui': 'BOLD'}, 'normal': False}, | |||
7: {'description': 'Inverse', 'attributes': {'cterm': 'REVERSE', 'gui': 'REVERSE'}, 'normal': False}, | |||
8: {'description': 'Invisible (hidden)', 'attributes': {'ctermfg': '0', 'ctermbg': '0', 'guifg': '#000000', 'guibg': '#000000'}, 'normal': False}, | |||
22: {'description': 'Normal (neither bold nor faint)', 'attributes': {'cterm': 'NONE', 'gui': 'NONE'}, 'normal': True}, | |||
24: {'description': 'Not underlined', 'attributes': {'cterm': 'NONE', 'gui': 'NONE'}, 'normal': True}, | |||
25: {'description': 'Steady (not blinking)', 'attributes': {'cterm': 'NONE', 'gui': 'NONE'}, 'normal': True}, | |||
27: {'description': 'Positive (not inverse)', 'attributes': {'cterm': 'NONE', 'gui': 'NONE'}, 'normal': True}, | |||
28: {'description': 'Visible (not hidden)', 'attributes': {'ctermfg': 'NONE', 'ctermbg': 'NONE', 'guifg': 'NONE', 'guibg': 'NONE'}, 'normal': True}, | |||
30: {'description': 'Set foreground color to Black', 'attributes': {'ctermfg': '16', 'guifg': '#000000'}, 'normal': False}, | |||
31: {'description': 'Set foreground color to Red', 'attributes': {'ctermfg': '1', 'guifg': '#ff0000'}, 'normal': False}, | |||
32: {'description': 'Set foreground color to Green', 'attributes': {'ctermfg': '2', 'guifg': '#00ff00'}, 'normal': False}, | |||
33: {'description': 'Set foreground color to Yellow', 'attributes': {'ctermfg': '3', 'guifg': '#ffff00'}, 'normal': False}, | |||
34: {'description': 'Set foreground color to Blue', 'attributes': {'ctermfg': '4', 'guifg': '#0000ff'}, 'normal': False}, | |||
35: {'description': 'Set foreground color to Magenta', 'attributes': {'ctermfg': '5', 'guifg': '#990099'}, 'normal': False}, | |||
36: {'description': 'Set foreground color to Cyan', 'attributes': {'ctermfg': '6', 'guifg': '#009999'}, 'normal': False}, | |||
37: {'description': 'Set foreground color to White', 'attributes': {'ctermfg': '7', 'guifg': '#ffffff'}, 'normal': False}, | |||
39: {'description': 'Set foreground color to default (original)', 'attributes': {'ctermfg': 'NONE', 'guifg': 'NONE'}, 'normal': True}, | |||
40: {'description': 'Set background color to Black', 'attributes': {'ctermbg': '16', 'guibg': '#000000'}, 'normal': False}, | |||
41: {'description': 'Set background color to Red', 'attributes': {'ctermbg': '1', 'guibg': '#ff0000'}, 'normal': False}, | |||
42: {'description': 'Set background color to Green', 'attributes': {'ctermbg': '2', 'guibg': '#00ff00'}, 'normal': False}, | |||
43: {'description': 'Set background color to Yellow', 'attributes': {'ctermbg': '3', 'guibg': '#ffff00'}, 'normal': False}, | |||
44: {'description': 'Set background color to Blue', 'attributes': {'ctermbg': '4', 'guibg': '#0000ff'}, 'normal': False}, | |||
45: {'description': 'Set background color to Magenta', 'attributes': {'ctermbg': '5', 'guibg': '#990099'}, 'normal': False}, | |||
46: {'description': 'Set background color to Cyan', 'attributes': {'ctermbg': '6', 'guibg': '#009999'}, 'normal': False}, | |||
47: {'description': 'Set background color to White', 'attributes': {'ctermbg': '7', 'guibg': '#ffffff'}, 'normal': False}, | |||
49: {'description': 'Set background color to default (original).', 'attributes': {'ctermbg': 'NONE', 'guibg': 'NONE'}, 'normal': True}, | |||
90: {'description': 'Set foreground color to Black', 'attributes': {'ctermfg': '8', 'guifg': '#000000'}, 'normal': False}, | |||
91: {'description': 'Set foreground color to Red', 'attributes': {'ctermfg': '9', 'guifg': '#ff0000'}, 'normal': False}, | |||
92: {'description': 'Set foreground color to Green', 'attributes': {'ctermfg': '10', 'guifg': '#00ff00'}, 'normal': False}, | |||
93: {'description': 'Set foreground color to Yellow', 'attributes': {'ctermfg': '11', 'guifg': '#ffff00'}, 'normal': False}, | |||
94: {'description': 'Set foreground color to Blue', 'attributes': {'ctermfg': '12', 'guifg': '#0000ff'}, 'normal': False}, | |||
95: {'description': 'Set foreground color to Magenta', 'attributes': {'ctermfg': '13', 'guifg': '#990099'}, 'normal': False}, | |||
96: {'description': 'Set foreground color to Cyan', 'attributes': {'ctermfg': '14', 'guifg': '#009999'}, 'normal': False}, | |||
97: {'description': 'Set foreground color to White', 'attributes': {'ctermfg': '15', 'guifg': '#ffffff'}, 'normal': False}, | |||
100: {'description': 'Set background color to Black', 'attributes': {'ctermbg': '8', 'guibg': '#000000'}, 'normal': False}, | |||
101: {'description': 'Set background color to Red', 'attributes': {'ctermbg': '9', 'guibg': '#ff0000'}, 'normal': False}, | |||
102: {'description': 'Set background color to Green', 'attributes': {'ctermbg': '10', 'guibg': '#00ff00'}, 'normal': False}, | |||
103: {'description': 'Set background color to Yellow', 'attributes': {'ctermbg': '11', 'guibg': '#ffff00'}, 'normal': False}, | |||
104: {'description': 'Set background color to Blue', 'attributes': {'ctermbg': '12', 'guibg': '#0000ff'}, 'normal': False}, | |||
105: {'description': 'Set background color to Magenta', 'attributes': {'ctermbg': '13', 'guibg': '#990099'}, 'normal': False}, | |||
106: {'description': 'Set background color to Cyan', 'attributes': {'ctermbg': '14', 'guibg': '#009999'}, 'normal': False}, | |||
107: {'description': 'Set background color to White', 'attributes': {'ctermbg': '15', 'guibg': '#ffffff'}, 'normal': False} | |||
} | |||
# regular expression matching (almost) all control sequences | |||
CONQUE_SEQ_REGEX = re.compile("(\x1b\[?\??#?[0-9;]*[a-zA-Z0-9@=>]|\x1b\][0-9];.*?\x07|[\x01-\x0f]|\x1b\([AB0])") | |||
CONQUE_SEQ_REGEX_CTL = re.compile("^[\x01-\x0f]$") | |||
CONQUE_SEQ_REGEX_CSI = re.compile("^\x1b\[") | |||
CONQUE_SEQ_REGEX_TITLE = re.compile("^\x1b\]") | |||
CONQUE_SEQ_REGEX_HASH = re.compile("^\x1b#") | |||
CONQUE_SEQ_REGEX_ESC = re.compile("^\x1b.$") | |||
CONQUE_SEQ_REGEX_CHAR = re.compile("^\x1b[()]") | |||
# match table output | |||
CONQUE_TABLE_OUTPUT = re.compile("^\s*\|\s.*\s\|\s*$|^\s*\+[=+-]+\+\s*$") | |||
# basic terminal colors | |||
CONQUE_COLOR_SEQUENCE = ( | |||
'000', '009', '090', '099', '900', '909', '990', '999', | |||
'000', '00f', '0f0', '0ff', 'f00', 'f0f', 'ff0', 'fff' | |||
) | |||
# Windows subprocess constants | |||
# shared memory size | |||
CONQUE_SOLE_BUFFER_LENGTH = 1000 | |||
CONQUE_SOLE_INPUT_SIZE = 1000 | |||
CONQUE_SOLE_STATS_SIZE = 1000 | |||
CONQUE_SOLE_COMMANDS_SIZE = 255 | |||
CONQUE_SOLE_RESCROLL_SIZE = 255 | |||
CONQUE_SOLE_RESIZE_SIZE = 255 | |||
# interval of screen redraw | |||
# larger number means less frequent | |||
CONQUE_SOLE_SCREEN_REDRAW = 50 | |||
# interval of full buffer redraw | |||
# larger number means less frequent | |||
CONQUE_SOLE_BUFFER_REDRAW = 500 | |||
# interval of full output bucket replacement | |||
# larger number means less frequent, 1 = every time | |||
CONQUE_SOLE_MEM_REDRAW = 1000 | |||
# maximum number of lines with terminal colors | |||
# ignored if g:ConqueTerm_Color = 2 | |||
CONQUE_MAX_SYNTAX_LINES = 200 | |||
# windows input splitting on special keys | |||
CONQUE_WIN32_REGEX_VK = re.compile("(\x1b\[[0-9;]+VK)") | |||
# windows attribute string splitting | |||
CONQUE_WIN32_REGEX_ATTR = re.compile("((.)\\2*)", re.DOTALL) | |||
# special key attributes | |||
CONQUE_VK_ATTR_CTRL_PRESSED = u('1024') | |||
@ -1,230 +0,0 @@ | |||
# FILE: autoload/conque_term/conque_screen.py | |||
# AUTHOR: Nico Raffo <nicoraffo@gmail.com> | |||
# WEBSITE: http://conque.googlecode.com | |||
# MODIFIED: 2011-04-04 | |||
# VERSION: 2.1, for Vim 7.0 | |||
# LICENSE: | |||
# Conque - Vim terminal/console emulator | |||
# Copyright (C) 2009-2011 Nico Raffo | |||
# | |||
# MIT License | |||
# | |||
# Permission is hereby granted, free of charge, to any person obtaining a copy | |||
# of this software and associated documentation files (the "Software"), to deal | |||
# in the Software without restriction, including without limitation the rights | |||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
# copies of the Software, and to permit persons to whom the Software is | |||
# furnished to do so, subject to the following conditions: | |||
# | |||
# The above copyright notice and this permission notice shall be included in | |||
# all copies or substantial portions of the Software. | |||
# | |||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||
# THE SOFTWARE. | |||
""" | |||
ConqueScreen is an extention of the vim.current.buffer object | |||
Unix terminal escape sequences usually reference line numbers relative to the | |||
top of the visible screen. However the visible portion of the Vim buffer | |||
representing the terminal probably doesn't start at the first line of the | |||
buffer. | |||
The ConqueScreen class allows access to the Vim buffer with screen-relative | |||
line numbering. And handles a few other related tasks, such as setting the | |||
correct cursor position. | |||
E.g.: | |||
s = ConqueScreen() | |||
... | |||
s[5] = 'Set 5th line in terminal to this line' | |||
s.append('Add new line to terminal') | |||
s[5] = 'Since previous append() command scrolled the terminal down, this is a different line than first cb[5] call' | |||
""" | |||
import vim | |||
class ConqueScreen(object): | |||
# the buffer | |||
buffer = None | |||
# screen and scrolling regions | |||
screen_top = 1 | |||
# screen width | |||
screen_width = 80 | |||
screen_height = 80 | |||
# char encoding for vim buffer | |||
screen_encoding = 'utf-8' | |||
def __init__(self): | |||
""" Initialize screen size and character encoding. """ | |||
self.buffer = vim.current.buffer | |||
# initialize screen size | |||
self.screen_top = 1 | |||
self.screen_width = vim.current.window.width | |||
self.screen_height = vim.current.window.height | |||
# save screen character encoding type | |||
self.screen_encoding = vim.eval('&fileencoding') | |||
def __len__(self): | |||
""" Define the len() function for ConqueScreen objects. """ | |||
return len(self.buffer) | |||
def __getitem__(self, key): | |||
""" Define value access for ConqueScreen objects. """ | |||
buffer_line = self.get_real_idx(key) | |||
# if line is past buffer end, add lines to buffer | |||
if buffer_line >= len(self.buffer): | |||
for i in range(len(self.buffer), buffer_line + 1): | |||
self.append(' ') | |||
return u(self.buffer[buffer_line], 'utf-8') | |||
def __setitem__(self, key, value): | |||
""" Define value assignments for ConqueScreen objects. """ | |||
buffer_line = self.get_real_idx(key) | |||
if CONQUE_PYTHON_VERSION == 2: | |||
val = value.encode(self.screen_encoding) | |||
else: | |||
# XXX / Vim's python3 interface doesn't accept bytes object | |||
val = str(value) | |||
# if line is past end of screen, append | |||
if buffer_line == len(self.buffer): | |||
self.buffer.append(val) | |||
else: | |||
self.buffer[buffer_line] = val | |||
def __delitem__(self, key): | |||
""" Define value deletion for ConqueScreen objects. """ | |||
del self.buffer[self.screen_top + key - 2] | |||
def append(self, value): | |||
""" Define value appending for ConqueScreen objects. """ | |||
if len(self.buffer) > self.screen_top + self.screen_height - 1: | |||
self.buffer[len(self.buffer) - 1] = value | |||
else: | |||
self.buffer.append(value) | |||
if len(self.buffer) > self.screen_top + self.screen_height - 1: | |||
self.screen_top += 1 | |||
if vim.current.buffer.number == self.buffer.number: | |||
vim.command('normal! G') | |||
def insert(self, line, value): | |||
""" Define value insertion for ConqueScreen objects. """ | |||
l = self.screen_top + line - 2 | |||
self.buffer.append(value, l) | |||
def get_top(self): | |||
""" Get the Vim line number representing the top of the visible terminal. """ | |||
return self.screen_top | |||
def get_real_idx(self, line): | |||
""" Get the zero index Vim line number corresponding to the provided screen line. """ | |||
return (self.screen_top + line - 2) | |||
def get_buffer_line(self, line): | |||
""" Get the Vim line number corresponding to the provided screen line. """ | |||
return (self.screen_top + line - 1) | |||
def set_screen_width(self, width): | |||
""" Set the screen width. """ | |||
self.screen_width = width | |||
def clear(self): | |||
""" Clear the screen. Does not clear the buffer, just scrolls down past all text. """ | |||
self.screen_width = width | |||
self.buffer.append(' ') | |||
vim.command('normal! Gzt') | |||
self.screen_top = len(self.buffer) | |||
def set_cursor(self, line, column): | |||
""" Set cursor position. """ | |||
# figure out line | |||
buffer_line = self.screen_top + line - 1 | |||
if buffer_line > len(self.buffer): | |||
for l in range(len(self.buffer) - 1, buffer_line): | |||
self.buffer.append('') | |||
# figure out column | |||
real_column = column | |||
if len(self.buffer[buffer_line - 1]) < real_column: | |||
self.buffer[buffer_line - 1] = self.buffer[buffer_line - 1] + ' ' * (real_column - len(self.buffer[buffer_line - 1])) | |||
if not CONQUE_FAST_MODE: | |||
# set cursor at byte index of real_column'th character | |||
vim.command('call cursor(' + str(buffer_line) + ', byteidx(getline(' + str(buffer_line) + '), ' + str(real_column) + '))') | |||
else: | |||
# old version | |||
# python version is occasionally grumpy | |||
try: | |||
vim.current.window.cursor = (buffer_line, real_column - 1) | |||
except: | |||
vim.command('call cursor(' + str(buffer_line) + ', ' + str(real_column) + ')') | |||
def reset_size(self, line): | |||
""" Change screen size """ | |||
# save cursor line number | |||
buffer_line = self.screen_top + line | |||
# reset screen size | |||
self.screen_width = vim.current.window.width | |||
self.screen_height = vim.current.window.height | |||
self.screen_top = len(self.buffer) - vim.current.window.height + 1 | |||
if self.screen_top < 1: | |||
self.screen_top = 1 | |||
# align bottom of buffer to bottom of screen | |||
vim.command('normal! ' + str(self.screen_height) + 'kG') | |||
# return new relative line number | |||
return (buffer_line - self.screen_top) | |||
def align(self): | |||
""" align bottom of buffer to bottom of screen """ | |||
vim.command('normal! ' + str(self.screen_height) + 'kG') | |||
@ -1,458 +0,0 @@ | |||
# FILE: autoload/conque_term/conque_sole.py | |||
# AUTHOR: Nico Raffo <nicoraffo@gmail.com> | |||
# WEBSITE: http://conque.googlecode.com | |||
# MODIFIED: 2011-04-04 | |||
# VERSION: 2.1, for Vim 7.0 | |||
# LICENSE: | |||
# Conque - Vim terminal/console emulator | |||
# Copyright (C) 2009-2011 Nico Raffo | |||
# | |||
# MIT License | |||
# | |||
# Permission is hereby granted, free of charge, to any person obtaining a copy | |||
# of this software and associated documentation files (the "Software"), to deal | |||
# in the Software without restriction, including without limitation the rights | |||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
# copies of the Software, and to permit persons to whom the Software is | |||
# furnished to do so, subject to the following conditions: | |||
# | |||
# The above copyright notice and this permission notice shall be included in | |||
# all copies or substantial portions of the Software. | |||
# | |||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||
# THE SOFTWARE. | |||
""" | |||
Windows Console Emulator | |||
This is the main interface to the Windows emulator. It reads new output from the background console | |||
and updates the Vim buffer. | |||
""" | |||
import vim | |||
class ConqueSole(Conque): | |||
window_top = None | |||
window_bottom = None | |||
color_cache = {} | |||
attribute_cache = {} | |||
color_mode = None | |||
color_conceals = {} | |||
buffer = None | |||
encoding = None | |||
# counters for periodic rendering | |||
buffer_redraw_ct = 1 | |||
screen_redraw_ct = 1 | |||
# line offset, shifts output down | |||
offset = 0 | |||
def open(self): | |||
""" Start command and initialize this instance | |||
Arguments: | |||
command - Command string, e.g. "Powershell.exe" | |||
options - Dictionary of config options | |||
python_exe - Path to the python.exe executable. Usually C:\PythonXX\python.exe | |||
communicator_py - Path to subprocess controller script in user's vimfiles directory | |||
""" | |||
# get arguments | |||
command = vim.eval('command') | |||
options = vim.eval('options') | |||
python_exe = vim.eval('py_exe') | |||
communicator_py = vim.eval('py_vim') | |||
# init size | |||
self.columns = vim.current.window.width | |||
self.lines = vim.current.window.height | |||
self.window_top = 0 | |||
self.window_bottom = vim.current.window.height - 1 | |||
# color mode | |||
self.color_mode = vim.eval('g:ConqueTerm_ColorMode') | |||
# line offset | |||
self.offset = int(options['offset']) | |||
# init color | |||
self.enable_colors = options['color'] and not CONQUE_FAST_MODE | |||
# open command | |||
self.proc = ConqueSoleWrapper() | |||
self.proc.open(command, self.lines, self.columns, python_exe, communicator_py, options) | |||
self.buffer = vim.current.buffer | |||
self.screen_encoding = vim.eval('&fileencoding') | |||
def read(self, timeout=1, set_cursor=True, return_output=False, update_buffer=True): | |||
""" Read from console and update Vim buffer. """ | |||
try: | |||
stats = self.proc.get_stats() | |||
if not stats: | |||
return | |||
# disable screen and buffer redraws in fast mode | |||
if not CONQUE_FAST_MODE: | |||
self.buffer_redraw_ct += 1 | |||
self.screen_redraw_ct += 1 | |||
update_top = 0 | |||
update_bottom = 0 | |||
lines = [] | |||
# full buffer redraw, our favorite! | |||
#if self.buffer_redraw_ct == CONQUE_SOLE_BUFFER_REDRAW: | |||
# self.buffer_redraw_ct = 0 | |||
# update_top = 0 | |||
# update_bottom = stats['top_offset'] + self.lines | |||
# (lines, attributes) = self.proc.read(update_top, update_bottom) | |||
# if return_output: | |||
# output = self.get_new_output(lines, update_top, stats) | |||
# if update_buffer: | |||
# for i in range(update_top, update_bottom + 1): | |||
# if CONQUE_FAST_MODE: | |||
# self.plain_text(i, lines[i], None, stats) | |||
# else: | |||
# self.plain_text(i, lines[i], attributes[i], stats) | |||
# full screen redraw | |||
if stats['cursor_y'] + 1 != self.l or stats['top_offset'] != self.window_top or self.screen_redraw_ct >= CONQUE_SOLE_SCREEN_REDRAW: | |||
self.screen_redraw_ct = 0 | |||
update_top = self.window_top | |||
update_bottom = max([stats['top_offset'] + self.lines + 1, stats['cursor_y']]) | |||
(lines, attributes) = self.proc.read(update_top, update_bottom - update_top + 1) | |||
if return_output: | |||
output = self.get_new_output(lines, update_top, stats) | |||
if update_buffer: | |||
for i in range(update_top, update_bottom + 1): | |||
if CONQUE_FAST_MODE: | |||
self.plain_text(i, lines[i - update_top], None, stats) | |||
else: | |||
self.plain_text(i, lines[i - update_top], attributes[i - update_top], stats) | |||
# single line redraw | |||
else: | |||
update_top = stats['cursor_y'] | |||
(lines, attributes) = self.proc.read(update_top, 1) | |||
if return_output: | |||
output = self.get_new_output(lines, update_top, stats) | |||
if update_buffer: | |||
if lines[0].rstrip() != u(self.buffer[update_top].rstrip()): | |||
if CONQUE_FAST_MODE: | |||
self.plain_text(update_top, lines[0], None, stats) | |||
else: | |||
self.plain_text(update_top, lines[0], attributes[0], stats) | |||
# reset current position | |||
self.window_top = stats['top_offset'] | |||
self.l = stats['cursor_y'] + 1 | |||
self.c = stats['cursor_x'] + 1 | |||
# reposition cursor if this seems plausible | |||
if set_cursor: | |||
self.set_cursor(self.l, self.c) | |||
if return_output: | |||
return output | |||
except: | |||
pass | |||
def get_new_output(self, lines, update_top, stats): | |||
""" Calculate the "new" output from this read. Fake but useful """ | |||
if not (stats['cursor_y'] + 1 > self.l or (stats['cursor_y'] + 1 == self.l and stats['cursor_x'] + 1 |