char.IsWhiteSpace(char)

Here are the examples of the csharp api char.IsWhiteSpace(char) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1211 Examples 7

19 Source : Parser.Internal.cs
with MIT License
from AlexGhiondea

private static IEnumerable<string> SplitCommandLineIntoSegments(string line)
        {
            if (string.IsNullOrEmpty(line))
                yield break;

            int currentPosition = 0;
            string segment;

            // skip over leading whitespace
            while (currentPosition < line.Length && char.IsWhiteSpace(line[currentPosition]))
            {
                currentPosition++;
            }

            int segmentStart = currentPosition;

            do
            {
                // if the current character is a quote, continue scanning until you find the next quote
                if (line[currentPosition] == '"')
                {
                    currentPosition++;
                    segmentStart = currentPosition;

                    while (currentPosition < line.Length && line[currentPosition] != '"')
                        currentPosition++;

                    // do we have a matching quote?
                    if (currentPosition == line.Length)
                        break; // if we don't, instead of throw, break from this loop.
                }
                else
                {
                    // find the next whitespace character.
                    while (currentPosition < line.Length && !char.IsWhiteSpace(line[currentPosition]))
                        currentPosition++;
                }

                // generate the current segment
                segment = line.Substring(segmentStart, currentPosition - segmentStart);
                yield return segment;

                // this maps to the trailing quote and needs to be skipped.
                if (currentPosition < line.Length && line[currentPosition] == '"')
                {
                    currentPosition++;
                }

                // skip whitespace characters
                while (currentPosition < line.Length && char.IsWhiteSpace(line[currentPosition]))
                {
                    currentPosition++;
                }
                segmentStart = currentPosition;
            } while (currentPosition < line.Length);
        }

19 Source : StringFormatter.cs
with MIT License
from alexis-

public static string Align(string str, int width, Alignment alignment, Cropping cropping, string ellipsis, char padCharacter)
    {
      if (str == null)
        throw new ArgumentNullException("str");

      if (width <= 0)
        throw new ArgumentOutOfRangeException("width");

      if (ellipsis != null)
      {
        if (cropping != Cropping.Both && width < ellipsis.Length)
          throw new ArgumentException("width must not be less than the length of ellipsis");
        else if (cropping == Cropping.Both && width < ellipsis.Length * 2)
          throw new ArgumentException("width must not be less than twice the length of the ellipsis when cropping is set to Both");
      }

      IList<string> lines = SplitAtLineBreaks(str);
      StringBuilder result = new StringBuilder();

      for (int j = 0; j < lines.Count; j++)
      {
        if (j != 0)
          result.Append(Environment.NewLine);

        string s = lines[j];
        int length = s.Length;
        if (length <= width)
        {
          switch (alignment)
          {
            case Alignment.Left:
              result.Append(s);
              result.Append(padCharacter, width - length);
              continue;
            case Alignment.Right:
              result.Append(padCharacter, width - length);
              result.Append(s);
              continue;
            case Alignment.Center:
              result.Append(padCharacter, (width - length) / 2);
              result.Append(s);
              result.Append(padCharacter, (width - length) - ((width - length) / 2));
              continue;
            case Alignment.Justified:
              string trimmed = s.Trim();
              length = trimmed.Length;

              int spaceCount = GetWordCount(s) - 1;

              Debug.replacedert(spaceCount >= 0);

              if (spaceCount == 0) // string only contain a single word
              {
                result.Append(trimmed);
                result.Append(padCharacter, width - length);
              }

              StringBuilder localResult = new StringBuilder();
              int remainingSpace = width - length;
              bool readingWord = true;

              for (int i = 0; i < length; i++)
              {
                if (!char.IsWhiteSpace(trimmed[i]))
                {
                  readingWord = true;
                  localResult.Append(trimmed[i]);
                }
                else if (readingWord)
                {
                  localResult.Append(trimmed[i]);
                  int spacesToAdd = remainingSpace / spaceCount--;
                  remainingSpace -= spacesToAdd;
                  localResult.Append(padCharacter, spacesToAdd);
                  readingWord = false;

                }
              }
              result.Append(localResult);
              continue;
            default:
              throw new InvalidOperationException("Internal error; Unimplemented Justification specified");
          }
        }

        // The string is too long and need to be cropped
        switch (cropping)
        {
          case Cropping.Right:
            return s.Substring(0, width - ellipsis.Length) + ellipsis;
          case Cropping.Left:
            return ellipsis + s.Substring(length - width + ellipsis.Length);
          case Cropping.Both:
            return ellipsis + s.Substring(length / 2 - width / 2, width - ellipsis.Length * 2) + ellipsis;
          default:
            break;
        }
      }
      return result.ToString();
    }

19 Source : StringFormatter.cs
with MIT License
from alexis-

public static int GetWordCount(string str)
    {
      if (str == null)
        throw new ArgumentNullException("str");

      int count = 0;
      bool readingWord = false;
      for (int i = 0; i < str.Length; i++)
      {
        if (!char.IsWhiteSpace(str[i]))
          readingWord = true;
        else if (readingWord)
        {
          count++;
          readingWord = false;
        }
      }
      if (readingWord)
        count++;

      return count;
    }

19 Source : Lexer.cs
with MIT License
from alirezanet

public SyntaxToken NextToken()
      {
         if (_position >= _text.Length) return new SyntaxToken(SyntaxKind.End, _position, "\0");

         var peek = Peek(1);
         switch (Current)
         {
            case '(':
               return new SyntaxToken(SyntaxKind.OpenParenthesisToken, _position++, "(");
            case ')':
               return new SyntaxToken(SyntaxKind.CloseParenthesis, _position++, ")");
            case ',':
               return new SyntaxToken(SyntaxKind.And, _position++, ",");
            case '|':
               return new SyntaxToken(SyntaxKind.Or, _position++, "|");
            case '^':
            {
               _waitingForValue = true;
               return new SyntaxToken(SyntaxKind.StartsWith, _position++, "^");
            }
            case '$':
            {
               _waitingForValue = true;
               return new SyntaxToken(SyntaxKind.EndsWith, _position++, "$");
            }
            case '!' when peek == '^':
            {
               _waitingForValue = true;
               return new SyntaxToken(SyntaxKind.NotStartsWith, _position += 2, "!^");
            }
            case '!' when peek == '$':
            {
               _waitingForValue = true;
               return new SyntaxToken(SyntaxKind.NotEndsWith, _position += 2, "!$");
            }
            case '=' when peek == '*':
            {
               _waitingForValue = true;
               return new SyntaxToken(SyntaxKind.Like, _position += 2, "=*");
            }
            case '=':
            {
               _waitingForValue = true;
               return new SyntaxToken(SyntaxKind.Equal, _position ++ , "=");
            }
            case '!' when peek == '=':
            {
               _waitingForValue = true;
               return new SyntaxToken(SyntaxKind.NotEqual, _position += 2, "!=");
            }
            case '!' when peek == '*':
            {
               _waitingForValue = true;
               return new SyntaxToken(SyntaxKind.NotLike, _position += 2, "!*");
            }
            case '/' when peek == 'i':
               return new SyntaxToken(SyntaxKind.CaseInsensitive, _position += 2, "/i");
            case '<':
            {
               _waitingForValue = true;
               return peek == '=' ? new SyntaxToken(SyntaxKind.LessOrEqualThan, _position += 2, "<=") :
                  new SyntaxToken(SyntaxKind.LessThan, _position++, "<");
            }
            case '>':
            {
               _waitingForValue = true;
               return peek == '=' ? new SyntaxToken(SyntaxKind.GreaterOrEqualThan, _position += 2, ">=") : 
                  new SyntaxToken(SyntaxKind.GreaterThan, _position++, ">");
            }
         }

         if (Current == '[')
         {
            Next();
            var start = _position; 
            while (char.IsDigit(Current))  
               Next();
      
            var length = _position - start;
            var text = _text.Substring(start, length);

            if (Current == ']')
            {
               _position++;
               return new SyntaxToken(SyntaxKind.FieldIndexToken, start, text);
            }
            
            _diagnostics.Add($"bad character input: '{peek.ToString()}' at {_position++.ToString()}. expected ']' ");
            return new SyntaxToken(SyntaxKind.BadToken, _position, Current.ToString());

         }

         if (char.IsLetter(Current) && !_waitingForValue)
         {
            var start = _position;

            while (char.IsLetterOrDigit(Current) || Current is '_')  
               Next();

            var length = _position - start;
            var text = _text.Substring(start, length);
            
            return new SyntaxToken(SyntaxKind.FieldToken, start, text);
         }
         

         if (char.IsWhiteSpace(Current))
         {
            var start = _position;

            // skipper
            while (char.IsWhiteSpace(Current))
               Next();

            var length = _position - start;
            var text = _text.Substring(start, length);

            return new SyntaxToken(SyntaxKind.WhiteSpace, start, text);
         }

         if (_waitingForValue)
         {
            var start = _position;

            var exitCharacters = new[] {'(', ')', ',', '|'};
            var lastChar = '\0';
            while ((!exitCharacters.Contains(Current) || exitCharacters.Contains(Current) && lastChar == '\\') &&
                   _position < _text.Length &&
                   (!(Current == '/' && Peek(1) == 'i') || (Current == '/' && Peek(1) == 'i') && lastChar == '\\')) // exit on case-insensitive operator
            {
               lastChar = Current;
               Next();
            }

            var text = new StringBuilder();
            for (var i = start; i < _position; i++)
            {
               var current = _text[i];

               if (current != '\\') // ignore escape character
                  text.Append(current);
               else if (current == '\\' && i > 0) // escape escape character
                  if (_text[i - 1] == '\\')
                     text.Append(current);
            }

            _waitingForValue = false;
            return new SyntaxToken(SyntaxKind.ValueToken, start, text.ToString());
         }

         _diagnostics.Add($"bad character input: '{Current.ToString()}' at {_position.ToString()}");
         return new SyntaxToken(SyntaxKind.BadToken, _position++, string.Empty);
      }

19 Source : TinyJsonReader.cs
with Apache License 2.0
from allenai

private void SkipWhiteSpace()
        {
            var c = this.reader.Peek();
            while (c != -1 && Char.IsWhiteSpace((char)c))
            {
                this.reader.Read();
                c = this.reader.Peek();
            }
        }

19 Source : StringNormalizationExtensions.cs
with MIT License
from AllocZero

public static string NormalizeWhiteSpace(this string self)
        {
            if (string.IsNullOrEmpty(self))
            {
                return string.Empty;
            }

            var currentIndex = 0;
            var skipped = false;
            var output = new char[self.Length];

            foreach (var currentChar in self.ToCharArray())
            {
                if (char.IsWhiteSpace(currentChar))
                {
                    if (!skipped)
                    {
                        if (currentIndex > 0)
                        {
                            output[currentIndex++] = ' ';
                        }

                        skipped = true;
                    }
                }
                else
                {
                    skipped = false;
                    output[currentIndex++] = currentChar;
                }
            }

            return new string(output, 0, currentIndex);
        }

19 Source : DockerContainerDetails.cs
with Apache License 2.0
from aloneguid

public void Report(string value)
      {
         //convert to printable string
         char[] pChars = value.ToCharArray().Where(c => !char.IsControl(c) || char.IsWhiteSpace(c)).ToArray();
         string pValue = new string(pChars, 0, pChars.Length);
         pValue += Environment.NewLine;

         txtLogs.AppendText(pValue);
         _logLinesCount += 1;

         tabLogs.Text = $"Logs ({_logLinesCount})";
      }

19 Source : CharExtension.cs
with MIT License
from AlphaYu

public static bool IsWhiteSpace(this char c)
        {
            return char.IsWhiteSpace(c);
        }

19 Source : Lexer.cs
with MIT License
from Alprog

public IEnumerator<Token> Tokenize(string line)
        {
            var token = new Token(TokenType.Invalid, 0, line.Length);
            int i = 0;
            while (i < line.Length)
            {
                var c = line[i];
                if (Char.IsWhiteSpace(c))
                {
                    // WhiteSpace
                    i++;
                    continue;
                }
                else if (Char.IsLetter(c) || c.Equals('_'))
                {
                    // Identifier or Keyword
                    int si = i; i++;
                    while (i < line.Length)
                    {
                        c = line[i];
                        if (Char.IsLetterOrDigit(c) || c.Equals('_'))
                        {
                            i++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    var tokenText = line.Substring(si, i - si);
                    if (tokenText.ToLower() == "true")
                    {
                        token = ValueToken(si, i - si, true);
                    }
                    else if (tokenText.ToLower() == "false")
                    {
                        token = ValueToken(si, i - si, false);
                    }
                    else if (tokenText.ToLower() == "null")
                    {
                        token = ValueToken(si, i - si, null);
                    }
                    else
                    {
                        if (i < line.Length && line[i].Equals('…'))
                        {
                            token = new Token(TokenType.Autocomplete, si, i - si, tokenText);
                            i++;
                        }
                        else
                        {
                            token = new Token(TokenType.Identifier, si, i - si, tokenText);
                        }
                    }
                }
                else if (c.Equals('\"'))
                {
                    // String
                    int si = i; i++;
                    bool ended = false;
                    while (i < line.Length)
                    {
                        c = line[i];
                        if (!c.Equals('\"'))
                        {
                            i++;
                        }
                        else
                        {
                            ended = true;
                            i++;
                            break;
                        }
                    }
                    if (ended)
                    {
                        var text = line.Substring(si + 1, i - si - 2);
                        token = ValueToken(si, i - si, text);
                    }
                    else
                    {
                        token = new Token(TokenType.Invalid, si, i - si);
                    }
                }
                else if (Char.IsDigit(c) || c.Equals('-'))
                {
                    // Minus or digit
                    if (c.Equals('-'))
                    {
                        if (token.Type == TokenType.Value ||
                            token.Type == TokenType.Identifier ||
                            token.Type == TokenType.ClosedBracket)
                        {
                            // force minus operator
                            i++;
                            token = new Token(TokenType.Operator, i, 1, Operator.Get("-"));
                            yield return token;
                            continue;
                        }
                    }

                    int si = i; i++;
                    while (i < line.Length)
                    {
                        c = line[i];
                        if (Char.IsDigit(c) || c.Equals('.'))
                        {
                            i++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    var tokenText = line.Substring(si, i - si);
                    if (tokenText == "-")
                    {
                        token = new Token(TokenType.Operator, si, i - si, Operator.Get(tokenText));
                        i++;
                    }
                    else
                    {
                        float number;
                        if (Single.TryParse(tokenText, NumberStyles.Any, CultureInfo.InvariantCulture, out number))
                        {
                            token = ValueToken(si, i - si, number);
                        }
                        else
                        {
                            token = new Token(TokenType.Invalid, si, i - si);
                        }
                    }
                }
                else if (operators.Contains(c.ToString()))
                {
                    // Operator
                    int si = i; i++;
                    while (i < line.Length)
                    {
                        c = line[i];
                        if (operators.Contains(c.ToString()))
                        {
                            i++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    var tokenText = line.Substring(si, i - si);
                    if (tokenText == "=")
                    {
                        token = new Token(TokenType.replacedignmentOperator, si, i - si);
                    }
                    else
                    {
                        token = new Token(TokenType.Operator, si, i - si, Operator.Get(tokenText));
                    }
                }
                else if (c.Equals('.'))
                {
                    token = new Token(TokenType.Dot, i, 1);
                    i++;
                }
                else if (c.Equals('('))
                {
                    token = new Token(TokenType.OpenBracket, i, 1);
                    i++;
                }
                else if (c.Equals(')'))
                {
                    token = new Token(TokenType.ClosedBracket, i, 1);
                    i++;
                }
                else if (c.Equals(','))
                {
                    token = new Token(TokenType.Comma, i, 1);
                    i++;
                }
                else if (c.Equals('…'))
                {
                    token = new Token(TokenType.Autocomplete, i, 1, String.Empty);
                    i++;
                }
                else
                {
                    token = new Token(TokenType.Invalid, i, 1);
                    i++;
                }

                yield return token;
            }

            yield return new Token(TokenType.EndOfLine, i, 0);
        }

19 Source : StringEx.cs
with MIT License
from AmazingDM

public static bool IsWhiteSpace(this string value)
        {
            foreach (var c in value)
            {
                if (char.IsWhiteSpace(c)) continue;

                return false;
            }
            return true;
        }

19 Source : StringBuilderExtensions.cs
with MIT License
from Aminator

public static StringBuilder TrimEnd(this StringBuilder sb)
        {
            if (sb.Length == 0) return sb;

            int i;

            for (i = sb.Length - 1; i >= 0; i--)
            {
                if (!char.IsWhiteSpace(sb[i]))
                {
                    break;
                }
            }

            if (i < sb.Length - 1)
            {
                sb.Length = i + 1;
            }

            return sb;
        }

19 Source : AssetHandler.cs
with GNU General Public License v3.0
from AndrasMumm

private int _GetWordCount(string text)
        {
            int wordCount = 0, index = 0;

            // skip whitespace until first word
            while (index < text.Length && char.IsWhiteSpace(text[index]))
                index++;

            while (index < text.Length)
            {
                // check if current char is part of a word
                while (index < text.Length && !char.IsWhiteSpace(text[index]))
                    index++;

                wordCount++;

                // skip whitespace until next word
                while (index < text.Length && char.IsWhiteSpace(text[index]))
                    index++;
            }

            return wordCount;
        }

19 Source : StringBuilderExtensions.cs
with MIT License
from AndreyAkinshin

public static StringBuilder TrimEnd([CanBeNull] this StringBuilder builder, params char[] trimChars)
        {
            if (builder == null)
                return null;

            int length = builder.Length;
            if (trimChars.Any())
                while (length > 0 && trimChars.Contains(builder[length - 1]))
                    length--;
            else
                while (length > 0 && char.IsWhiteSpace(builder[length - 1]))
                    length--;

            builder.Length = length;
            return builder;
        }

19 Source : Threshold.cs
with MIT License
from AndreyAkinshin

public static bool TryParse(string input, NumberStyles numberStyle, IFormatProvider formatProvider, out Threshold parsed)
        {
            if (string.IsNullOrWhiteSpace(input))
            {
                parsed = default;
                return false;
            }

            var trimmed = input.Trim().ToLowerInvariant();
            var number = new string(trimmed.TakeWhile(c => char.IsDigit(c) || c == '.' || c == ',').ToArray());
            var unit = new string(trimmed.SkipWhile(c => char.IsDigit(c) || c == '.' || c == ',' || char.IsWhiteSpace(c)).ToArray());

            if (!double.TryParse(number, numberStyle, formatProvider, out var parsedValue)
                || !ThresholdUnitExtensions.ShortNameToUnit.TryGetValue(unit, out var parsedUnit))
            {
                parsed = default;
                return false;
            }

            parsed = parsedUnit == ThresholdUnit.Ratio ? Create(ThresholdUnit.Ratio, parsedValue / 100.0) : Create(parsedUnit, parsedValue);

            return true;
        }

19 Source : EgsDoseLoader.cs
with Apache License 2.0
from anmcgrath

private string readNumberString(TextReader reader)
        {
            while (Char.IsWhiteSpace((char)reader.Peek())) //Read all the whitespace until the start of the next number
                reader.Read();
            string numberString = "";
            bool inNumber = true;
            while (inNumber)
            {
                int num = reader.Read();
                char c = (char)num;
                if (Char.IsWhiteSpace(c))
                    inNumber = false;
                else
                {
                    numberString += c;
                }
            }
            return numberString;
        }

19 Source : KeyboardInteropHelper.cs
with MIT License
from AnnoDesigner

private static bool IsVisibleCharacter(char c)
        {
            return !(char.IsWhiteSpace(c) || char.IsControl(c));
        }

19 Source : TemplateProcessor.cs
with MIT License
from ansel86castro

private static void SkipSpaces(string template, ref int i)
        {
            while (i < template.Length && char.IsWhiteSpace(template[i]))
                i++;
        }

19 Source : TypeNameParser.cs
with GNU General Public License v3.0
from anydream

internal void SkipWhite() {
			while (true) {
				int next = PeekChar();
				if (next == -1)
					break;
				if (!char.IsWhiteSpace((char)next))
					break;
				ReadChar();
			}
		}

19 Source : TypeNameParser.cs
with GNU General Public License v3.0
from anydream

internal override int GetIdChar(bool ignoreWhiteSpace) {
			int c = PeekChar();
			if (c == -1)
				return -1;
			if (ignoreWhiteSpace && char.IsWhiteSpace((char)c))
				return -1;
			switch (c) {
			case '\\':
				ReadChar();
				return ReadChar();

			case ',':
			case '+':
			case '&':
			case '*':
			case '[':
			case ']':
			case '=':
				return -1;

			default:
				return ReadChar();
			}
		}

19 Source : Options.cs
with MIT License
from aolszowka

private static List<string> GetLines (string description)
		{
			List<string> lines = new List<string> ();
			if (string.IsNullOrEmpty (description)) {
				lines.Add (string.Empty);
				return lines;
			}
			int length = 80 - OptionWidth - 2;
			int start = 0, end;
			do {
				end = GetLineEnd (start, length, description);
				bool cont = false;
				if (end < description.Length) {
					char c = description [end];
					if (c == '-' || (char.IsWhiteSpace (c) && c != '\n'))
						++end;
					else if (c != '\n') {
						cont = true;
						--end;
					}
				}
				lines.Add (description.Substring (start, end - start));
				if (cont) {
					lines [lines.Count-1] += "-";
				}
				start = end;
				if (start < description.Length && description [start] == '\n')
					++start;
			} while (end < description.Length);
			return lines;
		}

19 Source : LineFormatter.cs
with MIT License
from ap0llo

internal static IReadOnlyList<(string value, bool isWhiteSpace)> GetStringSegments(string input)
        {
            // empty string => no segments
            if (String.IsNullOrEmpty(input))
                return Array.Empty<(string, bool)>();

            var segments = new List<(string, bool)>();

            var i = 0;
            while (i < input.Length)
            {
                // determine is current char is whitespace or not
                var isWhiteSpace = char.IsWhiteSpace(input[i]);

                // move i forward as long as all chars are whitespace or non-whitespace
                var start = i;
                while (i < input.Length && char.IsWhiteSpace(input[i]) == isWhiteSpace)
                {
                    i++;
                }

                // emit new segment
                segments.Add((input.Substring(start, i - start), isWhiteSpace));
            }

            return segments;
        }

19 Source : AFMiniJSON.cs
with MIT License
from AppsFlyerSDK

public static bool IsWordBreak(char c) {
                return Char.IsWhiteSpace(c) || WORD_BREAK.IndexOf(c) != -1;
            }

19 Source : AFMiniJSON.cs
with MIT License
from AppsFlyerSDK

void EatWhitespace() {
                while (Char.IsWhiteSpace(PeekChar)) {
                    json.Read();

                    if (json.Peek() == -1) {
                        break;
                    }
                }
            }

19 Source : HangmanGame.cs
with MIT License
from ardalis

public void Guess(char guessChar)
        {
            // TODO: Consider using Ardalis.GuardClauses
            // TODO: Consider returning Ardalis.Result
            if (char.IsWhiteSpace(guessChar)) throw new InvalidGuessException("Guess cannot be blank.");
            if (!Regex.IsMatch(guessChar.ToString(), "^[A-Z]$")) throw new InvalidGuessException("Guess must be a capital letter A through Z");
            if (IsOver) throw new InvalidGuessException("Can't make guesses after game is over.");

            if (PreviousGuesses.Any(g => g == guessChar)) throw new DuplicateGuessException();

            PreviousGuesses.Add(guessChar);

            if (_secretWord.IndexOf(guessChar) >= 0)
            {
                if (!CurrentMaskedWord.Contains(_maskChar))
                {
                    Result = GameResult.Won;
                }
                return;
            }

            if(GuessesRemaining <= 0)
            {
                Result = GameResult.Lost;
            }
        }

19 Source : Nexus_filetype.cs
with GNU Affero General Public License v3.0
from arklumpus

public static double IsSupported(string fileName)
        {
            using (StreamReader sr = new StreamReader(fileName))
            {
                StringBuilder sb = new StringBuilder();

                int c = sr.Read();

                while (c >= 0 && char.IsWhiteSpace((char)c))
                {
                    c = sr.Read();
                }

                sb.Append((char)c);
                for (int i = 0; i < 5; i++)
                {
                    c = sr.Read();
                    if (c >= 0)
                    {
                        sb.Append((char)c);
                    }
                }

                return sb.ToString().Equals("#NEXUS", StringComparison.OrdinalIgnoreCase) ? 0.5 : 0;
            }
        }

19 Source : NCBI_ASN.1.cs
with GNU Affero General Public License v3.0
from arklumpus

public static double IsSupported(string fileName)
        {
            using FileStream fileStream = File.OpenRead(fileName);

            using BinaryReader reader = new BinaryReader(fileStream);

            byte[] header = reader.ReadBytes(4);

            if (header[0] == 0x30 && header[1] == 0x80 && header[3] == 0x80)
            {
                return 0.8;
            }

            fileStream.Seek(0, SeekOrigin.Begin);

            using (StreamReader sr = new StreamReader(fileStream))
            {
                StringBuilder sb = new StringBuilder();

                int c = sr.Read();

                while (c >= 0 && char.IsWhiteSpace((char)c))
                {
                    c = sr.Read();
                }

                for (int i = 0; i < 16; i++)
                {
                    sb.Append((char)c);
                    c = sr.Read();
                }

                if (sb.ToString() == "BioTreeContainer")
                {
                    return 0.8;
                }
            }

            return 0;
        }

19 Source : Newick_filetype.cs
with GNU Affero General Public License v3.0
from arklumpus

public static double IsSupported(string fileName)
        {
            using (StreamReader sr = new StreamReader(fileName))
            {
                StringBuilder sb = new StringBuilder();

                int c = sr.Read();

                while (c >= 0 && char.IsWhiteSpace((char)c))
                {
                    c = sr.Read();
                }

                return ((char)c == '(') ? 0.01 : 0;
            }
        }

19 Source : Set_up_age_distributions_attachment.cs
with GNU Affero General Public License v3.0
from arklumpus

public static bool IsNEXUS(Stream fs)
        {
            long pos = fs.Position;

            try
            {
                using (StreamReader sr = new StreamReader(fs, leaveOpen: true))
                {
                    StringBuilder sb = new StringBuilder();

                    int c = sr.Read();

                    while (c >= 0 && char.IsWhiteSpace((char)c))
                    {
                        c = sr.Read();
                    }

                    sb.Append((char)c);
                    for (int i = 0; i < 5; i++)
                    {
                        c = sr.Read();
                        if (c >= 0)
                        {
                            sb.Append((char)c);
                        }
                    }

                    return sb.ToString().Equals("#NEXUS", StringComparison.OrdinalIgnoreCase);
                }
            }
            finally
            {
                fs.Position = pos;
            }
        }

19 Source : Set_up_age_distributions_attachment.cs
with GNU Affero General Public License v3.0
from arklumpus

private static bool IsASNTxt(Stream fs)
        {
            long pos = fs.Position;

            try
            {
                using (StreamReader sr = new StreamReader(fs, leaveOpen: true))
                {
                    StringBuilder sb = new StringBuilder();

                    int c = sr.Read();

                    while (c >= 0 && char.IsWhiteSpace((char)c))
                    {
                        c = sr.Read();
                    }

                    for (int i = 0; i < 16; i++)
                    {
                        sb.Append((char)c);
                        c = sr.Read();
                    }

                    return sb.ToString() == "BioTreeContainer";
                }
            }
            finally
            {
                fs.Position = pos;
            }
        }

19 Source : Set_up_age_distributions_attachment.cs
with GNU Affero General Public License v3.0
from arklumpus

public static bool IsNewick(Stream fs)
        {
            long pos = fs.Position;

            try
            {
                using (StreamReader sr = new StreamReader(fs, leaveOpen: true))
                {
                    int c = sr.Read();

                    while (c >= 0 && char.IsWhiteSpace((char)c))
                    {
                        c = sr.Read();
                    }

                    return (char)c == '(';
                }
            }
            finally
            {
                fs.Position = pos;
            }
        }

19 Source : ConsoleWrapper.cs
with GNU Affero General Public License v3.0
from arklumpus

public static bool IsPrintable(char c)
        {
            if (char.IsWhiteSpace(c))
            {
                return true;
            }
            else
            {
                UnicodeCategory cat = char.GetUnicodeCategory(c);
                return cat != UnicodeCategory.Control && cat != UnicodeCategory.OtherNotreplacedigned && cat != UnicodeCategory.Surrogate;
            }
        }

19 Source : AttachmentCommand.cs
with GNU Affero General Public License v3.0
from arklumpus

public override void Execute(string command)
        {
            if (Program.TransformedTree != null)
            {
                command = command.TrimStart();

                StringBuilder firstWordBuilder = new StringBuilder();

                foreach (char c in command)
                {
                    if (!char.IsWhiteSpace(c))
                    {
                        firstWordBuilder.Append(c);
                    }
                    else
                    {
                        break;
                    }
                }

                string firstWord = firstWordBuilder.ToString();

                if (firstWord.Equals("list", StringComparison.OrdinalIgnoreCase))
                {
                    if (Program.StateData.Attachments.Count > 0)
                    {
                        ConsoleWrapper.WriteLine();
                        ConsoleWrapper.WriteLine(new ConsoleTextSpan("  Loaded attachments:"));
                        ConsoleWrapper.WriteList(from el in Program.StateData.Attachments select new ConsoleTextSpan[] { new ConsoleTextSpan(el.Key, 4, ConsoleColor.Blue) }, "    ");
                        ConsoleWrapper.WriteLine();
                    }
                    else
                    {
                        ConsoleWrapper.WriteLine();
                        ConsoleWrapper.WriteLine(new ConsoleTextSpan("  No attachment has been loaded!"));
                        ConsoleWrapper.WriteLine();
                    }
                }
                else if (firstWord.Equals("info", StringComparison.OrdinalIgnoreCase))
                {
                    command = command.Substring(4).Trim();

                    if (Program.StateData.Attachments.TryGetValue(command, out Attachment att))
                    {
                        ConsoleWrapper.WriteLine();
                        ConsoleWrapper.WriteLine(new ConsoleTextSpan[] { new ConsoleTextSpan("  Attachment: ", 2), new ConsoleTextSpan(att.Name, 2, ConsoleColor.Blue) });
                        ConsoleWrapper.WriteLine();
                        ConsoleWrapper.WriteLine(new ConsoleTextSpan[] { new ConsoleTextSpan("    Size: ", 4), new ConsoleTextSpan(GetHumanReadableSize(att.StreamLength), 4, ConsoleColor.Cyan) });
                        ConsoleWrapper.WriteLine(new ConsoleTextSpan[] { new ConsoleTextSpan("    Store in memory: ", 4), new ConsoleTextSpan(att.StoreInMemory ? "yes" : "no", 4, ConsoleColor.Cyan) });
                        ConsoleWrapper.WriteLine(new ConsoleTextSpan[] { new ConsoleTextSpan("    Cache results: ", 4), new ConsoleTextSpan(att.CacheResults ? "yes" : "no", 4, ConsoleColor.Cyan) });
                        ConsoleWrapper.WriteLine();
                    }
                    else
                    {
                        ConsoleWrapper.WriteLine();
                        ConsoleWrapper.WriteLine(new ConsoleTextSpan[] { new ConsoleTextSpan("The specified attachment ", ConsoleColor.Red), new ConsoleTextSpan(command, ConsoleColor.Blue), new ConsoleTextSpan(" does not exist!", ConsoleColor.Red) });
                        ConsoleWrapper.WriteLine();
                    }
                }
                else if (firstWord.Equals("delete", StringComparison.OrdinalIgnoreCase))
                {
                    command = command.Substring(6).Trim();

                    if (Program.StateData.Attachments.Remove(command, out Attachment removed))
                    {
                        removed.Dispose();
                        Program.AttachmentList.Remove(removed.Name);
                    }
                    else
                    {
                        ConsoleWrapper.WriteLine();
                        ConsoleWrapper.WriteLine(new ConsoleTextSpan[] { new ConsoleTextSpan("The specified attachment ", ConsoleColor.Red), new ConsoleTextSpan(command, ConsoleColor.Blue), new ConsoleTextSpan(" does not exist!", ConsoleColor.Red) });
                        ConsoleWrapper.WriteLine();
                    }
                }
                else if (firstWord == "add")
                {
                    command = command.Substring(3).Trim();
                    if (!string.IsNullOrEmpty(command))
                    {
                        command = Path.GetFullPath(command.Trim().Trim('\"'));
                        if (File.Exists(command))
                        {
                            ConsoleWrapper.WriteLine();

                            string attachmentName = null;
                            bool cancelled = false;

                            while (string.IsNullOrWhiteSpace(attachmentName))
                            {
                                ConsoleWrapper.Write(new ConsoleTextSpan("  Enter attachment name: "));
                                attachmentName = ConsoleWrapper.ReadLine();

                                if (!string.IsNullOrEmpty(attachmentName))
                                {
                                    attachmentName = attachmentName.Replace("\b", "").Replace(";", "_");
                                }

                                if (attachmentName == null)
                                {
                                    cancelled = true;
                                    break;
                                }
                                else if (string.IsNullOrWhiteSpace(attachmentName))
                                {
                                    attachmentName = null;
                                    ConsoleWrapper.WriteLine();
                                    ConsoleWrapper.WriteLine(new ConsoleTextSpan("  Invalid attachment name!", 2, ConsoleColor.Red));
                                    ConsoleWrapper.WriteLine();
                                }
                                else if (Program.StateData.Attachments.ContainsKey(attachmentName))
                                {
                                    ConsoleWrapper.WriteLine();
                                    ConsoleWrapper.WriteLine(new ConsoleTextSpan("  There is another attachment with the same name!", 2, ConsoleColor.Red));
                                    ConsoleWrapper.WriteLine();
                                    attachmentName = null;
                                }
                            }

                            ConsoleWrapper.WriteLine();

                            if (!cancelled)
                            {
                                ConsoleWrapper.Write(new ConsoleTextSpan("  Should the attachment be stored in memory? [Y(es)/N(o)] ", 2));

                                char key = '?';

                                while (key != 'y' && key != 'Y' && key != 'n' && key != 'N')
                                {
                                    key = ConsoleWrapper.ReadKey(true).KeyChar;
                                }

                                ConsoleWrapper.Write(key);
                                ConsoleWrapper.WriteLine();

                                bool storeInMemory = false;

                                if (key == 'y' || key == 'Y')
                                {
                                    storeInMemory = true;
                                }
                                else if (key == 'n' || key == 'N')
                                {
                                    storeInMemory = false;
                                }

                                ConsoleWrapper.WriteLine();
                                ConsoleWrapper.Write(new ConsoleTextSpan("  Should the results of parsing the attachment be cached? [Y(es)/N(o)] ", 2));

                                key = '?';

                                while (key != 'y' && key != 'Y' && key != 'n' && key != 'N')
                                {
                                    key = ConsoleWrapper.ReadKey(true).KeyChar;
                                }

                                ConsoleWrapper.Write(key);
                                ConsoleWrapper.WriteLine();

                                bool cacheResults = false;

                                if (key == 'y' || key == 'Y')
                                {
                                    cacheResults = true;
                                }
                                else if (key == 'n' || key == 'N')
                                {
                                    cacheResults = false;
                                }

                                Program.StateData.Attachments.Add(attachmentName, new Attachment(attachmentName, cacheResults, storeInMemory, command));
                                Program.AttachmentList.Add(attachmentName);
                                Program.AttachmentList.Sort();

                                ConsoleWrapper.WriteLine();
                            }
                        }
                        else
                        {
                            ConsoleWrapper.WriteLine();
                            ConsoleWrapper.WriteLine(new ConsoleTextSpan("The specified file does not exist!", ConsoleColor.Red));
                            ConsoleWrapper.WriteLine();
                        }
                    }
                    else
                    {
                        ConsoleWrapper.WriteLine();
                        ConsoleWrapper.WriteLine(new ConsoleTextSpan("No file has been specified!", ConsoleColor.Red));
                        ConsoleWrapper.WriteLine();
                    }
                }
                else
                {
                    ConsoleWrapper.WriteLine();
                    ConsoleWrapper.WriteLine(new ConsoleTextSpan("Unknown action: " + command, ConsoleColor.Red));
                    ConsoleWrapper.WriteLine();
                }
            }
            else
            {
                ConsoleWrapper.WriteLine();
                ConsoleWrapper.WriteLine(new ConsoleTextSpan("No tree has been loaded!", ConsoleColor.Red));
                ConsoleWrapper.WriteLine();
            }
        }

19 Source : BinaryCommand.cs
with GNU Affero General Public License v3.0
from arklumpus

public override void Execute(string command)
        {
            UpdateCommand.UpdateRequired();

            if (string.IsNullOrWhiteSpace(command))
            {
                if (Program.TransformedTree != null)
                {
                    if (string.IsNullOrEmpty(lastFileName))
                    {
                        using (Stream sr = Console.OpenStandardOutput())
                        {
                            ExportToStream(sr, 2, false, false, false);
                        }
                    }
                    else
                    {
                        using (FileStream fs = new FileStream(lastFileName, FileMode.Create))
                        {
                            ExportToStream(fs, 2, false, false, false);
                        }
                    }
                }
                else
                {
                    ConsoleWrapper.WriteLine();
                    ConsoleWrapper.WriteLine(new ConsoleTextSpan("No tree has been loaded!", ConsoleColor.Red));
                    ConsoleWrapper.WriteLine();
                }
            }
            else
            {
                command = command.Trim();

                StringBuilder firstWordBuilder = new StringBuilder();

                foreach (char c in command)
                {
                    if (!char.IsWhiteSpace(c))
                    {
                        firstWordBuilder.Append(c);
                    }
                    else
                    {
                        break;
                    }
                }

                string firstWord = firstWordBuilder.ToString();

                int treeIndex = 2;

                bool modules = false;

                if (!string.IsNullOrWhiteSpace(firstWord) && firstWord.Equals("modules", StringComparison.OrdinalIgnoreCase))
                {
                    modules = true;

                    command = command.Substring(7).TrimStart();

                    if (!string.IsNullOrWhiteSpace(command))
                    {
                        firstWordBuilder = new StringBuilder();

                        foreach (char c in command)
                        {
                            if (!char.IsWhiteSpace(c))
                            {
                                firstWordBuilder.Append(c);
                            }
                            else
                            {
                                break;
                            }
                        }

                        firstWord = firstWordBuilder.ToString();
                    }
                    else
                    {
                        firstWord = null;
                    }
                }

                if (!string.IsNullOrWhiteSpace(firstWord) && firstWord.Equals("loaded", StringComparison.OrdinalIgnoreCase))
                {
                    treeIndex = 0;

                    command = command.Substring(6).TrimStart();

                    if (!string.IsNullOrWhiteSpace(command))
                    {
                        firstWordBuilder = new StringBuilder();

                        foreach (char c in command)
                        {
                            if (!char.IsWhiteSpace(c))
                            {
                                firstWordBuilder.Append(c);
                            }
                            else
                            {
                                break;
                            }
                        }

                        firstWord = firstWordBuilder.ToString();
                    }
                    else
                    {
                        firstWord = null;
                    }
                }

                if (!string.IsNullOrWhiteSpace(firstWord) && firstWord.Equals("transformed", StringComparison.OrdinalIgnoreCase))
                {
                    treeIndex = 1;

                    command = command.Substring(11).TrimStart();


                    if (!string.IsNullOrWhiteSpace(command))
                    {
                        firstWordBuilder = new StringBuilder();

                        foreach (char c in command)
                        {
                            if (!char.IsWhiteSpace(c))
                            {
                                firstWordBuilder.Append(c);
                            }
                            else
                            {
                                break;
                            }
                        }

                        firstWord = firstWordBuilder.ToString();
                    }
                    else
                    {
                        firstWord = null;
                    }
                }

                if (string.IsNullOrWhiteSpace(firstWord))
                {
                    if ((treeIndex == 0 && Program.Trees != null) || (treeIndex == 1 && Program.FirstTransformedTree != null) || (treeIndex == 2 && Program.TransformedTree != null))
                    {
                        if (string.IsNullOrEmpty(lastFileName))
                        {
                            using (Stream sr = Console.OpenStandardOutput())
                            {
                                ExportToStream(sr, treeIndex, modules, modules && NexusCommand.AskIfShouldAddSignature(), NexusCommand.AskIfShouldAddAttachments());
                            }
                        }
                        else
                        {
                            using (FileStream fs = new FileStream(lastFileName, FileMode.Create))
                            {
                                ExportToStream(fs, treeIndex, modules, modules && NexusCommand.AskIfShouldAddSignature(), NexusCommand.AskIfShouldAddAttachments());
                            }
                        }
                    }
                    else
                    {
                        ConsoleWrapper.WriteLine();
                        ConsoleWrapper.WriteLine(new ConsoleTextSpan("No tree has been loaded!", ConsoleColor.Red));
                        ConsoleWrapper.WriteLine();
                    }
                }
                else if (firstWord.Equals("stdout", StringComparison.OrdinalIgnoreCase))
                {
                    lastFileName = null;
                    if ((treeIndex == 0 && Program.Trees != null) || (treeIndex == 1 && Program.FirstTransformedTree != null) || (treeIndex == 2 && Program.TransformedTree != null))
                    {
                        if (string.IsNullOrEmpty(lastFileName))
                        {
                            using (Stream sr = Console.OpenStandardOutput())
                            {
                                ExportToStream(sr, treeIndex, modules, modules && NexusCommand.AskIfShouldAddSignature(), NexusCommand.AskIfShouldAddAttachments());
                            }
                        }
                        else
                        {
                            using (FileStream fs = new FileStream(lastFileName, FileMode.Create))
                            {
                                ExportToStream(fs, treeIndex, modules, modules && NexusCommand.AskIfShouldAddSignature(), NexusCommand.AskIfShouldAddAttachments());
                            }
                        }
                    }
                    else
                    {
                        ConsoleWrapper.WriteLine();
                        ConsoleWrapper.WriteLine(new ConsoleTextSpan("No tree has been loaded!", ConsoleColor.Red));
                        ConsoleWrapper.WriteLine();
                    }
                }
                else
                {
                    lastFileName = command.Trim('\"');

                    if ((treeIndex == 0 && Program.Trees != null) || (treeIndex == 1 && Program.FirstTransformedTree != null) || (treeIndex == 2 && Program.TransformedTree != null))
                    {
                        if (string.IsNullOrEmpty(lastFileName))
                        {
                            using (Stream sr = Console.OpenStandardOutput())
                            {
                                ExportToStream(sr, treeIndex, modules, modules && NexusCommand.AskIfShouldAddSignature(), NexusCommand.AskIfShouldAddAttachments());
                            }
                        }
                        else
                        {
                            using (FileStream fs = new FileStream(lastFileName, FileMode.Create))
                            {
                                ExportToStream(fs, treeIndex, modules, modules && NexusCommand.AskIfShouldAddSignature(), NexusCommand.AskIfShouldAddAttachments());
                            }
                        }
                    }
                    else
                    {
                        ConsoleWrapper.WriteLine();
                        ConsoleWrapper.WriteLine(new ConsoleTextSpan("No tree has been loaded!", ConsoleColor.Red));
                        ConsoleWrapper.WriteLine();
                    }
                }
            }

        }

19 Source : EnwkCommand.cs
with GNU Affero General Public License v3.0
from arklumpus

public override IEnumerable<(ConsoleTextSpan[], string)> GetCompletions(string partialCommand)
        {
            if (string.IsNullOrWhiteSpace(partialCommand))
            {
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("enwk", ConsoleColor.Green) }, "enwk ");
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("enwk ", ConsoleColor.Green), new ConsoleTextSpan("stdout", ConsoleColor.Yellow) }, "enwk stdout ");
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("enwk ", ConsoleColor.Green), new ConsoleTextSpan("loaded", ConsoleColor.Yellow) }, "enwk loaded ");
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("enwk ", ConsoleColor.Green), new ConsoleTextSpan("transformed", ConsoleColor.Yellow) }, "enwk transformed ");

                foreach ((ConsoleTextSpan[], string) item in OptionCommand.GetFileCompletion(partialCommand, "enwk"))
                {
                    yield return item;
                }
            }
            else
            {
                partialCommand = partialCommand.TrimStart();

                StringBuilder firstWordBuilder = new StringBuilder();

                foreach (char c in partialCommand)
                {
                    if (!char.IsWhiteSpace(c))
                    {
                        firstWordBuilder.Append(c);
                    }
                    else
                    {
                        break;
                    }
                }

                string firstWord = firstWordBuilder.ToString();


                if (firstWord.Equals("stdout", StringComparison.OrdinalIgnoreCase))
                {
                    yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("enwk ", ConsoleColor.Green), new ConsoleTextSpan("stdout", ConsoleColor.Yellow) }, "enwk stdout ");
                }
                else if (firstWord.Equals("loaded", StringComparison.OrdinalIgnoreCase) || firstWord.Equals("transformed", StringComparison.OrdinalIgnoreCase))
                {
                    partialCommand = partialCommand.Substring(firstWord.Length).TrimStart();

                    if (string.IsNullOrWhiteSpace(partialCommand))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("enwk ", ConsoleColor.Green), new ConsoleTextSpan(firstWord, ConsoleColor.Yellow) }, "enwk " + firstWord + " ");
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("enwk ", ConsoleColor.Green), new ConsoleTextSpan(firstWord + " stdout", ConsoleColor.Yellow) }, "enwk " + firstWord + " stdout ");

                        foreach ((ConsoleTextSpan[], string) item in OptionCommand.GetFileCompletion(partialCommand, "enwk " + firstWord))
                        {
                            yield return item;
                        }
                    }
                    else
                    {
                        if ("stdout".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                        {
                            yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("enwk ", ConsoleColor.Green), new ConsoleTextSpan(firstWord + " stdout", ConsoleColor.Yellow) }, "enwk " + firstWord + " stdout ");
                        }

                        foreach ((ConsoleTextSpan[], string) item in OptionCommand.GetFileCompletion(partialCommand, "enwk " + firstWord))
                        {
                            yield return item;
                        }
                    }
                }
                else
                {
                    if ("stdout".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("enwk ", ConsoleColor.Green), new ConsoleTextSpan("stdout", ConsoleColor.Yellow) }, "enwk stdout ");
                    }

                    if ("loaded".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("enwk ", ConsoleColor.Green), new ConsoleTextSpan("loaded", ConsoleColor.Yellow) }, "enwk loaded ");
                    }

                    if ("transformed".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("enwk ", ConsoleColor.Green), new ConsoleTextSpan("transformed", ConsoleColor.Yellow) }, "enwk transformed ");
                    }

                    foreach ((ConsoleTextSpan[], string) item in OptionCommand.GetFileCompletion(partialCommand, "enwk"))
                    {
                        yield return item;
                    }
                }

            }
        }

19 Source : HelpCommand.cs
with GNU Affero General Public License v3.0
from arklumpus

public override IEnumerable<(ConsoleTextSpan[], string)> GetCompletions(string partialCommand)
        {
            partialCommand = partialCommand.TrimStart();

            StringBuilder firstWordBuilder = new StringBuilder();

            foreach (char c in partialCommand)
            {
                if (!char.IsWhiteSpace(c))
                {
                    firstWordBuilder.Append(c);
                }
                else
                {
                    break;
                }
            }

            string firstWord = firstWordBuilder.ToString();

            if (string.IsNullOrWhiteSpace(firstWord))
            {
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan(this.PrimaryCommand, ConsoleColor.Green) }, this.PrimaryCommand + " ");
            }

            if (firstWord == partialCommand)
            {
                foreach (Command command in Commands.AllAvailableCommands)
                {
                    if (command.PrimaryCommand.StartsWith(firstWord, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan(this.PrimaryCommand + " ", ConsoleColor.Green), new ConsoleTextSpan(command.PrimaryCommand, ConsoleColor.Blue) }, this.PrimaryCommand + " " + command.PrimaryCommand + " ");
                    }
                }
            }
            else
            {
                yield break;
            }
        }

19 Source : NewickCommand.cs
with GNU Affero General Public License v3.0
from arklumpus

public override void Execute(string command)
        {
            UpdateCommand.UpdateRequired();

            if (string.IsNullOrWhiteSpace(command))
            {
                if (Program.TransformedTree != null)
                {
                    if (string.IsNullOrEmpty(lastFileName))
                    {
                        using (Stream sr = Console.OpenStandardOutput())
                        {
                            ExportToStream(sr, 2);
                        }
                    }
                    else
                    {
                        using (FileStream fs = new FileStream(lastFileName, FileMode.Create))
                        {
                            ExportToStream(fs, 2);
                        }
                    }
                }
                else
                {
                    ConsoleWrapper.WriteLine();
                    ConsoleWrapper.WriteLine(new ConsoleTextSpan("No tree has been loaded!", ConsoleColor.Red));
                    ConsoleWrapper.WriteLine();
                }
            }
            else
            {
                command = command.Trim();

                StringBuilder firstWordBuilder = new StringBuilder();

                foreach (char c in command)
                {
                    if (!char.IsWhiteSpace(c))
                    {
                        firstWordBuilder.Append(c);
                    }
                    else
                    {
                        break;
                    }
                }

                string firstWord = firstWordBuilder.ToString();

                int treeIndex = 2;

                if (!string.IsNullOrWhiteSpace(firstWord) && firstWord.Equals("loaded", StringComparison.OrdinalIgnoreCase))
                {
                    treeIndex = 0;

                    command = command.Substring(6).TrimStart();

                    if (!string.IsNullOrWhiteSpace(command))
                    {
                        firstWordBuilder = new StringBuilder();

                        foreach (char c in command)
                        {
                            if (!char.IsWhiteSpace(c))
                            {
                                firstWordBuilder.Append(c);
                            }
                            else
                            {
                                break;
                            }
                        }

                        firstWord = firstWordBuilder.ToString();
                    }
                    else
                    {
                        firstWord = null;
                    }
                }

                if (!string.IsNullOrWhiteSpace(firstWord) && firstWord.Equals("transformed", StringComparison.OrdinalIgnoreCase))
                {
                    treeIndex = 1;

                    command = command.Substring(11).TrimStart();


                    if (!string.IsNullOrWhiteSpace(command))
                    {
                        firstWordBuilder = new StringBuilder();

                        foreach (char c in command)
                        {
                            if (!char.IsWhiteSpace(c))
                            {
                                firstWordBuilder.Append(c);
                            }
                            else
                            {
                                break;
                            }
                        }

                        firstWord = firstWordBuilder.ToString();
                    }
                    else
                    {
                        firstWord = null;
                    }
                }

                if (string.IsNullOrWhiteSpace(firstWord))
                {
                    if ((treeIndex == 0 && Program.Trees != null) || (treeIndex == 1 && Program.FirstTransformedTree != null) || (treeIndex == 2 && Program.TransformedTree != null))
                    {
                        if (string.IsNullOrEmpty(lastFileName))
                        {
                            using (Stream sr = Console.OpenStandardOutput())
                            {
                                ExportToStream(sr, treeIndex);
                            }
                        }
                        else
                        {
                            using (FileStream fs = new FileStream(lastFileName, FileMode.Create))
                            {
                                ExportToStream(fs, treeIndex);
                            }
                        }
                    }
                    else
                    {
                        ConsoleWrapper.WriteLine();
                        ConsoleWrapper.WriteLine(new ConsoleTextSpan("No tree has been loaded!", ConsoleColor.Red));
                        ConsoleWrapper.WriteLine();
                    }
                }
                else if (firstWord.Equals("stdout", StringComparison.OrdinalIgnoreCase))
                {
                    lastFileName = null;
                    if ((treeIndex == 0 && Program.Trees != null) || (treeIndex == 1 && Program.FirstTransformedTree != null) || (treeIndex == 2 && Program.TransformedTree != null))
                    {
                        if (string.IsNullOrEmpty(lastFileName))
                        {
                            using (Stream sr = Console.OpenStandardOutput())
                            {
                                ExportToStream(sr, treeIndex);
                            }
                        }
                        else
                        {
                            using (FileStream fs = new FileStream(lastFileName, FileMode.Create))
                            {
                                ExportToStream(fs, treeIndex);
                            }
                        }
                    }
                    else
                    {
                        ConsoleWrapper.WriteLine();
                        ConsoleWrapper.WriteLine(new ConsoleTextSpan("No tree has been loaded!", ConsoleColor.Red));
                        ConsoleWrapper.WriteLine();
                    }
                }
                else
                {
                    lastFileName = command.Trim('\"');

                    if ((treeIndex == 0 && Program.Trees != null) || (treeIndex == 1 && Program.FirstTransformedTree != null) || (treeIndex == 2 && Program.TransformedTree != null))
                    {
                        if (string.IsNullOrEmpty(lastFileName))
                        {
                            using (Stream sr = Console.OpenStandardOutput())
                            {
                                ExportToStream(sr, treeIndex);
                            }
                        }
                        else
                        {
                            using (FileStream fs = new FileStream(lastFileName, FileMode.Create))
                            {
                                ExportToStream(fs, treeIndex);
                            }
                        }
                    }
                    else
                    {
                        ConsoleWrapper.WriteLine();
                        ConsoleWrapper.WriteLine(new ConsoleTextSpan("No tree has been loaded!", ConsoleColor.Red));
                        ConsoleWrapper.WriteLine();
                    }
                }
            }

        }

19 Source : NexusCommand.cs
with GNU Affero General Public License v3.0
from arklumpus

public override void Execute(string command)
        {
            UpdateCommand.UpdateRequired();

            if (string.IsNullOrWhiteSpace(command))
            {
                if (Program.TransformedTree != null)
                {
                    if (string.IsNullOrEmpty(lastFileName))
                    {
                        using (Stream sr = Console.OpenStandardOutput())
                        {
                            ExportToStream(sr, 2, false, false, false);
                        }
                    }
                    else
                    {
                        using (FileStream fs = new FileStream(lastFileName, FileMode.Create))
                        {
                            ExportToStream(fs, 2, false, false, false);
                        }
                    }
                }
                else
                {
                    ConsoleWrapper.WriteLine();
                    ConsoleWrapper.WriteLine(new ConsoleTextSpan("No tree has been loaded!", ConsoleColor.Red));
                    ConsoleWrapper.WriteLine();
                }
            }
            else
            {
                command = command.Trim();

                StringBuilder firstWordBuilder = new StringBuilder();

                foreach (char c in command)
                {
                    if (!char.IsWhiteSpace(c))
                    {
                        firstWordBuilder.Append(c);
                    }
                    else
                    {
                        break;
                    }
                }

                string firstWord = firstWordBuilder.ToString();

                int treeIndex = 2;

                bool modules = false;

                if (!string.IsNullOrWhiteSpace(firstWord) && firstWord.Equals("modules", StringComparison.OrdinalIgnoreCase))
                {
                    modules = true;

                    command = command.Substring(7).TrimStart();

                    if (!string.IsNullOrWhiteSpace(command))
                    {
                        firstWordBuilder = new StringBuilder();

                        foreach (char c in command)
                        {
                            if (!char.IsWhiteSpace(c))
                            {
                                firstWordBuilder.Append(c);
                            }
                            else
                            {
                                break;
                            }
                        }

                        firstWord = firstWordBuilder.ToString();
                    }
                    else
                    {
                        firstWord = null;
                    }
                }

                if (!string.IsNullOrWhiteSpace(firstWord) && firstWord.Equals("loaded", StringComparison.OrdinalIgnoreCase))
                {
                    treeIndex = 0;

                    command = command.Substring(6).TrimStart();

                    if (!string.IsNullOrWhiteSpace(command))
                    {
                        firstWordBuilder = new StringBuilder();

                        foreach (char c in command)
                        {
                            if (!char.IsWhiteSpace(c))
                            {
                                firstWordBuilder.Append(c);
                            }
                            else
                            {
                                break;
                            }
                        }

                        firstWord = firstWordBuilder.ToString();
                    }
                    else
                    {
                        firstWord = null;
                    }
                }

                if (!string.IsNullOrWhiteSpace(firstWord) && firstWord.Equals("transformed", StringComparison.OrdinalIgnoreCase))
                {
                    treeIndex = 1;

                    command = command.Substring(11).TrimStart();


                    if (!string.IsNullOrWhiteSpace(command))
                    {
                        firstWordBuilder = new StringBuilder();

                        foreach (char c in command)
                        {
                            if (!char.IsWhiteSpace(c))
                            {
                                firstWordBuilder.Append(c);
                            }
                            else
                            {
                                break;
                            }
                        }

                        firstWord = firstWordBuilder.ToString();
                    }
                    else
                    {
                        firstWord = null;
                    }
                }

                if (string.IsNullOrWhiteSpace(firstWord))
                {
                    if ((treeIndex == 0 && Program.Trees != null) || (treeIndex == 1 && Program.FirstTransformedTree != null) || (treeIndex == 2 && Program.TransformedTree != null))
                    {
                        if (string.IsNullOrEmpty(lastFileName))
                        {
                            using (Stream sr = Console.OpenStandardOutput())
                            {
                                ExportToStream(sr, treeIndex, modules, modules && AskIfShouldAddSignature(), AskIfShouldAddAttachments());
                            }
                        }
                        else
                        {
                            using (FileStream fs = new FileStream(lastFileName, FileMode.Create))
                            {
                                ExportToStream(fs, treeIndex, modules, modules && AskIfShouldAddSignature(), AskIfShouldAddAttachments());
                            }
                        }
                    }
                    else
                    {
                        ConsoleWrapper.WriteLine();
                        ConsoleWrapper.WriteLine(new ConsoleTextSpan("No tree has been loaded!", ConsoleColor.Red));
                        ConsoleWrapper.WriteLine();
                    }
                }
                else if (firstWord.Equals("stdout", StringComparison.OrdinalIgnoreCase))
                {
                    lastFileName = null;
                    if ((treeIndex == 0 && Program.Trees != null) || (treeIndex == 1 && Program.FirstTransformedTree != null) || (treeIndex == 2 && Program.TransformedTree != null))
                    {
                        if (string.IsNullOrEmpty(lastFileName))
                        {
                            using (Stream sr = Console.OpenStandardOutput())
                            {
                                ExportToStream(sr, treeIndex, modules, modules && AskIfShouldAddSignature(), AskIfShouldAddAttachments());
                            }
                        }
                        else
                        {
                            using (FileStream fs = new FileStream(lastFileName, FileMode.Create))
                            {
                                ExportToStream(fs, treeIndex, modules, modules && AskIfShouldAddSignature(), AskIfShouldAddAttachments());
                            }
                        }
                    }
                    else
                    {
                        ConsoleWrapper.WriteLine();
                        ConsoleWrapper.WriteLine(new ConsoleTextSpan("No tree has been loaded!", ConsoleColor.Red));
                        ConsoleWrapper.WriteLine();
                    }
                }
                else
                {
                    lastFileName = command.Trim('\"');

                    if ((treeIndex == 0 && Program.Trees != null) || (treeIndex == 1 && Program.FirstTransformedTree != null) || (treeIndex == 2 && Program.TransformedTree != null))
                    {
                        if (string.IsNullOrEmpty(lastFileName))
                        {
                            using (Stream sr = Console.OpenStandardOutput())
                            {
                                ExportToStream(sr, treeIndex, modules, modules && AskIfShouldAddSignature(), AskIfShouldAddAttachments());
                            }
                        }
                        else
                        {
                            using (FileStream fs = new FileStream(lastFileName, FileMode.Create))
                            {
                                ExportToStream(fs, treeIndex, modules, modules && AskIfShouldAddSignature(), AskIfShouldAddAttachments());
                            }
                        }
                    }
                    else
                    {
                        ConsoleWrapper.WriteLine();
                        ConsoleWrapper.WriteLine(new ConsoleTextSpan("No tree has been loaded!", ConsoleColor.Red));
                        ConsoleWrapper.WriteLine();
                    }
                }
            }

        }

19 Source : OpenCommand.cs
with GNU Affero General Public License v3.0
from arklumpus

public override void Execute(string command)
        {
            if (string.IsNullOrWhiteSpace(command))
            {
                if (!string.IsNullOrEmpty(Program.InputFileName))
                {
                    OpenFile(Program.InputFileName, null);
                }
                else
                {
                    ConsoleWrapper.WriteLine();
                    ConsoleWrapper.WriteLine(new ConsoleTextSpan("No input file selected!", ConsoleColor.Red));
                    ConsoleWrapper.WriteLine();
                }
            }
            else
            {
                command = command.TrimStart();

                StringBuilder firstWordBuilder = new StringBuilder();

                foreach (char c in command)
                {
                    if (!char.IsWhiteSpace(c))
                    {
                        firstWordBuilder.Append(c);
                    }
                    else
                    {
                        break;
                    }
                }

                string firstWord = firstWordBuilder.ToString();

                if (firstWord.Equals("with", StringComparison.OrdinalIgnoreCase))
                {
                    if (!string.IsNullOrEmpty(Program.InputFileName))
                    {
                        command = command.Substring(4).Trim();

                        bool found = false;

                        foreach (FileTypeModule mod in Modules.FileTypeModules)
                        {
                            if (mod.Name.Equals(command, StringComparison.OrdinalIgnoreCase) || mod.Id.Equals(command, StringComparison.OrdinalIgnoreCase))
                            {
                                OpenFile(Program.InputFileName, mod.Id);
                                found = true;
                                break;
                            }
                        }

                        if (!found)
                        {
                            ConsoleWrapper.WriteLine();
                            ConsoleWrapper.WriteLine(new ConsoleTextSpan("Could not find the specified module!", ConsoleColor.Red));
                            ConsoleWrapper.WriteLine();
                        }
                    }
                    else
                    {
                        ConsoleWrapper.WriteLine();
                        ConsoleWrapper.WriteLine(new ConsoleTextSpan("No input file selected!", ConsoleColor.Red));
                        ConsoleWrapper.WriteLine();
                    }
                }
                else if (firstWord.Equals("info", StringComparison.OrdinalIgnoreCase))
                {
                    if (!string.IsNullOrEmpty(Program.InputFileName))
                    {
                        Dictionary<string, double> info = GetOpenInfo(Program.InputFileName);
                        (string, string, double)[] scores = (from el in info orderby el.Value descending select (el.Key, Modules.GetModule(Modules.FileTypeModules, el.Key).Name, el.Value)).ToArray();

                        int maxNameLength = (from el in scores select el.Item2.Length).Max() + 4;
                        int maxKeyLength = (from el in scores select el.Item1.Length).Max();
                        int maxValueLength = (from el in scores select el.Item3.ToString("0.####").Length).Max() + 4;

                        maxNameLength = Math.Max(maxNameLength, "Module name".Length + 4);
                        maxKeyLength = Math.Max(maxKeyLength, "Module id".Length);
                        maxValueLength = Math.Max(maxValueLength, "Priority".Length + 4);

                        ConsoleWrapper.WriteLine();

                        ConsoleWrapper.WriteLine(new ConsoleTextSpan[] {
                                new ConsoleTextSpan(new string(ConsoleWrapper.Whitespace, 2) + "Priority" + new string(ConsoleWrapper.Whitespace, maxValueLength - "Priority".Length), 2),
                                new ConsoleTextSpan("Module name" + new string(ConsoleWrapper.Whitespace, maxNameLength - "Module name".Length), 2),
                                new ConsoleTextSpan("Module id" + new string(ConsoleWrapper.Whitespace, maxKeyLength - "Module id".Length), 2)
                                });


                        ConsoleWrapper.WriteLine(new ConsoleTextSpan[] {
                                new ConsoleTextSpan(new string(ConsoleWrapper.Whitespace, 2) + new string('─', maxNameLength + maxKeyLength + maxValueLength), 2)
                                });


                        for (int i = 0; i < scores.Length; i++)
                        {
                            ConsoleWrapper.WriteLine(new ConsoleTextSpan[] {
                                new ConsoleTextSpan(new string(ConsoleWrapper.Whitespace, 2)),
                                new ConsoleTextSpan(scores[i].Item3.ToString("0.####") + new string(ConsoleWrapper.Whitespace, maxValueLength - scores[i].Item3.ToString("0.####").Length), 2, scores[i].Item3 <= 0 ? ConsoleColor.Red : i == 0 ? ConsoleColor.Green : ConsoleColor.Yellow),
                                new ConsoleTextSpan(scores[i].Item2 + new string(ConsoleWrapper.Whitespace, maxNameLength - scores[i].Item2.Length), 2),
                                new ConsoleTextSpan(scores[i].Item1 + new string(ConsoleWrapper.Whitespace, maxKeyLength - scores[i].Item1.Length), 2)
                                });
                        }

                        ConsoleWrapper.WriteLine();
                    }
                    else
                    {
                        ConsoleWrapper.WriteLine();
                        ConsoleWrapper.WriteLine(new ConsoleTextSpan("No input file selected!", ConsoleColor.Red));
                        ConsoleWrapper.WriteLine();
                    }
                }
                else
                {
                    command = Path.GetFullPath(command.Trim().Trim('\"'));
                    if (File.Exists(command))
                    {
                        Program.InputFileName = command;
                        OpenFile(Program.InputFileName, null);
                        LoadCommand.LoadFile(null);
                    }
                    else
                    {
                        ConsoleWrapper.WriteLine();
                        ConsoleWrapper.WriteLine(new ConsoleTextSpan("The specified file does not exist!", ConsoleColor.Red));
                        ConsoleWrapper.WriteLine();
                    }
                }
            }
        }

19 Source : OpenCommand.cs
with GNU Affero General Public License v3.0
from arklumpus

public override IEnumerable<(ConsoleTextSpan[], string)> GetCompletions(string partialCommand)
        {
            if (string.IsNullOrWhiteSpace(partialCommand))
            {
                if (!string.IsNullOrEmpty(Program.InputFileName))
                {
                    yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("open", ConsoleColor.Green) }, "open ");
                    yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("open ", ConsoleColor.Green), new ConsoleTextSpan("info", ConsoleColor.Yellow) }, "open info ");
                    yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("open ", ConsoleColor.Green), new ConsoleTextSpan("with", ConsoleColor.Yellow) }, "open with ");
                }

                string[] directories = Directory.GetDirectories(Directory.GetCurrentDirectory(), "*");

                List<(ConsoleTextSpan[], string)> tbr = new List<(ConsoleTextSpan[], string)>();

                foreach (string sr in directories)
                {
                    tbr.Add((new ConsoleTextSpan[]
                    {
                        new ConsoleTextSpan(Path.GetFileName(sr) + " ", ConsoleColor.Blue)
                    }, this.PrimaryCommand + " " + Path.GetFileName(sr) + Path.DirectorySeparatorChar));
                }


                string[] files = Directory.GetFiles(Directory.GetCurrentDirectory(), "*");

                foreach (string sr in files)
                {
                    tbr.Add((new ConsoleTextSpan[]
                    {
                        new ConsoleTextSpan(Path.GetFileName(sr) + " ", ConsoleColor.Red)
                    }, this.PrimaryCommand + " " + Path.GetFileName(sr) + " "));
                }

                tbr.Sort((a, b) => a.Item2.CompareTo(b.Item2));

                foreach ((ConsoleTextSpan[], string) item in tbr)
                {
                    yield return item;
                }
            }
            else
            {
                partialCommand = partialCommand.TrimStart();

                StringBuilder firstWordBuilder = new StringBuilder();

                foreach (char c in partialCommand)
                {
                    if (!char.IsWhiteSpace(c))
                    {
                        firstWordBuilder.Append(c);
                    }
                    else
                    {
                        break;
                    }
                }

                string firstWord = firstWordBuilder.ToString();

                if (firstWord.Equals("with", StringComparison.OrdinalIgnoreCase))
                {
                    partialCommand = partialCommand.Substring(4).TrimStart();

                    foreach (FileTypeModule mod in Modules.FileTypeModules)
                    {
                        if (mod.Name.StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                        {
                            yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("open ", ConsoleColor.Green), new ConsoleTextSpan("with ", ConsoleColor.Yellow), new ConsoleTextSpan(mod.Name + " ", ConsoleColor.Blue) }, "open with " + mod.Name + " ");
                        }
                    }

                    foreach (FileTypeModule mod in Modules.FileTypeModules)
                    {
                        if (mod.Id.StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                        {
                            yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("open ", ConsoleColor.Green), new ConsoleTextSpan("with ", ConsoleColor.Yellow), new ConsoleTextSpan(mod.Id + " ", ConsoleColor.Blue) }, "open with " + mod.Id + " ");
                        }
                    }
                }
                else if (firstWord.Equals("info", StringComparison.OrdinalIgnoreCase))
                {
                    yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("open ", ConsoleColor.Green), new ConsoleTextSpan("info", ConsoleColor.Yellow) }, "open info ");
                }
                else
                {
                    if ("with".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("open ", ConsoleColor.Green), new ConsoleTextSpan("with", ConsoleColor.Yellow) }, "open with ");
                    }

                    if ("info".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("open ", ConsoleColor.Green), new ConsoleTextSpan("info", ConsoleColor.Yellow) }, "open info ");
                    }

                    Regex reg = new Regex("^[A-Za-z]:$");
                    if (reg.IsMatch(partialCommand))
                    {
                        partialCommand = partialCommand + "\\";
                    }

                    partialCommand = partialCommand.Trim();
                    string directory = null;

                    directory = Path.GetDirectoryName(partialCommand);


                    if (directory == null)
                    {
                        reg = new Regex("^[A-Za-z]:\\\\$");
                        if (reg.IsMatch(partialCommand))
                        {
                            directory = partialCommand;
                        }
                    }

                    string actualDirectory = directory;

                    if (string.IsNullOrEmpty(actualDirectory))
                    {
                        actualDirectory = Directory.GetCurrentDirectory();
                    }

                    string fileName = Path.GetFileName(partialCommand);

                    string[] directories = Directory.GetDirectories(actualDirectory, fileName + "*");

                    List<(ConsoleTextSpan[], string)> tbr = new List<(ConsoleTextSpan[], string)>();

                    foreach (string sr in directories)
                    {
                        tbr.Add((new ConsoleTextSpan[]
                        {
                        new ConsoleTextSpan(Path.GetFileName(sr) + " ", ConsoleColor.Blue)
                        }, this.PrimaryCommand + " " + Path.Combine(directory, Path.GetFileName(sr)) + Path.DirectorySeparatorChar));
                    }


                    string[] files = Directory.GetFiles(actualDirectory, fileName + "*");

                    foreach (string sr in files)
                    {
                        tbr.Add((new ConsoleTextSpan[]
                        {
                        new ConsoleTextSpan(Path.GetFileName(sr) + " ", ConsoleColor.Red)
                        }, this.PrimaryCommand + " " + Path.Combine(directory, Path.GetFileName(sr)) + " "));
                    }

                    tbr.Sort((a, b) => a.Item2.CompareTo(b.Item2));

                    foreach ((ConsoleTextSpan[], string) item in tbr)
                    {
                        yield return item;
                    }
                }
            }
        }

19 Source : SVGCommand.cs
with GNU Affero General Public License v3.0
from arklumpus

public override IEnumerable<(ConsoleTextSpan[], string)> GetCompletions(string partialCommand)
        {
            if (string.IsNullOrWhiteSpace(partialCommand))
            {
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("svg", ConsoleColor.Green) }, "svg ");
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("svg ", ConsoleColor.Green), new ConsoleTextSpan("stdout", ConsoleColor.Yellow) }, "svg stdout ");

                string[] directories = Directory.GetDirectories(Directory.GetCurrentDirectory(), "*");

                List<(ConsoleTextSpan[], string)> tbr = new List<(ConsoleTextSpan[], string)>();

                foreach (string sr in directories)
                {
                    tbr.Add((new ConsoleTextSpan[]
                    {
                        new ConsoleTextSpan(Path.GetFileName(sr) + " ", ConsoleColor.Blue)
                    }, this.PrimaryCommand + " " + Path.GetFileName(sr) + Path.DirectorySeparatorChar));
                }


                string[] files = Directory.GetFiles(Directory.GetCurrentDirectory(), "*");

                foreach (string sr in files)
                {
                    tbr.Add((new ConsoleTextSpan[]
                    {
                        new ConsoleTextSpan(Path.GetFileName(sr) + " ", ConsoleColor.Red)
                    }, this.PrimaryCommand + " " + Path.GetFileName(sr) + " "));
                }

                tbr.Sort((a, b) => a.Item2.CompareTo(b.Item2));

                foreach ((ConsoleTextSpan[], string) item in tbr)
                {
                    yield return item;
                }
            }
            else
            {
                partialCommand = partialCommand.TrimStart();

                StringBuilder firstWordBuilder = new StringBuilder();

                foreach (char c in partialCommand)
                {
                    if (!char.IsWhiteSpace(c))
                    {
                        firstWordBuilder.Append(c);
                    }
                    else
                    {
                        break;
                    }
                }

                string firstWord = firstWordBuilder.ToString();

                if (firstWord.Equals("stdout", StringComparison.OrdinalIgnoreCase))
                {
                    partialCommand = partialCommand.Substring(4).TrimStart();

                    yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("svg ", ConsoleColor.Green), new ConsoleTextSpan("stdout", ConsoleColor.Yellow) }, "svg stdout ");
                }
                else
                {
                    if ("stdout".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("svg ", ConsoleColor.Green), new ConsoleTextSpan("stdout", ConsoleColor.Yellow) }, "svg stdout ");
                    }

                    Regex reg = new Regex("^[A-Za-z]:$");
                    if (reg.IsMatch(partialCommand))
                    {
                        partialCommand = partialCommand + "\\";
                    }

                    partialCommand = partialCommand.Trim();
                    string directory = null;

                    directory = Path.GetDirectoryName(partialCommand);


                    if (directory == null)
                    {
                        reg = new Regex("^[A-Za-z]:\\\\$");
                        if (reg.IsMatch(partialCommand))
                        {
                            directory = partialCommand;
                        }
                    }

                    string actualDirectory = directory;

                    if (string.IsNullOrEmpty(actualDirectory))
                    {
                        actualDirectory = Directory.GetCurrentDirectory();
                    }

                    string fileName = Path.GetFileName(partialCommand);

                    string[] directories = Directory.GetDirectories(actualDirectory, fileName + "*");

                    List<(ConsoleTextSpan[], string)> tbr = new List<(ConsoleTextSpan[], string)>();

                    foreach (string sr in directories)
                    {
                        tbr.Add((new ConsoleTextSpan[]
                        {
                        new ConsoleTextSpan(Path.GetFileName(sr) + " ", ConsoleColor.Blue)
                        }, this.PrimaryCommand + " " + Path.Combine(directory, Path.GetFileName(sr)) + Path.DirectorySeparatorChar));
                    }


                    string[] files = Directory.GetFiles(actualDirectory, fileName + "*");

                    foreach (string sr in files)
                    {
                        tbr.Add((new ConsoleTextSpan[]
                        {
                        new ConsoleTextSpan(Path.GetFileName(sr) + " ", ConsoleColor.Red)
                        }, this.PrimaryCommand + " " + Path.Combine(directory, Path.GetFileName(sr)) + " "));
                    }

                    tbr.Sort((a, b) => a.Item2.CompareTo(b.Item2));

                    foreach ((ConsoleTextSpan[], string) item in tbr)
                    {
                        yield return item;
                    }
                }
            }
        }

19 Source : HtmlTag.cs
with GNU General Public License v3.0
from arklumpus

private static HtmlTag ParseTag(StringReader reader)
        {
            StringBuilder tagBuilder = new StringBuilder();

            int character = reader.Read();

            while (character >= 0 && (char)character != '<')
            {
                character = reader.Read();
            }

            if ((char)character == '<')
            {
                character = reader.Read();
            }

            while (character >= 0 && char.IsWhiteSpace((char)character))
            {
                character = reader.Read();
            }

            while (character >= 0 && !char.IsWhiteSpace((char)character) && (char)character != '>')
            {
                tagBuilder.Append((char)character);
                character = reader.Read();
            }

            string tag = tagBuilder.ToString();

            Dictionary<string, string> attributes = new Dictionary<string, string>();

            (string, string)? attribute = ReadAttribute(reader, ref character);

            while (attribute != null && character >= 0)
            {
                attributes[attribute.Value.Item1] = attribute.Value.Item2;
                attribute = ReadAttribute(reader, ref character);
            }

            return new HtmlTag(tag, attributes);
        }

19 Source : HtmlTag.cs
with GNU General Public License v3.0
from arklumpus

private static (string, string)? ReadAttribute(StringReader reader, ref int character)
        {
            while (character >= 0 && char.IsWhiteSpace((char)character) && (char)character != '>')
            {
                character = reader.Read();
            }

            if ((char)character == '>')
            {
                return null;
            }
            else
            {
                StringBuilder attributeNameBuilder = new StringBuilder();

                while (character >= 0 && !char.IsWhiteSpace((char)character) && (char)character != '>' && (char)character != '=')
                {
                    attributeNameBuilder.Append((char)character);
                    character = reader.Read();
                }

                string attributeName = attributeNameBuilder.ToString();

                while (character >= 0 && char.IsWhiteSpace((char)character) && (char)character != '>' && (char)character != '=')
                {
                    character = reader.Read();
                }

                if ((char)character == '=')
                {
                    character = reader.Read();

                    while (character >= 0 && char.IsWhiteSpace((char)character) && (char)character != '>')
                    {
                        character = reader.Read();
                    }

                    if ((char)character == '>')
                    {
                        return (attributeName, null);
                    }
                    else
                    {
                        bool quoted = (char)character == '"' || (char)character == '\'';

                        if (quoted)
                        {
                            char quoteChar = (char)character;

                            character = reader.Read();

                            StringBuilder attributeValueBuilder = new StringBuilder();

                            bool isEscaped = (char)character == '\\';

                            while (character >= 0 && ((char)character != quoteChar || isEscaped))
                            {
                                attributeValueBuilder.Append((char)character);
                                character = reader.Read();
                                isEscaped = (char)character == '\\' && !isEscaped;
                            }

                            string attributeValue = attributeValueBuilder.ToString();

                            return (attributeName, attributeValue);
                        }
                        else
                        {
                            StringBuilder attributeValueBuilder = new StringBuilder();

                            while (character >= 0 && !char.IsWhiteSpace((char)character) && (char)character != '>' && (char)character != '=')
                            {
                                attributeValueBuilder.Append((char)character);
                                character = reader.Read();
                            }

                            string attributeValue = attributeValueBuilder.ToString();

                            return (attributeName, attributeValue);
                        }
                    }
                }
                else
                {
                    return (attributeName, null);
                }
            }
        }

19 Source : Word.cs
with GNU General Public License v3.0
from arklumpus

private static IEnumerable<Word> GetWordsInternal(string text, Font font)
        {
            StringBuilder currWord = new StringBuilder();

            char currWhitespace = '\0';
            int whitespaceCount = 0;

            for (int i = 0; i < text.Length; i++)
            {
                if (char.IsWhiteSpace(text[i]))
                {
                    if (currWord.Length > 0)
                    {
                        yield return new Word(currWhitespace, whitespaceCount, currWord.ToString(), font);

                        currWord.Clear();
                        currWhitespace = text[i];
                        whitespaceCount = 1;
                    }
                    else if (currWhitespace == text[i])
                    {
                        whitespaceCount++;
                    }
                    else
                    {
                        yield return new Word(currWhitespace, whitespaceCount, null, font);

                        currWhitespace = text[i];
                        whitespaceCount = 1;
                    }
                }
                else
                {
                    currWord.Append(text[i]);
                }
            }

            if (currWord.Length > 0)
            {
                yield return new Word(currWhitespace, whitespaceCount, currWord.ToString(), font);

                currWord.Clear();
            }
            else if (whitespaceCount > 0)
            {
                yield return new Word(currWhitespace, whitespaceCount, null, font);
            }
        }

19 Source : BinaryCommand.cs
with GNU Affero General Public License v3.0
from arklumpus

public override IEnumerable<(ConsoleTextSpan[], string)> GetCompletions(string partialCommand)
        {
            if (string.IsNullOrWhiteSpace(partialCommand))
            {
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("binary", ConsoleColor.Green) }, "binary ");
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("binary ", ConsoleColor.Green), new ConsoleTextSpan("modules", ConsoleColor.Yellow) }, "binary modules ");
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("binary ", ConsoleColor.Green), new ConsoleTextSpan("stdout", ConsoleColor.Yellow) }, "binary stdout ");
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("binary ", ConsoleColor.Green), new ConsoleTextSpan("loaded", ConsoleColor.Yellow) }, "binary loaded ");
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("binary ", ConsoleColor.Green), new ConsoleTextSpan("transformed", ConsoleColor.Yellow) }, "binary transformed ");

                foreach ((ConsoleTextSpan[], string) item in OptionCommand.GetFileCompletion(partialCommand, "binary"))
                {
                    yield return item;
                }
            }
            else
            {
                partialCommand = partialCommand.TrimStart();

                StringBuilder firstWordBuilder = new StringBuilder();

                foreach (char c in partialCommand)
                {
                    if (!char.IsWhiteSpace(c))
                    {
                        firstWordBuilder.Append(c);
                    }
                    else
                    {
                        break;
                    }
                }

                string firstWord = firstWordBuilder.ToString();

                if (firstWord.Equals("modules", StringComparison.OrdinalIgnoreCase))
                {
                    partialCommand = partialCommand.Substring(7).TrimStart();

                    if (string.IsNullOrWhiteSpace(partialCommand))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("binary ", ConsoleColor.Green), new ConsoleTextSpan("modules", ConsoleColor.Yellow) }, "binary modules ");
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("binary ", ConsoleColor.Green), new ConsoleTextSpan("modules stdout", ConsoleColor.Yellow) }, "binary modules stdout ");
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("binary ", ConsoleColor.Green), new ConsoleTextSpan("modules loaded", ConsoleColor.Yellow) }, "binary modules loaded ");
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("binary ", ConsoleColor.Green), new ConsoleTextSpan("modules transformed", ConsoleColor.Yellow) }, "binary modules transformed ");

                        foreach ((ConsoleTextSpan[], string) item in OptionCommand.GetFileCompletion(partialCommand, "binary modules"))
                        {
                            yield return item;
                        }
                    }
                    else
                    {
                        firstWordBuilder = new StringBuilder();

                        foreach (char c in partialCommand)
                        {
                            if (!char.IsWhiteSpace(c))
                            {
                                firstWordBuilder.Append(c);
                            }
                            else
                            {
                                break;
                            }
                        }

                        firstWord = firstWordBuilder.ToString();

                        if (firstWord.Equals("stdout", StringComparison.OrdinalIgnoreCase))
                        {
                            yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("binary ", ConsoleColor.Green), new ConsoleTextSpan("modules stdout", ConsoleColor.Yellow) }, "binary modules stdout ");
                        }
                        else if (firstWord.Equals("loaded", StringComparison.OrdinalIgnoreCase) || firstWord.Equals("transformed", StringComparison.OrdinalIgnoreCase))
                        {
                            partialCommand = partialCommand.Substring(firstWord.Length).TrimStart();

                            if (string.IsNullOrWhiteSpace(partialCommand))
                            {
                                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("binary ", ConsoleColor.Green), new ConsoleTextSpan(firstWord, ConsoleColor.Yellow) }, "binary modules " + firstWord + " ");
                                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("binary ", ConsoleColor.Green), new ConsoleTextSpan("modules " + firstWord + " stdout", ConsoleColor.Yellow) }, "binary modules " + firstWord + " stdout ");

                                foreach ((ConsoleTextSpan[], string) item in OptionCommand.GetFileCompletion(partialCommand, "binary modules " + firstWord))
                                {
                                    yield return item;
                                }
                            }
                            else
                            {
                                if ("stdout".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                                {
                                    yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("binary ", ConsoleColor.Green), new ConsoleTextSpan("modules " + firstWord + " stdout", ConsoleColor.Yellow) }, "binary modules " + firstWord + " stdout ");
                                }

                                foreach ((ConsoleTextSpan[], string) item in OptionCommand.GetFileCompletion(partialCommand, "binary modules " + firstWord))
                                {
                                    yield return item;
                                }
                            }
                        }
                        else
                        {
                            if ("stdout".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                            {
                                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("binary ", ConsoleColor.Green), new ConsoleTextSpan("modules stdout", ConsoleColor.Yellow) }, "binary modules stdout ");
                            }

                            if ("loaded".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                            {
                                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("binary ", ConsoleColor.Green), new ConsoleTextSpan("modules loaded", ConsoleColor.Yellow) }, "binary modules loaded ");
                            }

                            if ("transformed".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                            {
                                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("binary ", ConsoleColor.Green), new ConsoleTextSpan("modules transformed", ConsoleColor.Yellow) }, "binary modules transformed ");
                            }

                            foreach ((ConsoleTextSpan[], string) item in OptionCommand.GetFileCompletion(partialCommand, "binary modules"))
                            {
                                yield return item;
                            }
                        }
                    }
                }
                else if (firstWord.Equals("stdout", StringComparison.OrdinalIgnoreCase))
                {
                    yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("binary ", ConsoleColor.Green), new ConsoleTextSpan("stdout", ConsoleColor.Yellow) }, "binary stdout ");
                }
                else if (firstWord.Equals("loaded", StringComparison.OrdinalIgnoreCase) || firstWord.Equals("transformed", StringComparison.OrdinalIgnoreCase))
                {
                    partialCommand = partialCommand.Substring(firstWord.Length).TrimStart();

                    if (string.IsNullOrWhiteSpace(partialCommand))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("binary ", ConsoleColor.Green), new ConsoleTextSpan(firstWord, ConsoleColor.Yellow) }, "binary " + firstWord + " ");
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("binary ", ConsoleColor.Green), new ConsoleTextSpan(firstWord + " stdout", ConsoleColor.Yellow) }, "binary " + firstWord + " stdout ");

                        foreach ((ConsoleTextSpan[], string) item in OptionCommand.GetFileCompletion(partialCommand, "binary " + firstWord))
                        {
                            yield return item;
                        }
                    }
                    else
                    {
                        if ("stdout".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                        {
                            yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("binary ", ConsoleColor.Green), new ConsoleTextSpan(firstWord + " stdout", ConsoleColor.Yellow) }, "binary " + firstWord + " stdout ");
                        }

                        foreach ((ConsoleTextSpan[], string) item in OptionCommand.GetFileCompletion(partialCommand, "binary " + firstWord))
                        {
                            yield return item;
                        }
                    }
                }
                else
                {
                    if ("modules".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("binary ", ConsoleColor.Green), new ConsoleTextSpan("modules", ConsoleColor.Yellow) }, "binary modules ");
                    }

                    if ("stdout".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("binary ", ConsoleColor.Green), new ConsoleTextSpan("stdout", ConsoleColor.Yellow) }, "binary stdout ");
                    }

                    if ("loaded".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("binary ", ConsoleColor.Green), new ConsoleTextSpan("loaded", ConsoleColor.Yellow) }, "binary loaded ");
                    }

                    if ("transformed".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("binary ", ConsoleColor.Green), new ConsoleTextSpan("transformed", ConsoleColor.Yellow) }, "binary transformed ");
                    }

                    foreach ((ConsoleTextSpan[], string) item in OptionCommand.GetFileCompletion(partialCommand, "binary"))
                    {
                        yield return item;
                    }
                }

            }
        }

19 Source : LoadCommand.cs
with GNU Affero General Public License v3.0
from arklumpus

public override IEnumerable<(ConsoleTextSpan[], string)> GetCompletions(string partialCommand)
        {
            if (string.IsNullOrWhiteSpace(partialCommand))
            {
                if (!string.IsNullOrEmpty(Program.InputFileName))
                {
                    yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("load", ConsoleColor.Green) }, "load ");
                    yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("load ", ConsoleColor.Green), new ConsoleTextSpan("info", ConsoleColor.Yellow) }, "load info ");
                    yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("load ", ConsoleColor.Green), new ConsoleTextSpan("with", ConsoleColor.Yellow) }, "load with ");
                }
            }
            else
            {
                partialCommand = partialCommand.TrimStart();

                StringBuilder firstWordBuilder = new StringBuilder();

                foreach (char c in partialCommand)
                {
                    if (!char.IsWhiteSpace(c))
                    {
                        firstWordBuilder.Append(c);
                    }
                    else
                    {
                        break;
                    }
                }

                string firstWord = firstWordBuilder.ToString();

                if (firstWord.Equals("with", StringComparison.OrdinalIgnoreCase))
                {
                    partialCommand = partialCommand.Substring(4).TrimStart();

                    foreach (LoadFileModule mod in Modules.LoadFileModules)
                    {
                        if (mod.Name.StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                        {
                            yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("load ", ConsoleColor.Green), new ConsoleTextSpan("with ", ConsoleColor.Yellow), new ConsoleTextSpan(mod.Name + " ", ConsoleColor.Blue) }, "load with " + mod.Name + " ");
                        }
                    }

                    foreach (LoadFileModule mod in Modules.LoadFileModules)
                    {
                        if (mod.Id.StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                        {
                            yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("load ", ConsoleColor.Green), new ConsoleTextSpan("with ", ConsoleColor.Yellow), new ConsoleTextSpan(mod.Id + " ", ConsoleColor.Blue) }, "load with " + mod.Id + " ");
                        }
                    }
                }
                else if (firstWord.Equals("info", StringComparison.OrdinalIgnoreCase))
                {
                    yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("load ", ConsoleColor.Green), new ConsoleTextSpan("info", ConsoleColor.Yellow) }, "load info ");
                }
                else
                {
                    if ("with".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("load ", ConsoleColor.Green), new ConsoleTextSpan("with", ConsoleColor.Yellow) }, "load with ");
                    }

                    if ("info".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("load ", ConsoleColor.Green), new ConsoleTextSpan("info", ConsoleColor.Yellow) }, "load info ");
                    }
                }
            }
        }

19 Source : NewickCommand.cs
with GNU Affero General Public License v3.0
from arklumpus

public override IEnumerable<(ConsoleTextSpan[], string)> GetCompletions(string partialCommand)
        {
            if (string.IsNullOrWhiteSpace(partialCommand))
            {
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("newick", ConsoleColor.Green) }, "newick ");
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("newick ", ConsoleColor.Green), new ConsoleTextSpan("stdout", ConsoleColor.Yellow) }, "newick stdout ");
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("newick ", ConsoleColor.Green), new ConsoleTextSpan("loaded", ConsoleColor.Yellow) }, "newick loaded ");
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("newick ", ConsoleColor.Green), new ConsoleTextSpan("transformed", ConsoleColor.Yellow) }, "newick transformed ");

                foreach ((ConsoleTextSpan[], string) item in OptionCommand.GetFileCompletion(partialCommand, "newick"))
                {
                    yield return item;
                }
            }
            else
            {
                partialCommand = partialCommand.TrimStart();

                StringBuilder firstWordBuilder = new StringBuilder();

                foreach (char c in partialCommand)
                {
                    if (!char.IsWhiteSpace(c))
                    {
                        firstWordBuilder.Append(c);
                    }
                    else
                    {
                        break;
                    }
                }

                string firstWord = firstWordBuilder.ToString();


                if (firstWord.Equals("stdout", StringComparison.OrdinalIgnoreCase))
                {
                    yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("newick ", ConsoleColor.Green), new ConsoleTextSpan("stdout", ConsoleColor.Yellow) }, "newick stdout ");
                }
                else if (firstWord.Equals("loaded", StringComparison.OrdinalIgnoreCase) || firstWord.Equals("transformed", StringComparison.OrdinalIgnoreCase))
                {
                    partialCommand = partialCommand.Substring(firstWord.Length).TrimStart();

                    if (string.IsNullOrWhiteSpace(partialCommand))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("newick ", ConsoleColor.Green), new ConsoleTextSpan(firstWord, ConsoleColor.Yellow) }, "newick " + firstWord + " ");
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("newick ", ConsoleColor.Green), new ConsoleTextSpan(firstWord + " stdout", ConsoleColor.Yellow) }, "newick " + firstWord + " stdout ");

                        foreach ((ConsoleTextSpan[], string) item in OptionCommand.GetFileCompletion(partialCommand, "newick " + firstWord))
                        {
                            yield return item;
                        }
                    }
                    else
                    {
                        if ("stdout".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                        {
                            yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("newick ", ConsoleColor.Green), new ConsoleTextSpan(firstWord + " stdout", ConsoleColor.Yellow) }, "newick " + firstWord + " stdout ");
                        }

                        foreach ((ConsoleTextSpan[], string) item in OptionCommand.GetFileCompletion(partialCommand, "newick " + firstWord))
                        {
                            yield return item;
                        }
                    }
                }
                else
                {
                    if ("stdout".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("newick ", ConsoleColor.Green), new ConsoleTextSpan("stdout", ConsoleColor.Yellow) }, "newick stdout ");
                    }

                    if ("loaded".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("newick ", ConsoleColor.Green), new ConsoleTextSpan("loaded", ConsoleColor.Yellow) }, "newick loaded ");
                    }

                    if ("transformed".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("newick ", ConsoleColor.Green), new ConsoleTextSpan("transformed", ConsoleColor.Yellow) }, "newick transformed ");
                    }

                    foreach ((ConsoleTextSpan[], string) item in OptionCommand.GetFileCompletion(partialCommand, "newick"))
                    {
                        yield return item;
                    }
                }

            }
        }

19 Source : NexusCommand.cs
with GNU Affero General Public License v3.0
from arklumpus

public override IEnumerable<(ConsoleTextSpan[], string)> GetCompletions(string partialCommand)
        {
            if (string.IsNullOrWhiteSpace(partialCommand))
            {
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("nexus", ConsoleColor.Green) }, "nexus ");
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("nexus ", ConsoleColor.Green), new ConsoleTextSpan("modules", ConsoleColor.Yellow) }, "nexus modules ");
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("nexus ", ConsoleColor.Green), new ConsoleTextSpan("stdout", ConsoleColor.Yellow) }, "nexus stdout ");
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("nexus ", ConsoleColor.Green), new ConsoleTextSpan("loaded", ConsoleColor.Yellow) }, "nexus loaded ");
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("nexus ", ConsoleColor.Green), new ConsoleTextSpan("transformed", ConsoleColor.Yellow) }, "nexus transformed ");

                foreach ((ConsoleTextSpan[], string) item in OptionCommand.GetFileCompletion(partialCommand, "nexus"))
                {
                    yield return item;
                }
            }
            else
            {
                partialCommand = partialCommand.TrimStart();

                StringBuilder firstWordBuilder = new StringBuilder();

                foreach (char c in partialCommand)
                {
                    if (!char.IsWhiteSpace(c))
                    {
                        firstWordBuilder.Append(c);
                    }
                    else
                    {
                        break;
                    }
                }

                string firstWord = firstWordBuilder.ToString();

                if (firstWord.Equals("modules", StringComparison.OrdinalIgnoreCase))
                {
                    partialCommand = partialCommand.Substring(7).TrimStart();

                    if (string.IsNullOrWhiteSpace(partialCommand))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("nexus ", ConsoleColor.Green), new ConsoleTextSpan("modules", ConsoleColor.Yellow) }, "nexus modules ");
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("nexus ", ConsoleColor.Green), new ConsoleTextSpan("modules stdout", ConsoleColor.Yellow) }, "nexus modules stdout ");
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("nexus ", ConsoleColor.Green), new ConsoleTextSpan("modules loaded", ConsoleColor.Yellow) }, "nexus modules loaded ");
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("nexus ", ConsoleColor.Green), new ConsoleTextSpan("modules transformed", ConsoleColor.Yellow) }, "nexus modules transformed ");

                        foreach ((ConsoleTextSpan[], string) item in OptionCommand.GetFileCompletion(partialCommand, "nexus modules"))
                        {
                            yield return item;
                        }
                    }
                    else
                    {
                        firstWordBuilder = new StringBuilder();

                        foreach (char c in partialCommand)
                        {
                            if (!char.IsWhiteSpace(c))
                            {
                                firstWordBuilder.Append(c);
                            }
                            else
                            {
                                break;
                            }
                        }

                        firstWord = firstWordBuilder.ToString();

                        if (firstWord.Equals("stdout", StringComparison.OrdinalIgnoreCase))
                        {
                            yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("nexus ", ConsoleColor.Green), new ConsoleTextSpan("modules stdout", ConsoleColor.Yellow) }, "nexus modules stdout ");
                        }
                        else if (firstWord.Equals("loaded", StringComparison.OrdinalIgnoreCase) || firstWord.Equals("transformed", StringComparison.OrdinalIgnoreCase))
                        {
                            partialCommand = partialCommand.Substring(firstWord.Length).TrimStart();

                            if (string.IsNullOrWhiteSpace(partialCommand))
                            {
                                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("nexus ", ConsoleColor.Green), new ConsoleTextSpan(firstWord, ConsoleColor.Yellow) }, "nexus modules " + firstWord + " ");
                                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("nexus ", ConsoleColor.Green), new ConsoleTextSpan("modules " + firstWord + " stdout", ConsoleColor.Yellow) }, "nexus modules " + firstWord + " stdout ");

                                foreach ((ConsoleTextSpan[], string) item in OptionCommand.GetFileCompletion(partialCommand, "nexus modules " + firstWord))
                                {
                                    yield return item;
                                }
                            }
                            else
                            {
                                if ("stdout".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                                {
                                    yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("nexus ", ConsoleColor.Green), new ConsoleTextSpan("modules " + firstWord + " stdout", ConsoleColor.Yellow) }, "nexus modules " + firstWord + " stdout ");
                                }

                                foreach ((ConsoleTextSpan[], string) item in OptionCommand.GetFileCompletion(partialCommand, "nexus modules " + firstWord))
                                {
                                    yield return item;
                                }
                            }
                        }
                        else
                        {
                            if ("stdout".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                            {
                                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("nexus ", ConsoleColor.Green), new ConsoleTextSpan("modules stdout", ConsoleColor.Yellow) }, "nexus modules stdout ");
                            }

                            if ("loaded".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                            {
                                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("nexus ", ConsoleColor.Green), new ConsoleTextSpan("modules loaded", ConsoleColor.Yellow) }, "nexus modules loaded ");
                            }

                            if ("transformed".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                            {
                                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("nexus ", ConsoleColor.Green), new ConsoleTextSpan("modules transformed", ConsoleColor.Yellow) }, "nexus modules transformed ");
                            }

                            foreach ((ConsoleTextSpan[], string) item in OptionCommand.GetFileCompletion(partialCommand, "nexus modules"))
                            {
                                yield return item;
                            }
                        }
                    }
                }
                else if (firstWord.Equals("stdout", StringComparison.OrdinalIgnoreCase))
                {
                    yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("nexus ", ConsoleColor.Green), new ConsoleTextSpan("stdout", ConsoleColor.Yellow) }, "nexus stdout ");
                }
                else if (firstWord.Equals("loaded", StringComparison.OrdinalIgnoreCase) || firstWord.Equals("transformed", StringComparison.OrdinalIgnoreCase))
                {
                    partialCommand = partialCommand.Substring(firstWord.Length).TrimStart();

                    if (string.IsNullOrWhiteSpace(partialCommand))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("nexus ", ConsoleColor.Green), new ConsoleTextSpan(firstWord, ConsoleColor.Yellow) }, "nexus " + firstWord + " ");
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("nexus ", ConsoleColor.Green), new ConsoleTextSpan(firstWord + " stdout", ConsoleColor.Yellow) }, "nexus " + firstWord + " stdout ");

                        foreach ((ConsoleTextSpan[], string) item in OptionCommand.GetFileCompletion(partialCommand, "nexus " + firstWord))
                        {
                            yield return item;
                        }
                    }
                    else
                    {
                        if ("stdout".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                        {
                            yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("nexus ", ConsoleColor.Green), new ConsoleTextSpan(firstWord + " stdout", ConsoleColor.Yellow) }, "nexus " + firstWord + " stdout ");
                        }

                        foreach ((ConsoleTextSpan[], string) item in OptionCommand.GetFileCompletion(partialCommand, "nexus " + firstWord))
                        {
                            yield return item;
                        }
                    }
                }
                else
                {
                    if ("modules".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("nexus ", ConsoleColor.Green), new ConsoleTextSpan("modules", ConsoleColor.Yellow) }, "nexus modules ");
                    }

                    if ("stdout".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("nexus ", ConsoleColor.Green), new ConsoleTextSpan("stdout", ConsoleColor.Yellow) }, "nexus stdout ");
                    }

                    if ("loaded".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("nexus ", ConsoleColor.Green), new ConsoleTextSpan("loaded", ConsoleColor.Yellow) }, "nexus loaded ");
                    }

                    if ("transformed".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("nexus ", ConsoleColor.Green), new ConsoleTextSpan("transformed", ConsoleColor.Yellow) }, "nexus transformed ");
                    }

                    foreach ((ConsoleTextSpan[], string) item in OptionCommand.GetFileCompletion(partialCommand, "nexus"))
                    {
                        yield return item;
                    }
                }

            }
        }

19 Source : NodeCommand.cs
with GNU Affero General Public License v3.0
from arklumpus

public override IEnumerable<(ConsoleTextSpan[], string)> GetCompletions(string partialCommand)
        {
            if (string.IsNullOrWhiteSpace(partialCommand))
            {
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("node ", ConsoleColor.Green), new ConsoleTextSpan("select", ConsoleColor.Yellow) }, "node select ");
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("node ", ConsoleColor.Green), new ConsoleTextSpan("info", ConsoleColor.Yellow) }, "node info ");
            }
            else
            {
                partialCommand = partialCommand.TrimStart();

                StringBuilder firstWordBuilder = new StringBuilder();

                foreach (char c in partialCommand)
                {
                    if (!char.IsWhiteSpace(c))
                    {
                        firstWordBuilder.Append(c);
                    }
                    else
                    {
                        break;
                    }
                }

                string firstWord = firstWordBuilder.ToString();

                if (firstWord.Equals("info", StringComparison.OrdinalIgnoreCase))
                {
                    yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("node ", ConsoleColor.Green), new ConsoleTextSpan("info", ConsoleColor.Yellow) }, "node info ");
                }
                else if (firstWord.Equals("select", StringComparison.OrdinalIgnoreCase))
                {
                    partialCommand = partialCommand.Substring(6).TrimStart().Trim();

                    TreeNode referenceTree = Program.TransformedTree;

                    List<string> names;

                    if (referenceTree != null)
                    {
                        names = referenceTree.GetNodeNames();
                    }
                    else
                    {
                        names = new List<string>();
                    }

                    if (string.IsNullOrWhiteSpace(partialCommand))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("root", ConsoleColor.Yellow) }, "node select root ");
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("#", ConsoleColor.Blue) }, "node select #");
                        foreach (string sr in names)
                        {
                            yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("\"" + sr + "\"", ConsoleColor.Blue) }, "node select \"" + sr + "\" ");
                        }
                    }
                    else if (partialCommand.Contains("\""))
                    {
                        int count = partialCommand.Length - partialCommand.Replace("\"", "").Length;

                        string prevCommand = partialCommand.Substring(0, partialCommand.LastIndexOf("\"") + 1);

                        partialCommand = partialCommand.Substring(partialCommand.LastIndexOf("\"") + 1).TrimStart();

                        if (count % 2 == 0)
                        {
                            if (string.IsNullOrWhiteSpace(partialCommand))
                            {
                                foreach (string sr in names)
                                {
                                    yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("\"" + sr + "\"", ConsoleColor.Blue) }, "node select " + prevCommand + " \"" + sr + "\" ");
                                }
                            }
                            else
                            {
                                yield break;
                            }
                        }
                        else
                        {
                            if (string.IsNullOrWhiteSpace(partialCommand))
                            {
                                foreach (string sr in names)
                                {
                                    yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("\"" + sr + "\"", ConsoleColor.Blue) }, "node select " + prevCommand + sr + "\" ");
                                }
                            }
                            else
                            {
                                foreach (string sr in names)
                                {
                                    if (sr.StartsWith(partialCommand))
                                    {
                                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("\"" + sr + "\"", ConsoleColor.Blue) }, "node select " + prevCommand + sr + "\" ");
                                    }
                                }
                            }
                        }

                    }
                    else
                    {
                        if (partialCommand == "#")
                        {
                            yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("#", ConsoleColor.Blue) }, "node select #");
                        }
                        else if ("root".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                        {
                            yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("root", ConsoleColor.Yellow) }, "node select root ");
                        }

                        yield break;
                    }
                }
                else
                {
                    if ("info".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("node ", ConsoleColor.Green), new ConsoleTextSpan("info", ConsoleColor.Yellow) }, "node info ");
                    }

                    if ("select".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("node ", ConsoleColor.Green), new ConsoleTextSpan("select", ConsoleColor.Yellow) }, "node select ");
                    }
                }
            }
        }

19 Source : PDFCommand.cs
with GNU Affero General Public License v3.0
from arklumpus

public override IEnumerable<(ConsoleTextSpan[], string)> GetCompletions(string partialCommand)
        {
            if (string.IsNullOrWhiteSpace(partialCommand))
            {
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("pdf", ConsoleColor.Green) }, "pdf ");
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("pdf ", ConsoleColor.Green), new ConsoleTextSpan("stdout", ConsoleColor.Yellow) }, "pdf stdout ");

                string[] directories = Directory.GetDirectories(Directory.GetCurrentDirectory(), "*");

                List<(ConsoleTextSpan[], string)> tbr = new List<(ConsoleTextSpan[], string)>();

                foreach (string sr in directories)
                {
                    tbr.Add((new ConsoleTextSpan[]
                    {
                        new ConsoleTextSpan(Path.GetFileName(sr) + " ", ConsoleColor.Blue)
                    }, this.PrimaryCommand + " " + Path.GetFileName(sr) + Path.DirectorySeparatorChar));
                }


                string[] files = Directory.GetFiles(Directory.GetCurrentDirectory(), "*");

                foreach (string sr in files)
                {
                    tbr.Add((new ConsoleTextSpan[]
                    {
                        new ConsoleTextSpan(Path.GetFileName(sr) + " ", ConsoleColor.Red)
                    }, this.PrimaryCommand + " " + Path.GetFileName(sr) + " "));
                }

                tbr.Sort((a, b) => a.Item2.CompareTo(b.Item2));

                foreach ((ConsoleTextSpan[], string) item in tbr)
                {
                    yield return item;
                }
            }
            else
            {
                partialCommand = partialCommand.TrimStart();

                StringBuilder firstWordBuilder = new StringBuilder();

                foreach (char c in partialCommand)
                {
                    if (!char.IsWhiteSpace(c))
                    {
                        firstWordBuilder.Append(c);
                    }
                    else
                    {
                        break;
                    }
                }

                string firstWord = firstWordBuilder.ToString();

                if (firstWord.Equals("stdout", StringComparison.OrdinalIgnoreCase))
                {
                    partialCommand = partialCommand.Substring(4).TrimStart();

                    yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("pdf ", ConsoleColor.Green), new ConsoleTextSpan("stdout", ConsoleColor.Yellow) }, "pdf stdout ");
                }
                else
                {
                    if ("stdout".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("pdf ", ConsoleColor.Green), new ConsoleTextSpan("stdout", ConsoleColor.Yellow) }, "pdf stdout ");
                    }

                    Regex reg = new Regex("^[A-Za-z]:$");
                    if (reg.IsMatch(partialCommand))
                    {
                        partialCommand = partialCommand + "\\";
                    }

                    partialCommand = partialCommand.Trim();
                    string directory = null;

                    directory = Path.GetDirectoryName(partialCommand);


                    if (directory == null)
                    {
                        reg = new Regex("^[A-Za-z]:\\\\$");
                        if (reg.IsMatch(partialCommand))
                        {
                            directory = partialCommand;
                        }
                    }

                    string actualDirectory = directory;

                    if (string.IsNullOrEmpty(actualDirectory))
                    {
                        actualDirectory = Directory.GetCurrentDirectory();
                    }

                    string fileName = Path.GetFileName(partialCommand);

                    string[] directories = Directory.GetDirectories(actualDirectory, fileName + "*");

                    List<(ConsoleTextSpan[], string)> tbr = new List<(ConsoleTextSpan[], string)>();

                    foreach (string sr in directories)
                    {
                        tbr.Add((new ConsoleTextSpan[]
                        {
                        new ConsoleTextSpan(Path.GetFileName(sr) + " ", ConsoleColor.Blue)
                        }, this.PrimaryCommand + " " + Path.Combine(directory, Path.GetFileName(sr)) + Path.DirectorySeparatorChar));
                    }


                    string[] files = Directory.GetFiles(actualDirectory, fileName + "*");

                    foreach (string sr in files)
                    {
                        tbr.Add((new ConsoleTextSpan[]
                        {
                        new ConsoleTextSpan(Path.GetFileName(sr) + " ", ConsoleColor.Red)
                        }, this.PrimaryCommand + " " + Path.Combine(directory, Path.GetFileName(sr)) + " "));
                    }

                    tbr.Sort((a, b) => a.Item2.CompareTo(b.Item2));

                    foreach ((ConsoleTextSpan[], string) item in tbr)
                    {
                        yield return item;
                    }
                }
            }
        }

19 Source : UpdateCommand.cs
with GNU Affero General Public License v3.0
from arklumpus

public override IEnumerable<(ConsoleTextSpan[], string)> GetCompletions(string partialCommand)
        {
            if (string.IsNullOrWhiteSpace(partialCommand))
            {
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("update", ConsoleColor.Green) }, "update ");
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("update ", ConsoleColor.Green), new ConsoleTextSpan("all", ConsoleColor.Yellow) }, "update all ");
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("update ", ConsoleColor.Green), new ConsoleTextSpan("list", ConsoleColor.Yellow) }, "update list ");
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("update ", ConsoleColor.Green), new ConsoleTextSpan("transformer", ConsoleColor.Yellow) }, "update transformer ");
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("update ", ConsoleColor.Green), new ConsoleTextSpan("further transformations", ConsoleColor.Yellow) }, "update further transformations ");
                yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("update ", ConsoleColor.Green), new ConsoleTextSpan("coordinates", ConsoleColor.Yellow) }, "update coordinates ");
            }
            else
            {
                partialCommand = partialCommand.TrimStart();

                StringBuilder firstWordBuilder = new StringBuilder();

                foreach (char c in partialCommand)
                {
                    if (!char.IsWhiteSpace(c))
                    {
                        firstWordBuilder.Append(c);
                    }
                    else
                    {
                        break;
                    }
                }

                string firstWord = firstWordBuilder.ToString();

                if (firstWord.Equals("all", StringComparison.OrdinalIgnoreCase))
                {
                    yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("update ", ConsoleColor.Green), new ConsoleTextSpan("all", ConsoleColor.Yellow) }, "update all ");
                }
                else if (firstWord.Equals("list", StringComparison.OrdinalIgnoreCase))
                {
                    yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("update ", ConsoleColor.Green), new ConsoleTextSpan("list", ConsoleColor.Yellow) }, "update list ");
                }
                else if (firstWord.Equals("transformer", StringComparison.OrdinalIgnoreCase))
                {
                    yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("update ", ConsoleColor.Green), new ConsoleTextSpan("transformer", ConsoleColor.Yellow) }, "update transformer ");
                }
                else if (firstWord.Equals("further transformations", StringComparison.OrdinalIgnoreCase))
                {
                    yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("update ", ConsoleColor.Green), new ConsoleTextSpan("further transformations", ConsoleColor.Yellow) }, "update further transformations ");
                }
                else if (firstWord.Equals("coordinates", StringComparison.OrdinalIgnoreCase))
                {
                    yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("update ", ConsoleColor.Green), new ConsoleTextSpan("coordinates", ConsoleColor.Yellow) }, "update coordinates ");
                }
                else
                {
                    if ("all".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("update ", ConsoleColor.Green), new ConsoleTextSpan("all", ConsoleColor.Yellow) }, "update all ");
                    }

                    if ("list".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("update ", ConsoleColor.Green), new ConsoleTextSpan("all", ConsoleColor.Yellow) }, "update list ");
                    }

                    if ("transformer".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("update ", ConsoleColor.Green), new ConsoleTextSpan("transformer", ConsoleColor.Yellow) }, "update transformer ");
                    }

                    if ("further transformations".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("update ", ConsoleColor.Green), new ConsoleTextSpan("further transformations", ConsoleColor.Yellow) }, "update further transformations ");
                    }

                    if ("coordinates".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("update ", ConsoleColor.Green), new ConsoleTextSpan("coordinates", ConsoleColor.Yellow) }, "update coordinates ");
                    }
                }
            }
        }

See More Examples