Basic Syntax highlighting, added CodeTextBox to MainWindow to test it.
This commit is contained in:
38
Befunge/Editor/CharStyles/BefungeStyler.cs
Normal file
38
Befunge/Editor/CharStyles/BefungeStyler.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Befunge.Editor.CharStyles
|
||||
{
|
||||
public class BefungeStyler : ITextStyler
|
||||
{
|
||||
private string _directionals = "<>^v?r";
|
||||
|
||||
public IEnumerable<Run> StyledString(string input)
|
||||
{
|
||||
var runs = new List<Run>();
|
||||
|
||||
foreach (var c in input)
|
||||
{
|
||||
if (_directionals.Contains(c))
|
||||
runs.Add(new Run(c.ToString())
|
||||
{
|
||||
Foreground = new SolidColorBrush(Colors.CornflowerBlue),
|
||||
FontWeight = FontWeights.Bold
|
||||
});
|
||||
else
|
||||
{
|
||||
runs.Add(new Run(c.ToString())
|
||||
{
|
||||
Foreground = new SolidColorBrush(Colors.Black),
|
||||
FontWeight = FontWeights.Normal
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return runs;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Documents;
|
||||
|
||||
namespace Befunge.Editor.CharStyles
|
||||
{
|
||||
public interface ICharStyler
|
||||
public interface ITextStyler
|
||||
{
|
||||
Run StyledString(string input);
|
||||
IEnumerable<Run> StyledString(string input);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user