public LineText(string text, int lineNumber, TypeOfLine lineType) { Text = text; LineNumber = lineNumber; LineType = lineType; }
/// <summary> /// Generates a box. /// </summary> /// <param name="pType">Type of line.</param> /// <param name="pPosX">Top position.</param> /// <param name="pPosY">Left position.</param> /// <param name="pWidth">Width.</param> /// <param name="pHeight">Height.</param> internal static void GenerateBox(Core.Layer pLayer, TypeOfLine pType, int pPosX, int pPosY, int pWidth, int pHeight) { // Minimum value must be at least 2 pWidth = pWidth < 2 ? 1 : pWidth - 2; pHeight = pHeight < 2 ? 1 : pHeight - 1; // Verify that values are within bounds if (pPosX < 0) { pPosX = 0; } if (pPosX + pWidth > ConsoleTools.BufferWidth) { pPosX = ConsoleTools.BufferWidth - pWidth; } if (pPosY < 0) { pPosY = 0; } if (pPosY + pHeight > ConsoleTools.BufferWidth) { pPosY = ConsoleTools.BufferWidth - pHeight; } // Default is single lines char CornerTLChar = Graphics.Lines.SingleCorner[0]; // Top Left char CornerTRChar = Graphics.Lines.SingleCorner[1]; // Top Right char CornerBLChar = Graphics.Lines.SingleCorner[3]; // Bottom Left char CornerBRChar = Graphics.Lines.SingleCorner[2]; // Bottom Right char HorizontalChar = Graphics.Lines.Single[1]; // Horizontal char VerticalChar = Graphics.Lines.Single[0]; // Vertical switch (pType) { case TypeOfLine.Double: CornerTLChar = Graphics.Lines.DoubleCorner[0]; CornerTRChar = Graphics.Lines.DoubleCorner[1]; CornerBLChar = Graphics.Lines.DoubleCorner[3]; CornerBRChar = Graphics.Lines.DoubleCorner[2]; HorizontalChar = Graphics.Lines.Double[1]; VerticalChar = Graphics.Lines.Double[0]; break; } // Top wall Core.Write(pLayer, CornerTLChar, pPosX, pPosY); ConsoleTools.GenerateHorizontalLine(pLayer, HorizontalChar, pWidth); Core.Write(pLayer, CornerTRChar); // Side walls Console.SetCursorPosition(pPosX, pPosY + 1); ConsoleTools.GenerateVerticalLine(pLayer, VerticalChar, pHeight); Console.SetCursorPosition(pPosX + pWidth + 1, pPosY + 1); ConsoleTools.GenerateVerticalLine(pLayer, VerticalChar, pHeight); // Bottom wall Console.SetCursorPosition(pPosX, pPosY + pHeight); Core.Write(pLayer, CornerBLChar); ConsoleTools.GenerateHorizontalLine(pLayer, HorizontalChar, pWidth); Core.Write(pLayer, CornerBRChar); }
/// <summary> /// Perform 3-way merge /// </summary> /// <returns>Merged text.</returns> /// <param name="merge"></param> /// <param name="prevGenLines">Previously generated version ie: 'base version'.</param> /// <param name="userLines">User-modified version of 'base'.</param> /// <param name="nextGenLines">Latest generated version of 'base'.</param> internal static string GetMergedOutput(SlyceMergeResult merge, string[] prevGenLines, string[] userLines, string[] nextGenLines) { // default values and initialisation merge.DiffType = TypeOfDiff.ExactCopy; merge.Lines = new List <LineText>(200); string output = ""; int lineCounter = -1; const string pilcrowString = "¶"; const char pilcrow = '¶'; // diff the User version and LatestGenerated version against the PrevGenerated version IList res = Merge.MergeLists(prevGenLines, new[] { userLines, nextGenLines }); // handle empty input if (res.Count == 1 && res[0].Equals(string.Empty)) { return(string.Empty); } string conflictTypeName = typeof(Merge.Conflict).FullName; // process each line from the diff foreach (object line in res) { lineCounter++; string lineTypeName = line.GetType().ToString(); if (lineTypeName == "System.String") { string thisLine = (string)line; merge.Lines.Add(new LineText(thisLine.Replace(pilcrowString, ""), lineCounter, TypeOfLine.Normal)); } else if (lineTypeName == conflictTypeName) { Merge.Conflict conf = (Merge.Conflict)line; Range[] ranges = conf.Ranges; Range rangeUser = ranges[0]; Range rangeNewGen = ranges[1]; string[] conflictUserLines = GetLinesFromRange(userLines, rangeUser); string[] conflictNewGenLines = GetLinesFromRange(nextGenLines, rangeNewGen); // Get diff of the conflicts Diff diff = new Diff(conflictUserLines, conflictNewGenLines, true, false); foreach (Diff.Hunk hunk in diff) { if (hunk.Same) { string same = GetPortionOfString(conflictUserLines, hunk.Left.Start, hunk.Left.End); same = RemoveTrailingCharacter(pilcrowString, same); same = same.Replace(pilcrowString, "\r\n"); output += same; merge.Lines.Add(new LineText(same, lineCounter, TypeOfLine.Normal)); } else { // Get the user modified lines string userPortion = GetPortionOfString(conflictUserLines, hunk.Left.Start, hunk.Left.End); userPortion = RemoveTrailingCharacter(pilcrowString, userPortion); // Get the newly generated lines string newGenPortion = GetPortionOfString(conflictNewGenLines, hunk.Right.Start, hunk.Right.End); newGenPortion = RemoveTrailingCharacter(pilcrowString, newGenPortion); merge.SetDiffType(TypeOfDiff.Conflict); TypeOfLine lineType = newGenPortion.Length > 0 ? TypeOfLine.User : TypeOfLine.Normal; string[] userSplitLines = userPortion.Split(pilcrow); if (userPortion.Length > 0) { merge.Lines.Add(new LineText(userSplitLines[0], lineCounter, lineType)); } for (int myCount = 1; myCount < userSplitLines.Length; myCount++) { lineCounter++; merge.Lines.Add(new LineText(userSplitLines[myCount], lineCounter, lineType)); } lineType = userPortion.Length > 0 ? TypeOfLine.NewGen : TypeOfLine.Normal; string[] newGenSplitLines = newGenPortion.Split(pilcrow); if (newGenPortion.Length > 0) { merge.Lines.Add(new LineText(newGenSplitLines[0], lineCounter, lineType)); } for (int myCount = 1; myCount < newGenSplitLines.Length; myCount++) { lineCounter++; merge.Lines.Add(new LineText(newGenSplitLines[myCount], lineCounter, lineType)); } } } } else { throw new Exception(string.Format("Unexpected line type: {0}\nText1:{1}\n\nText2:{2}\n\nText3:{3}", line.GetType(), prevGenLines, userLines, nextGenLines)); } } return(output); }