예제 #1
0
        public CachedLine(UserLine realLine)
        {
            #region param checks
            if (realLine == null)
            {
                throw new ArgumentNullException("realLine");
            }
            #endregion

            RealLine = realLine;
        }
예제 #2
0
        public UserLine( UserLine copy )
        {
            #region param checks
            if( copy == null )
            {
                throw new ArgumentNullException( "copy" );
            }
            #endregion

            CachedWrapAt = -1;
            IsOutput = copy.IsOutput;

            foreach( var span in copy.Spans )
            {
                Spans.Add( new Span( span ) );
            }
        }
예제 #3
0
        public UserLine(UserLine copy)
        {
            #region param checks
            if (copy == null)
            {
                throw new ArgumentNullException("copy");
            }
            #endregion

            CachedWrapAt = -1;
            IsOutput     = copy.IsOutput;

            foreach (var span in copy.Spans)
            {
                Spans.Add(new Span(span));
            }
        }
		private void UpdateLineCache( UserLine line )
		{
			line.CachedLines = new List<CachedLine>();
			line.CachedWrapAt = CharsPerLine;

			int len = 0;

			CachedLine cachedLine = null;

			foreach( var origSpan in line.Spans )
			{
				if( cachedLine == null )
				{
					cachedLine = new CachedLine( line );
					line.CachedLines.Add( cachedLine );
				}

				if( (origSpan.Text.Length + len) < CharsPerLine )
				{
					cachedLine.Spans.Add( origSpan );
					len += origSpan.Text.Length;
				}
				else
				{
					string spanText = origSpan.Text;

					while( spanText.Length > 0 )
					{
						string substring = spanText.Substring( 0, Math.Min( CharsPerLine - len, spanText.Length ) );
						spanText = spanText.Substring( Math.Min( CharsPerLine - len, spanText.Length ) );
						len = 0;

						var cachedSpan = new Span( substring, origSpan.ForegroundColour, origSpan.BackgroundColour );
						cachedLine.Spans.Add( cachedSpan );

						if( spanText.Length > 0 )
						{
							cachedLine = new CachedLine( line );
							line.CachedLines.Add( cachedLine );

							cachedLine.Spans.Add( line.IsOutput ? PromptOutputWrap : PromptWrap );
							len += line.IsOutput ? PromptOutputWrap.Text.Length : PromptWrap.Text.Length;
						}
					}
				}
			}
		}
		private void ClearCurrentLine()
		{
			m_currentLine = new UserLine();
			m_currentLine.Spans.Add( Prompt );
		}
		public void WriteOutput( string text, Colour foregroundColour, Colour backgroundColour )
		{
			ResetHistoryNavigation();
			var outputLines = Regex.Split( text, @"\r\n|\r|\n" );

			foreach( string outputLine in outputLines )
			{
				var line = new UserLine();
				line.IsOutput = true;

				line.Spans.Add( PromptOutput );

				var span = new Span( outputLine, foregroundColour, backgroundColour );
				line.Spans.Add( span );

				UpdateMaxHistoryItems();

				m_lines.AddFirst( line );
			}

			m_currentLine = new UserLine();
         m_currentLine.Spans.Add( Prompt );
		}
		private void ShowHistoryItem()
		{
			m_currentLine = new UserLine( m_historyItem.Value );
		}