public override void Render(View view, int lineIndex) { var line = GetLine(view, lineIndex); if (line == null) return; var foregroundColor = GetForegroundColor(view, lineIndex); var backgroundColor = GetBackgroundColor(view, lineIndex); RenderLine(view, lineIndex, line.Text, foregroundColor, backgroundColor); }
private static ConsoleColor GetBackgroundColor(View view, int lineIndex) { var patchLine = GetLine(view, lineIndex); if (patchLine == null) return Console.BackgroundColor; var kind = patchLine.Kind; var isSelected = view.SelectedLine == lineIndex; if (isSelected) { return kind.IsAdditionOrRemoval() ? ConsoleColor.Gray : ConsoleColor.DarkGray; } return Console.BackgroundColor; }
private static ConsoleColor GetForegroundColor(View view, int lineIndex) { var line = GetLine(view, lineIndex); if (line == null) return Console.ForegroundColor; switch (line.Kind) { case PatchLineKind.Header: return ConsoleColor.White; case PatchLineKind.Hunk: return ConsoleColor.DarkCyan; case PatchLineKind.Context: goto default; case PatchLineKind.Addition: return ConsoleColor.DarkGreen; case PatchLineKind.Removal: return ConsoleColor.DarkRed; default: return Console.ForegroundColor; } }
protected void RenderLine(View view, int lineIndex, string line, ConsoleColor foregroundColor, ConsoleColor backgroundColor) { var textStart = Math.Min(view.LeftChar, line.Length); var textLength = Math.Max(Math.Min(view.Width, line.Length - view.LeftChar), 0); var text = textLength < 0 ? string.Empty : line.ToVisual(view.VisibleWhitespace).Substring(textStart, textLength); var oldForeground = Console.ForegroundColor; var oldBackgorund = Console.BackgroundColor; Console.ForegroundColor = foregroundColor; Console.BackgroundColor = backgroundColor; var visualLine = lineIndex - view.TopLine + view.Top; Console.SetCursorPosition(view.Left, visualLine); Console.Write(text); var remaining = view.Width - textLength; if (remaining > 0) Console.Write(_blankRow, 0, remaining); Console.ForegroundColor = oldForeground; Console.BackgroundColor = oldBackgorund; }
private void InitializeScreen() { var oldView = _view; _header = new Label(0, 0, Console.WindowWidth); _header.Foreground = ConsoleColor.Yellow; _header.Background = ConsoleColor.DarkGray; var renderer = new PatchDocumentLineRenderer(); _view = new View(renderer, 1, 0, Console.WindowHeight - 2, Console.WindowWidth); _view.SelectedLineChanged += delegate { UpdateHeader(); }; _footer = new Label(Console.WindowHeight - 2, 0, Console.WindowWidth); _footer.Foreground = ConsoleColor.Yellow; _footer.Background = ConsoleColor.DarkGray; UpdateRepository(); if (oldView != null) { _view.VisibleWhitespace = oldView.VisibleWhitespace; _view.SelectedLine = oldView.SelectedLine; _view.BringIntoView(_view.SelectedLine); } }
private static PatchLine GetLine(View view, int lineIndex) { var document = view.Document as PatchDocument; return document?.Lines[lineIndex]; }
public abstract void Render(View view, int lineIndex);