|
|
|
|
|
|
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Linq; |
|
|
using System.Text; |
|
|
using System.Diagnostics; |
|
|
using System.Windows; |
|
|
using System.Windows.Media; |
|
|
using System.Windows.Threading; |
|
|
|
|
|
using ICSharpCode.AvalonEdit; |
|
|
using ICSharpCode.AvalonEdit.Document; |
|
|
using ICSharpCode.AvalonEdit.Rendering; |
|
|
using ICSharpCode.AvalonEdit.Highlighting; |
|
|
|
|
|
namespace PythonConsoleControl |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
public class PythonConsoleHighlightingColorizer : HighlightingColorizer |
|
|
{ |
|
|
TextDocument document; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public PythonConsoleHighlightingColorizer(IHighlightingDefinition highlightingDefinition, TextDocument document) |
|
|
: base(new DocumentHighlighter(document, highlightingDefinition )) |
|
|
{ |
|
|
if (document == null) |
|
|
throw new ArgumentNullException("document"); |
|
|
this.document = document; |
|
|
} |
|
|
|
|
|
|
|
|
protected override void ColorizeLine(DocumentLine line) |
|
|
{ |
|
|
IHighlighter highlighter = CurrentContext.TextView.Services.GetService(typeof(IHighlighter)) as IHighlighter; |
|
|
string lineString = document.GetText(line); |
|
|
if (highlighter != null) |
|
|
{ |
|
|
if (lineString.Length < 3 || lineString.Substring(0, 3) == ">>>" || lineString.Substring(0, 3) == "...") { |
|
|
HighlightedLine hl = highlighter.HighlightLine(line.LineNumber); |
|
|
foreach (HighlightedSection section in hl.Sections) |
|
|
{ |
|
|
ChangeLinePart(section.Offset, section.Offset + section.Length, |
|
|
visualLineElement => ApplyColorToElement(visualLineElement, section.Color)); |
|
|
} |
|
|
} |
|
|
else { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|