Skip to content

Instantly share code, notes, and snippets.

@gmanny
Created October 31, 2020 17:37
Show Gist options
  • Save gmanny/d40f71f0e38a6a9da673a2e05117b847 to your computer and use it in GitHub Desktop.
Save gmanny/d40f71f0e38a6a9da673a2e05117b847 to your computer and use it in GitHub Desktop.
Dark Mode for RoslynPad
using System;
using System.IO;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using Microsoft.CodeAnalysis;
using RoslynPad.Editor;
using WpfAppCommon;
namespace Namespace
{
public partial class RoslynWindow
{
public RoslynWindow()
{
InitializeComponent();
editor.TextArea.SelectionCornerRadius = 0;
editor.TextArea.SelectionBorder = new Pen(new SolidColorBrush(Colors.Black), 0);
editor.TextArea.SelectionBrush = new SolidColorBrush(Color.FromArgb(100, 51,153,255));
editor.TextArea.SelectionForeground = new SolidColorBrush(Color.FromRgb(220, 220, 220));
editor.SearchReplacePanel.MarkerBrush = new SolidColorBrush(Color.FromRgb(119,56,0));
}
private void OnEditorLoaded(object sender, RoutedEventArgs e)
{
RoslynCodeEditor editor = (RoslynCodeEditor) sender;
editor.Loaded -= OnEditorLoaded;
// just an example of editor.Initialize with dark theme colors
editor.Initialize(____host, new DarkModeHighlightColors(), Directory.GetCurrentDirectory(), "/*code*/");
}
}
}
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Windows;
using System.Windows.Media;
using ICSharpCode.AvalonEdit.Highlighting;
using Microsoft.CodeAnalysis.Classification;
using RoslynPad.Editor;
namespace Namespace
{
public class DarkModeHighlightColors : IClassificationHighlightColors
{
public HighlightingColor DefaultBrush { get; protected set; } = new HighlightingColor { Foreground = new SimpleHighlightingBrush(Color.FromRgb(220,220,220)) };
public HighlightingColor TypeBrush { get; protected set; } = new HighlightingColor { Foreground = new SimpleHighlightingBrush(Color.FromRgb(78, 201, 176)) };
public HighlightingColor InterfaceBrush { get; protected set; } = new HighlightingColor { Foreground = new SimpleHighlightingBrush(Color.FromRgb(184,215,163)) };
public HighlightingColor MethodBrush { get; protected set; } = new HighlightingColor { Foreground = new SimpleHighlightingBrush(Color.FromRgb(216,216,163)) };
public HighlightingColor CommentBrush { get; protected set; } = new HighlightingColor { Foreground = new SimpleHighlightingBrush(Color.FromRgb(87, 166, 74)) };
public HighlightingColor XmlCommentBrush { get; protected set; } = new HighlightingColor { Foreground = new SimpleHighlightingBrush(Color.FromRgb(200,200,200)) };
public HighlightingColor XmlCdataBrush { get; protected set; } = new HighlightingColor { Foreground = new SimpleHighlightingBrush(Color.FromRgb(233,213,133)) };
public HighlightingColor XmlCommentCommentBrush { get; protected set; } = new HighlightingColor { Foreground = new SimpleHighlightingBrush(Color.FromRgb(96,139,78)) };
public HighlightingColor KeywordBrush { get; protected set; } = new HighlightingColor { Foreground = new SimpleHighlightingBrush(Color.FromRgb(86,156,214)) };
public HighlightingColor ControlKeywordBrush { get; protected set; } = new HighlightingColor { Foreground = new SimpleHighlightingBrush(Color.FromRgb(220,220,220)) };
public HighlightingColor PreprocessorKeywordBrush { get; protected set; } = new HighlightingColor { Foreground = new SimpleHighlightingBrush(Color.FromRgb(155,155,155)) };
public HighlightingColor StringBrush { get; protected set; } = new HighlightingColor { Foreground = new SimpleHighlightingBrush(Color.FromRgb(214,157,133)) };
public HighlightingColor StringEscapeBrush { get; protected set; } = new HighlightingColor { Foreground = new SimpleHighlightingBrush(Color.FromRgb(255,214,143)) };
public HighlightingColor BraceMatchingBrush { get; protected set; } = new HighlightingColor { Foreground = new SimpleHighlightingBrush(Color.FromRgb(220,220,220)), Background = new SimpleHighlightingBrush(Color.FromRgb(14,69,131)) };
public HighlightingColor StaticSymbolBrush { get; protected set; } = new HighlightingColor { FontWeight = FontWeights.Bold };
public const string BraceMatchingClassificationTypeName = "brace matching";
private readonly Lazy<ImmutableDictionary<string, HighlightingColor>> _map;
public DarkModeHighlightColors()
{
_map = new Lazy<ImmutableDictionary<string, HighlightingColor>>(() => new Dictionary<string, HighlightingColor>
{
[ClassificationTypeNames.ClassName] = AsFrozen(TypeBrush),
[ClassificationTypeNames.StructName] = AsFrozen(TypeBrush),
[ClassificationTypeNames.InterfaceName] = AsFrozen(InterfaceBrush),
[ClassificationTypeNames.DelegateName] = AsFrozen(TypeBrush),
[ClassificationTypeNames.EnumName] = AsFrozen(InterfaceBrush),
[ClassificationTypeNames.ModuleName] = AsFrozen(TypeBrush),
[ClassificationTypeNames.TypeParameterName] = AsFrozen(InterfaceBrush),
[ClassificationTypeNames.MethodName] = AsFrozen(MethodBrush),
[ClassificationTypeNames.Comment] = AsFrozen(CommentBrush),
[ClassificationTypeNames.StaticSymbol] = AsFrozen(StaticSymbolBrush),
[ClassificationTypeNames.XmlDocCommentAttributeName] = AsFrozen(XmlCommentBrush),
[ClassificationTypeNames.XmlDocCommentAttributeQuotes] = AsFrozen(XmlCommentBrush),
[ClassificationTypeNames.XmlDocCommentAttributeValue] = AsFrozen(XmlCommentBrush),
[ClassificationTypeNames.XmlDocCommentCDataSection] = AsFrozen(XmlCdataBrush),
[ClassificationTypeNames.XmlDocCommentComment] = AsFrozen(XmlCommentCommentBrush),
[ClassificationTypeNames.XmlDocCommentDelimiter] = AsFrozen(XmlCommentCommentBrush),
[ClassificationTypeNames.XmlDocCommentEntityReference] = AsFrozen(XmlCommentCommentBrush),
[ClassificationTypeNames.XmlDocCommentName] = AsFrozen(XmlCommentCommentBrush),
[ClassificationTypeNames.XmlDocCommentProcessingInstruction] = AsFrozen(XmlCommentCommentBrush),
[ClassificationTypeNames.XmlDocCommentText] = AsFrozen(XmlCommentCommentBrush),
[ClassificationTypeNames.Keyword] = AsFrozen(KeywordBrush),
[ClassificationTypeNames.ControlKeyword] = AsFrozen(ControlKeywordBrush),
[ClassificationTypeNames.PreprocessorKeyword] = AsFrozen(PreprocessorKeywordBrush),
[ClassificationTypeNames.StringLiteral] = AsFrozen(StringBrush),
[ClassificationTypeNames.VerbatimStringLiteral] = AsFrozen(StringBrush),
[ClassificationTypeNames.StringEscapeCharacter] = AsFrozen(StringEscapeBrush),
[ClassificationTypeNames.StringEscapeCharacter] = AsFrozen(StringEscapeBrush),
[BraceMatchingClassificationTypeName] = AsFrozen(BraceMatchingBrush)
}.ToImmutableDictionary());
}
protected virtual ImmutableDictionary<string, HighlightingColor> GetOrCreateMap()
{
return _map.Value;
}
public HighlightingColor GetBrush(string classificationTypeName)
{
GetOrCreateMap().TryGetValue(classificationTypeName, out var brush);
return brush ?? AsFrozen(DefaultBrush);
}
private static HighlightingColor AsFrozen(HighlightingColor color)
{
if (!color.IsFrozen)
{
color.Freeze();
}
return color;
}
}
}
@surfmuggle
Copy link

surfmuggle commented Sep 9, 2023

I assume the gist above requires to make the changes to the source code files above and compile roslynpad.
But searching for AdditionalSetup.cs or DarkModeHighlightColors.cs returned no result

Zero search hits

Is there an easier option for Release 18 to enable dark-mode?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment