2
0

Status.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. namespace TodoList
  7. {
  8. [Command(
  9. Name: "status",
  10. ShortDescription: "Summarize todo list.",
  11. ErrorText: "",
  12. LongHelpText: "Displays task counts in each category.",
  13. Synonyms: "stat stats"
  14. )]
  15. internal class Status : ICommand
  16. {
  17. [SwitchDocumentation("Path to task file.")]
  18. public string file = "todo.txt";
  19. public void Invoke(Dictionary<String, Object> PipedArguments)
  20. {
  21. if (String.IsNullOrEmpty(file))
  22. {
  23. Console.WriteLine("No file specified. How did you manage that? It defaults to todo.txt");
  24. return;
  25. }
  26. var list = EntryList.LoadFile(file, false);
  27. var statusHash = new Dictionary<String, int>();
  28. foreach (var task in list.Root.EnumerateTree())
  29. if (statusHash.ContainsKey(task.Status))
  30. statusHash[task.Status] += 1;
  31. else
  32. statusHash.Add(task.Status, 1);
  33. var total = statusHash.Values.Sum();
  34. Presentation.FillBar();
  35. Console.BackgroundColor = ConsoleColor.Black;
  36. Console.ForegroundColor = ConsoleColor.DarkGreen;
  37. foreach (var tag in statusHash)
  38. {
  39. Presentation.FillLine();
  40. Console.WriteLine(String.Format("{0,5} {1} {2:00.00}%", tag.Value, tag.Key, ((float)tag.Value / (float)total * 100.0f)));
  41. }
  42. Presentation.FillLine();
  43. Console.WriteLine(String.Format("{0,5} Total Tasks", total));
  44. Presentation.FillBar();
  45. Console.ResetColor();
  46. }
  47. }
  48. }