Permalink
Browse files

Updated table output to prevent encoding/font issues

  • Loading branch information...
1 parent b68904a commit 86a45d6caec7b1086421e4c170afd9fd9a38ff51 @actionshrimp committed Apr 4, 2011
Showing with 71 additions and 44 deletions.
  1. +1 −1 plugin/xpath.vim
  2. +2 −2 syntax/xpathresults.vim
  3. +41 −26 xpath.vba
  4. +27 −15 xpath/xpath.py
View
@@ -29,7 +29,7 @@ endif
"Used to track the results buffer
let s:results_buffer_name = 'xpath_search_results'
-let s:result_pattern = '^\(\d\+\).*$'
+let s:result_pattern = '^|\(\d\+\).*$'
autocmd FileType * :call XPathFileType(expand("<amatch>"))
View
@@ -1,4 +1,4 @@
-syntax match XPathResult /^\d\+.*$/
-syntax match CurrentXPathResult /\(\(^\d\+.*\%#.*$\)\|\(^\%#\d\+.*$\)\|\(^\%#\d\+.*$\)\)/
+syntax match XPathResult /^|\d\+.*$/
+syntax match CurrentXPathResult /\(\(^|\d\+.*\%#.*$\)\|\(^|\%#\d\+.*$\)\|\(^\%#|\d\+.*$\)\)/
hi link CurrentXPathResult Error
View
@@ -101,14 +101,14 @@ endif
"Used to track the results buffer
let s:results_buffer_name = 'xpath_search_results'
-let s:result_pattern = '^\(\d\+\).*$'
+let s:result_pattern = '^|\(\d\+\).*$'
autocmd FileType * :call XPathFileType(expand("<amatch>"))
function! XPathFileType(bufft)
for ft in g:xpath_search_filetypes
if (a:bufft == ft)
- nnoremap <buffer> <unique> X :call XPathSearchPrompt()<cr>
+ nnoremap <buffer> X :call XPathSearchPrompt()<cr>
end
endfor
endfunction
@@ -261,12 +261,12 @@ function! XPathResultsCursorlineCheck()
endfunction
syntax/xpathresults.vim [[[1
4
-syntax match XPathResult /^\d\+.*$/
-syntax match CurrentXPathResult /\(\(^\d\+.*\%#.*$\)\|\(^\%#\d\+.*$\)\|\(^\%#\d\+.*$\)\)/
+syntax match XPathResult /^|\d\+.*$/
+syntax match CurrentXPathResult /\(\(^|\d\+.*\%#.*$\)\|\(^|\%#\d\+.*$\)\|\(^\%#|\d\+.*$\)\)/
hi link CurrentXPathResult Error
xpath/xpath.py [[[1
-491
+506
#-*- encoding:utf-8 -*-
import re
@@ -319,10 +319,11 @@ class VimXPathInterface(object):
return results
def prep_searcher(self, search_buffer_name):
- search_buffer = self.buffer_manager.get_buffer(search_buffer_name)
+ if search_buffer_name != self.buffer_manager.get_defined_buffer('results'):
+ search_buffer = self.buffer_manager.get_buffer(search_buffer_name)
- search_text = self.buffer_manager.get_buffer_content(search_buffer)
- self.searcher.build_tree(search_text)
+ search_text = self.buffer_manager.get_buffer_content(search_buffer)
+ self.searcher.build_tree(search_text)
def output_results(self, xpath, results):
results_buffer = self.buffer_manager.get_defined_buffer('results')
@@ -394,7 +395,7 @@ class XPathSearcher(object):
self.cache['eval'] = etree.XPathEvaluator(self.cache['tree'])
self.cache['error'] = None
- except etree.XMLSyntaxError as xmlerr:
+ except Exception as xmlerr:
err_text = str(xmlerr)
self.cache['error'] = XPathParseErrorResult(err_text)
@@ -404,7 +405,7 @@ class XPathSearcher(object):
raw_results = self.cache['eval'](xpath)
results = self.parse_results(raw_results)
- except etree.XPathError as xpatherr:
+ except Exception as xpatherr:
err_text = str(xpatherr)
results = [XPathSearchErrorResult(err_text, xpath)]
else:
@@ -462,6 +463,18 @@ class XPathSearcher(object):
return result
+class TBL(object):
+# TL = '┏'; TC = '┳'; TR = '┓'; T = '━'
+# HL = '┣'; HC = '╋'; HR = '┫'; H = '━'
+# ML = '┃'; MC = '┃'; MR = '┃'; M = '━'
+# BL = '┗'; BC = '┻'; BR = '┛'; B = '━'
+
+ TL = '+'; TC = '+'; TR = '+'; T = '-'
+ HL = '+'; HC = '+'; HR = '+'; H = '-'
+ ML = '|'; MC = '|'; MR = '|'; M = '-'
+ BL = '+'; BC = '+'; BR = '+'; B = '-'
+
+
class ResultsFormatter(object):
def __init__(self, window_width, xpath, results):
@@ -507,54 +520,56 @@ class ResultsFormatter(object):
lines += self.build_body()
lines += self.build_footer()
+ lines = [x.replace("\n", " ") for x in lines]
+
return lines
def build_header(self):
header_lines = []
- header_lines.append('┏' + '━'* (self.width-2) + '┓')
+ header_lines.append(TBL.TL + TBL.T* (self.width-2) + TBL.TR)
header_text = 'Results: ' + self.xpath_string
- header_lines.append('┃' + header_text + ' ' * (self.width - len(header_text) - 2) + '┃')
+ header_lines.append(TBL.ML + header_text + ' ' * (self.width - len(header_text) - 2) + TBL.MR)
- lines = ['┣', '┃', '┣']
+ lines = [TBL.HL, TBL.ML, TBL.HL]
for c in self.table.columns:
- lines[0] += '━' * c.width + '┳'
- lines[1] += c.title + ' '*(c.width - len(c.title)) + '┃'
- lines[2] += '━' * c.width + '╋'
+ lines[0] += TBL.T * c.width + TBL.TC
+ lines[1] += c.title + ' '*(c.width - len(c.title)) + TBL.MC
+ lines[2] += TBL.H * c.width + TBL.HC
- lines[0] = lines[0][:-len('┳')] + '┫'
- lines[2] = lines[2][:-len('┃')] + '┫'
+ lines[0] = lines[0][:-len(TBL.TC)] + TBL.HR
+ lines[2] = lines[2][:-len(TBL.HC)] + TBL.HR
- header_lines.append(lines)
+ header_lines += lines
return header_lines
def build_body(self):
body_lines = []
for r in self.table.rows:
- line = '┃'
+ line = TBL.ML
for c in self.table.columns:
contents = r.cells.get(c, '')
if len(contents) > c.width:
contents = contents[:c.width-3] + '...'
else:
contents += ' '*(c.width - len(contents))
- line += contents + '┃'
+ line += contents + TBL.MC
body_lines.append(line)
return body_lines
def build_footer(self):
footer_lines = []
- line = '┗'
+ line = TBL.BL
for c in self.table.columns:
- line += '━' * c.width + '┻'
+ line += TBL.B * c.width + TBL.BC
- line = line[:-len('┻')] + '┛'
+ line = line[:-len(TBL.BC)] + TBL.BR
footer_lines.append(line)
return footer_lines
@@ -689,8 +704,8 @@ class XPathParseErrorResult(XPathErrorResult):
class XPathSearchErrorResult(XPathErrorResult):
def __init__(self, error, xpath):
self.error = 'Error with XPath (' + xpath + '): ' + error
- self.line = '-'
- self.column = '-'
+ self.line = '*'
+ self.column = '*'
class XPathNoResultsResult(XPathResult):
def __init__(self):
View
@@ -194,6 +194,18 @@ def get_parse_class(self, raw_result):
return result
+class TBL(object):
+# TL = '┏'; TC = '┳'; TR = '┓'; T = '━'
+# HL = '┣'; HC = '╋'; HR = '┫'; H = '━'
+# ML = '┃'; MC = '┃'; MR = '┃'; M = '━'
+# BL = '┗'; BC = '┻'; BR = '┛'; B = '━'
+
+ TL = '+'; TC = '+'; TR = '+'; T = '-'
+ HL = '+'; HC = '+'; HR = '+'; H = '-'
+ ML = '|'; MC = '|'; MR = '|'; M = '-'
+ BL = '+'; BC = '+'; BR = '+'; B = '-'
+
+
class ResultsFormatter(object):
def __init__(self, window_width, xpath, results):
@@ -246,19 +258,19 @@ def get_formatted_lines(self):
def build_header(self):
header_lines = []
- header_lines.append('' + ''* (self.width-2) + '')
+ header_lines.append(TBL.TL + TBL.T* (self.width-2) + TBL.TR)
header_text = 'Results: ' + self.xpath_string
- header_lines.append('' + header_text + ' ' * (self.width - len(header_text) - 2) + '')
+ header_lines.append(TBL.ML + header_text + ' ' * (self.width - len(header_text) - 2) + TBL.MR)
- lines = ['', '', '']
+ lines = [TBL.HL, TBL.ML, TBL.HL]
for c in self.table.columns:
- lines[0] += '' * c.width + ''
- lines[1] += c.title + ' '*(c.width - len(c.title)) + ''
- lines[2] += '' * c.width + ''
+ lines[0] += TBL.T * c.width + TBL.TC
+ lines[1] += c.title + ' '*(c.width - len(c.title)) + TBL.MC
+ lines[2] += TBL.H * c.width + TBL.HC
- lines[0] = lines[0][:-len('')] + ''
- lines[2] = lines[2][:-len('')] + ''
+ lines[0] = lines[0][:-len(TBL.TC)] + TBL.HR
+ lines[2] = lines[2][:-len(TBL.HC)] + TBL.HR
header_lines += lines
@@ -268,27 +280,27 @@ def build_body(self):
body_lines = []
for r in self.table.rows:
- line = ''
+ line = TBL.ML
for c in self.table.columns:
contents = r.cells.get(c, '')
if len(contents) > c.width:
contents = contents[:c.width-3] + '...'
else:
contents += ' '*(c.width - len(contents))
- line += contents + ''
+ line += contents + TBL.MC
body_lines.append(line)
return body_lines
def build_footer(self):
footer_lines = []
- line = ''
+ line = TBL.BL
for c in self.table.columns:
- line += '' * c.width + ''
+ line += TBL.B * c.width + TBL.BC
- line = line[:-len('')] + ''
+ line = line[:-len(TBL.BC)] + TBL.BR
footer_lines.append(line)
return footer_lines
@@ -423,8 +435,8 @@ def first_group_match(self, pattern, text):
class XPathSearchErrorResult(XPathErrorResult):
def __init__(self, error, xpath):
self.error = 'Error with XPath (' + xpath + '): ' + error
- self.line = '-'
- self.column = '-'
+ self.line = '*'
+ self.column = '*'
class XPathNoResultsResult(XPathResult):
def __init__(self):

0 comments on commit 86a45d6

Please sign in to comment.