mirror of
				https://github.com/nsnail/spectre.console.git
				synced 2025-11-04 02:25:28 +08:00 
			
		
		
		
	Allow mutation of segments
This commit is contained in:
		@@ -13,25 +13,10 @@ namespace Spectre.Console.Rendering
 | 
				
			|||||||
    [DebuggerDisplay("{Text,nq}")]
 | 
					    [DebuggerDisplay("{Text,nq}")]
 | 
				
			||||||
    public class Segment
 | 
					    public class Segment
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        private readonly bool _mutable;
 | 
					 | 
				
			||||||
        private string _text;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Gets the segment text.
 | 
					        /// Gets the segment text.
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        public string Text
 | 
					        public string Text { get; private set; }
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            get => _text;
 | 
					 | 
				
			||||||
            private set
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                if (!_mutable)
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    throw new NotSupportedException();
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                _text = value;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Gets a value indicating whether or not this is an expicit line break
 | 
					        /// Gets a value indicating whether or not this is an expicit line break
 | 
				
			||||||
@@ -54,12 +39,12 @@ namespace Spectre.Console.Rendering
 | 
				
			|||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Gets a segment representing a line break.
 | 
					        /// Gets a segment representing a line break.
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        public static Segment LineBreak { get; } = new Segment(Environment.NewLine, Style.Plain, true, false);
 | 
					        public static Segment LineBreak => new Segment(Environment.NewLine, Style.Plain, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Gets an empty segment.
 | 
					        /// Gets an empty segment.
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        public static Segment Empty { get; } = new Segment(string.Empty, Style.Plain, false, false);
 | 
					        public static Segment Empty => new Segment(string.Empty, Style.Plain, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Initializes a new instance of the <see cref="Segment"/> class.
 | 
					        /// Initializes a new instance of the <see cref="Segment"/> 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)
 | 
					            if (text is null)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                throw new ArgumentNullException(nameof(text));
 | 
					                throw new ArgumentNullException(nameof(text));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            _mutable = mutable;
 | 
					            Text = text.NormalizeLineEndings();
 | 
				
			||||||
            _text = text.NormalizeLineEndings();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            Style = style;
 | 
					            Style = style;
 | 
				
			||||||
            IsLineBreak = lineBreak;
 | 
					            IsLineBreak = lineBreak;
 | 
				
			||||||
            IsWhiteSpace = string.IsNullOrWhiteSpace(text);
 | 
					            IsWhiteSpace = string.IsNullOrWhiteSpace(text);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user