/// <summary> /// Shows the peek preview of available completions. /// </summary> public void Peek() { if (!Matching.Any()) { return; } OriginX = Console.CursorLeft; OriginY = Console.CursorTop; var peek = Matching.Length < PeekMax ? Matching : Matching.Take(PeekMax).Concat(new[] { "..." }); var itemWidth = peek.Select(i => i.Length).Max() + 2; var windowWidth = Console.WindowWidth; while (windowWidth % itemWidth > 0) { itemWidth++; } Console.CursorVisible = false; Console.CursorLeft = 0; Console.CursorTop++; Peek1 = Console.CursorTop; var foregroundCurrent = Console.ForegroundColor; Console.ForegroundColor = PeekColor; foreach (var item in peek) { Console.Write(item.PadRight(itemWidth)); } Console.ForegroundColor = foregroundCurrent; Peek2 = Console.CursorTop; Console.SetCursorPosition(OriginX, OriginY); Console.CursorVisible = true; }
public NeuralGenomeCmpInfo(NeuralGenome target1, NeuralGenome target2) { var excessPoint = Math.Min( target1.NeuralGenes.Max(ng => ng.Synapse.InnovationNb), target2.NeuralGenes.Max(ng => ng.Synapse.InnovationNb) ); var groups = target1.NeuralGenes .Concat(target2.NeuralGenes) .GroupBy(ng => ng.Synapse.InnovationNb); Matching = groups.Where(x => x.Count() == 2) .Select(x => new Tuple <NeuralGene, NeuralGene>( x.First(), x.Last()) ); Disjoint = groups.Where(x => x.Count() == 1 && x.First().Synapse.InnovationNb <= excessPoint) .SelectMany(x => x); Excess = groups.Where(x => x.Count() == 1 && x.First().Synapse.InnovationNb > excessPoint) .SelectMany(x => x); Debug.Assert(Matching.Any(x => !target1.NeuralGenes.Contains(x.Item1) || !target2.NeuralGenes.Contains(x.Item2))); }
/// <summary> /// Gets the next matching auto complete item. /// </summary> /// <returns>Matching item or null.</returns> public string Next() { if (!Matching.Any()) { return(null); } if (CurrentIndex >= Matching.Length || CurrentIndex < 0) { CurrentIndex = 0; } return(MatchingPath == null ? Matching[CurrentIndex++] : Path.Combine(MatchingPath, Matching[CurrentIndex++])); }
/// <summary> /// Filters the list by the matching start string. /// </summary> /// <param name="start">Common start for the completions.</param> /// <param name="includeCommands">Set true to include internal commands.</param> /// <returns>Offset where the completion match or -1 when nothing matches.</returns> public int Match(string start, bool includeCommands = false) { MatchingPath = null; if (String.IsNullOrWhiteSpace(start)) { Reload(".", includeCommands); Matching = All; return(0); } start = CommandLine.Unquote(start); var lastSlashIndex = start.LastIndexOf(Path.DirectorySeparatorChar); if (lastSlashIndex >= 0) { var path = start.Substring(0, lastSlashIndex + 1); start = start.Substring(lastSlashIndex + 1); Reload(MatchingPath = path); Matching = String.IsNullOrEmpty(start) ? All : All.Where(i => i.StartsWith(start, StringComparison.OrdinalIgnoreCase)).ToArray(); return(lastSlashIndex + 1); } Reload(".", includeCommands); Matching = All.Where(i => i.StartsWith(start, StringComparison.OrdinalIgnoreCase)).ToArray(); return(Matching.Any() ? 0 : -1); }