From 13c56eca017f7390938c4101d58b0d8cde33399c Mon Sep 17 00:00:00 2001 From: Patrik Svensson Date: Sat, 5 Sep 2020 08:39:48 +0200 Subject: [PATCH] Allow mutation of segments --- src/Spectre.Console/Rendering/Segment.cs | 27 +++++------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/src/Spectre.Console/Rendering/Segment.cs b/src/Spectre.Console/Rendering/Segment.cs index f0a3562..6aacc88 100644 --- a/src/Spectre.Console/Rendering/Segment.cs +++ b/src/Spectre.Console/Rendering/Segment.cs @@ -13,25 +13,10 @@ namespace Spectre.Console.Rendering [DebuggerDisplay("{Text,nq}")] public class Segment { - private readonly bool _mutable; - private string _text; - /// /// Gets the segment text. /// - public string Text - { - get => _text; - private set - { - if (!_mutable) - { - throw new NotSupportedException(); - } - - _text = value; - } - } + public string Text { get; private set; } /// /// Gets a value indicating whether or not this is an expicit line break @@ -54,12 +39,12 @@ namespace Spectre.Console.Rendering /// /// Gets a segment representing a line break. /// - public static Segment LineBreak { get; } = new Segment(Environment.NewLine, Style.Plain, true, false); + public static Segment LineBreak => new Segment(Environment.NewLine, Style.Plain, true); /// /// Gets an empty segment. /// - public static Segment Empty { get; } = new Segment(string.Empty, Style.Plain, false, false); + public static Segment Empty => new Segment(string.Empty, Style.Plain, false); /// /// Initializes a new instance of the class. @@ -80,16 +65,14 @@ namespace Spectre.Console.Rendering { } - private Segment(string text, Style style, bool lineBreak, bool mutable = true) + private Segment(string text, Style style, bool lineBreak) { if (text is null) { throw new ArgumentNullException(nameof(text)); } - _mutable = mutable; - _text = text.NormalizeLineEndings(); - + Text = text.NormalizeLineEndings(); Style = style; IsLineBreak = lineBreak; IsWhiteSpace = string.IsNullOrWhiteSpace(text);