ProcessTable.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using Terminal.Gui;
  5. using System.Linq;
  6. using System.Globalization;
  7. using static Terminal.Gui.TableView;
  8. using System.Diagnostics;
  9. namespace UICatalog.Scenarios {
  10. [ScenarioMetadata (Name: "ProcessTable", Description: "Demonstrates TableView with the currently running processes.")]
  11. [ScenarioCategory ("TableView")]
  12. public class ProcessTable : Scenario {
  13. TableView tableView;
  14. public override void Setup ()
  15. {
  16. Win.Title = this.GetName ();
  17. Win.Y = 1; // menu
  18. Win.Height = Dim.Fill (1); // status bar
  19. this.tableView = new TableView () {
  20. X = 0,
  21. Y = 0,
  22. Width = Dim.Fill (),
  23. Height = Dim.Fill (1),
  24. };
  25. // First time
  26. CreateProcessTable ();
  27. // Then every second
  28. Application.AddTimeout (TimeSpan.FromSeconds (1),
  29. () => {
  30. CreateProcessTable ();
  31. return true;
  32. });
  33. Win.Add (tableView);
  34. }
  35. private void CreateProcessTable ()
  36. {
  37. var ro = tableView.RowOffset;
  38. var co = tableView.ColumnOffset;
  39. tableView.Table = new EnumerableTableSource<Process> (Process.GetProcesses (),
  40. new Dictionary<string, Func<Process, object>>() {
  41. { "ID",(p)=>p.Id},
  42. { "Name",(p)=>p.ProcessName},
  43. { "Threads",(p)=>p.Threads.Count},
  44. { "Virtual Memory",(p)=>p.VirtualMemorySize64},
  45. { "Working Memory",(p)=>p.WorkingSet64},
  46. });
  47. tableView.RowOffset = ro;
  48. tableView.ColumnOffset = co;
  49. tableView.EnsureValidScrollOffsets ();
  50. }
  51. }
  52. }