remove FossilTui.csproj

This commit is contained in:
ig 2023-02-23 16:04:39 +01:00
parent a0b935b8d2
commit 595bcc203a
7 changed files with 0 additions and 502 deletions

View File

@ -1,10 +0,0 @@
namespace InnovEnergy.FossilTui;
public static class Actions
{
public const String Remove = "Remove";
public const String Revert = "Revert";
public const String Ignore = "Ignore";
public const String Add = "Add ";
public const String CheckIn = "CheckIn";
}

View File

@ -1,48 +0,0 @@
using InnovEnergy.Lib.Utils;
namespace InnovEnergy.FossilTui;
// ReSharper disable once PropertyCanBeMadeInitOnly.Global
public sealed class Change
{
public FossilState State { get; }
public FossilAction SelectedAction { get; private set; } = FossilAction.Ignore;
public String File { get; }
public Change(FossilState state, String file)
{
State = state;
File = file;
}
public Boolean Equals(Change? other)
{
return File == other?.File;
}
public override Int32 GetHashCode()
{
return File.GetHashCode();
}
public FossilAction SelectNextAction(Boolean canCommit)
{
return SelectedAction = State
.AvailableActions
.Unless(a => a == FossilAction.Commit && !canCommit)
.ToList()
.GetNext(SelectedAction);
}
public FossilAction SelectPreviousAction(Boolean canCommit)
{
return SelectedAction = State
.AvailableActions
.Unless(a => a == FossilAction.Commit && !canCommit)
.ToList()
.GetPrevious(SelectedAction);
}
}// ignore me

View File

@ -1,88 +0,0 @@
[
{"id":"id1574","value":"0.000000"},
{"id":"id1462","value":"800.000000"},
{"id":"id1476","value":"3.000000"},
{"id":"id1478","value":"0.000000"},
{"id":"id1492","value":"1.000000"},
{"id":"id57","value":"3232235778.000000"},
{"id":"id58","value":"4294967040.000000"},
{"id":"id59","value":"3232235777.000000"},
{"id":"id2075","value":"0.000000"},
{"id":"id2076","value":"tisoc"},
{"id":"id62","value":"10.000000"},
{"id":"id1489","value":"0.000000"},
{"id":"id1624","value":"0.000000"},
{"id":"id247","value":"1.000000"},
{"id":"id844","value":"0.000000"},
{"id":"id1616","value":"0.000000"},
{"id":"id1757","value":"0.000000"},
{"id":"id1832","value":"48.000000"},
{"id":"id1833","value":"0.000000"},
{"id":"id554","value":"75.000000"},
{"id":"id560","value":"0.000000"},
{"id":"id488","value":"167.000000"},
{"id":"id491","value":"167.000000"},
{"id":"id1255","value":"10.000000"},
{"id":"id1258","value":"50.000000"},
{"id":"id1261","value":"5.000000"},
{"id":"id251","value":"80.000000"},
{"id":"id252","value":"80.000000"},
{"id":"id253","value":"80.000000"},
{"id":"id1937","value":"125.000000"},
{"id":"id1938","value":"125.000000"},
{"id":"id1939","value":"125.000000"},
{"id":"id1994","value":"0.000000"},
{"id":"id1995","value":"0.000000"},
{"id":"id1985","value":"0.000000"},
{"id":"id1986","value":"0.000000"},
{"id":"id1987","value":"0.000000"},
{"id":"id1988","value":"0.000000"},
{"id":"id1989","value":"0.000000"},
{"id":"id1990","value":"0.000000"},
{"id":"id1991","value":"0.000000"},
{"id":"id1992","value":"0.000000"},
{"id":"id1993","value":"0.000000"},
{"id":"id865","value":"195.000000"},
{"id":"id866","value":"305.000000"},
{"id":"id868","value":"48.800000"},
{"id":"id869","value":"50.500000"},
{"id":"id2346","value":"0.000000"},
{"id":"id1782","value":"100.000000"},
{"id":"id1978","value":"2.000000"},
{"id":"id1979","value":"5.000000"},
{"id":"id2013","value":"2.500000"},
{"id":"id2014","value":"-2.500000"},
{"id":"id2015","value":"115.000000"},
{"id":"id2016","value":"85.000000"},
{"id":"id267","value":"1.000000"},
{"id":"id275","value":"2.000000"},
{"id":"id1416","value":"100.000000"},
{"id":"id1460","value":"800.000000"},
{"id":"id1461","value":"0.000000"},
{"id":"id1475","value":"0.000000"},
{"id":"id1367","value":"0.000000"},
{"id":"id1940","value":"1.000000"},
{"id":"id533","value":"9000.000000"},
{"id":"id1625","value":"0.000000"},
{"id":"id1626","value":"850.000000"},
{"id":"id1627","value":"40.000000"},
{"id":"id1628","value":"40.000000"},
{"id":"id1629","value":"0.000000"},
{"id":"id1936","value":"10.000000"},
{"id":"id1420","value":"100.000000"},
{"id":"id1368","value":"900.000000"},
{"id":"id1369","value":"880.000000"},
{"id":"id1370","value":"920.000000"},
{"id":"id235","value":"850.000000"},
{"id":"id273","value":"830.000000"},
{"id":"id274","value":"870.000000"},
{"id":"id2034","value":"950.000000"},
{"id":"id2035","value":"915.000000"},
{"id":"id2036","value":"885.000000"},
{"id":"id2037","value":"850.000000"},
{"id":"id2038","value":"930.000000"},
{"id":"id2039","value":"870.000000"},
{"id":"id2040","value":"830.000000"},
{"id":"id2041","value":"750.000000"},
{"id":"id2042","value":"77.000000"}
]

View File

@ -1,16 +0,0 @@
using System.Diagnostics.CodeAnalysis;
namespace InnovEnergy.FossilTui;
[SuppressMessage("ReSharper", "IdentifierTypo")]
public enum FossilAction
{
Revert,
Ignore,
Add,
Commit,
Delete
}

View File

@ -1,42 +0,0 @@
using static InnovEnergy.FossilTui.FossilAction;
namespace InnovEnergy.FossilTui;
public record FossilState
{
public String Name { get; }
public ConsoleColor Color { get; }
public IReadOnlyList<FossilAction> AvailableActions { get; }
public static FossilState Parse(String state) => States.Single(s => s.Name == state);
public static readonly FossilState Missing = new("MISSING" , ConsoleColor.Red, new[] { Ignore, Revert });
public static readonly FossilState Deleted = new("DELETED" , ConsoleColor.DarkRed, new[] { Ignore, Commit, Revert });
public static readonly FossilState Added = new("ADDED" , ConsoleColor.DarkGreen, new[] { Ignore, Commit, Delete });
public static readonly FossilState Edited = new("EDITED" , ConsoleColor.Yellow, new[] { Ignore, Commit, Delete }); // Revert will bring it back to not edited
public static readonly FossilState Extra = new("EXTRA" , ConsoleColor.Green, new[] { Ignore, Add, Delete});
//public static readonly FossilState Unchanged = new("UNCHANGED", ConsoleColor.DarkGray, new[] { Ignore, Commit, Revert });
private static readonly IReadOnlyList<FossilState> States = new[]
{
Missing,
Deleted,
Added,
Edited,
Extra,
// Unchanged,
};
private FossilState(String name, ConsoleColor color, IReadOnlyList<FossilAction> availableActions)
{
Name = name;
Color = color;
AvailableActions = availableActions;
}
public override String ToString() => Name;
}

View File

@ -1,15 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../InnovEnergy.app.props" />
<PropertyGroup>
<RootNamespace>InnovEnergy.FossilTui</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../../lib/Utils/Utils.csproj" />
<ProjectReference Include="../../lib/Time/Time.csproj" />
<PackageReference Include="CliWrap" Version="3.5.0" />
</ItemGroup>
</Project>

View File

@ -1,283 +0,0 @@
using CliWrap;
using CliWrap.Buffered;
using InnovEnergy.Lib.Utils;
namespace InnovEnergy.FossilTui;
public static class Program
{
private static readonly Command Fossil = Cli.Wrap("fossil");
public static async Task Main()
{
Console.CancelKeyPress += (_, _) => "aborted".WriteLine();
while (true)
{
var needsUpdate = await NeedsUpdate();
var changes = await GetChanges();
var status = await GetStatus();
if (!changes.Any())
{
Console.Clear();
status.WriteLine(Environment.NewLine);
"No Changes".WriteLine(ConsoleColor.Green);
return;
}
var selectedChange = changes.First();
while (true)
{
Console.Clear();
status.WriteLine(Environment.NewLine);
if (needsUpdate)
{
"Update available for your branch".WriteLine(ConsoleColor.Red);
"Press U to Update".WriteLine(Environment.NewLine);
}
ShowChanges(changes, selectedChange);
var key = Console.ReadKey().Key;
if (key == ConsoleKey.DownArrow)
{
selectedChange = changes.GetNext(selectedChange);
}
else if (key == ConsoleKey.UpArrow)
{
selectedChange = changes.GetPrevious(selectedChange);
}
else if (key == ConsoleKey.RightArrow)
{
selectedChange.SelectNextAction(!needsUpdate);
}
else if (key == ConsoleKey.LeftArrow)
{
selectedChange.SelectPreviousAction(!needsUpdate);
}
else if (key == ConsoleKey.D && selectedChange.State == FossilState.Edited)
{
var fossilGetDiff = Fossil.WithArguments("gdiff " + selectedChange.File);
await fossilGetDiff.ExecuteBufferedAsync();
}
else if (key == ConsoleKey.U)
{
await FossilUpdate();
break;
}
else if (key == ConsoleKey.Spacebar)
{
//
}
else if (key == ConsoleKey.Escape)
{
Console.Clear();
return;
}
else if (key == ConsoleKey.Enter)
{
await ApplyActions(changes, needsUpdate);
break;
}
Console.Clear();
}
}
}
private static async Task<IReadOnlyList<Change>> GetChanges()
{
var result = await Fossil
.WithArguments("changes --differ")
.ExecuteBufferedAsync();
return result
.StandardOutput
.SplitLines()
.Unless(String.IsNullOrWhiteSpace)
//.Unless(f => f.Contains("FossilTui")) // TODO: remove
.Select(l => l.Split(' ', StringSplitOptions.RemoveEmptyEntries))
.Select(t => new Change(FossilState.Parse(t[0]), t[1]))
.ToList();
}
private static async Task<String> GetStatus()
{
var statusResult = await Fossil
.WithArguments("status")
.ExecuteBufferedAsync();
return statusResult
.StandardOutput
.SplitLines()
.Unless(String.IsNullOrWhiteSpace)
.Where(l => l[0] is >= 'a' and <= 'z')
.JoinNonEmptyLines();
}
private static async Task FossilUpdate()
{
var result = await Fossil
.WithArguments("update")
.WithValidation(CommandResultValidation.None)
.ExecuteBufferedAsync();
if (result.ExitCode != 0)
{
Console.WriteLine(result.StandardOutput);
Console.WriteLine(result.StandardError);
}
}
private static async Task ApplyActions(IReadOnlyList<Change> changes, Boolean needsUpdate)
{
await DeleteFiles(changes);
await AddFiles(changes); // must run before CommitFiles
await RevertFiles(changes);
await CommitFiles(changes, needsUpdate);
}
private static async Task CommitFiles(IReadOnlyList<Change> changes, Boolean needsUpdate)
{
var filesToCheckIn = changes.GetFilesWithAction(FossilAction.Commit);
if (!filesToCheckIn.Any())
return;
if (needsUpdate)
{
"Would fork".WriteLine(ConsoleColor.Red);
"Not committing selected files".WriteLine();
"Please update first".WriteLine();
}
else
{
var msg = RequestCommitMessage().Quote();
var files = filesToCheckIn.JoinWith(" ");
var result = await Fossil
.WithArguments($"ci -m {msg} {files}")
.ExecuteBufferedAsync();
if (result.ExitCode != 0)
{
Console.WriteLine(result.StandardOutput);
Console.WriteLine(result.StandardError);
}
}
}
private static String RequestCommitMessage()
{
while(true)
{
Console.WriteLine("Write your Commit message:");
var msg = Console.ReadLine();
if (msg.IsNullOrWhiteSpace())
continue;
return msg!;
}
}
private static async Task RevertFiles(IReadOnlyList<Change> changes)
{
var filesToRevert = changes.GetFilesWithAction(FossilAction.Revert);
if (!filesToRevert.Any())
return;
var args = filesToRevert.Aggregate("revert", (a, b) => a + " " + b);
var result = await Fossil.WithArguments(args).ExecuteBufferedAsync();
if (result.ExitCode != 0)
{
Console.WriteLine(result.StandardOutput);
Console.WriteLine(result.StandardError);
}
}
private static async Task AddFiles(IReadOnlyList<Change> changes)
{
var args = changes
.Where(c => c.SelectedAction == FossilAction.Add)
.Select(c => c.File)
.Aggregate("add", (a, b) => a + " " + b);
var result = await Fossil.WithArguments(args).ExecuteBufferedAsync();
if (result.ExitCode != 0)
{
Console.WriteLine(result.StandardOutput);
Console.WriteLine(result.StandardError);
}
}
private static async Task DeleteFiles(IReadOnlyCollection<Change> changes)
{
foreach (var file in changes.GetFilesWithAction(FossilAction.Delete))
{
var result = await Fossil.WithArguments($"rm {file}").WithValidation(CommandResultValidation.None).ExecuteBufferedAsync();
if (result.ExitCode != 0)
{
Console.WriteLine(result.StandardOutput);
Console.WriteLine(result.StandardError);
}
try
{
File.Delete(file);
}
catch (Exception e)
{
Console.WriteLine($"Failed to delete file {file}");
Console.WriteLine(e);
}
}
}
private static IReadOnlyList<String> GetFilesWithAction(this IEnumerable<Change> changes, FossilAction fossilAction)
{
return changes
.Where(c => c.SelectedAction == fossilAction)
.Select(c => c.File)
.ToList();
}
private static void ShowChanges(IReadOnlyList<Change> changes, Change selectedChange)
{
foreach (var change in changes)
{
const ConsoleColor bg = ConsoleColor.Black;
const ConsoleColor fg = ConsoleColor.Gray;
var state = change.State;
var stateFgColor = state.Color;
var selected = change.File == selectedChange.File;
state.Name.PadRight(10).Write(stateFgColor, bg, selected);
change.SelectedAction.ToString().PadRight(10).Write(fg, bg, selected);
change.File.Write(fg, bg, selected);
Console.WriteLine();
}
}
private static async Task<Boolean> NeedsUpdate()
{
var result = await Fossil
.WithArguments("update -n")
.ExecuteBufferedAsync();
return result
.StandardOutput
.SplitLines()
.Any(l => l.StartsWith("updated-to"));
}
}