ProcessTable.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. Application.Top.LayoutSubviews ();
  20. this.tableView = new TableView () {
  21. X = 0,
  22. Y = 0,
  23. Width = Dim.Fill (),
  24. Height = Dim.Fill (1),
  25. };
  26. // First time
  27. CreateProcessTable ();
  28. // Then every second
  29. Application.MainLoop.AddTimeout (TimeSpan.FromSeconds (1),
  30. (s) => {
  31. CreateProcessTable ();
  32. return true;
  33. });
  34. Win.Add (tableView);
  35. }
  36. private void CreateProcessTable ()
  37. {
  38. var ro = tableView.RowOffset;
  39. var co = tableView.ColumnOffset;
  40. tableView.Table = new EnumerableTableSource<Process> (Process.GetProcesses (),
  41. new Dictionary<string, Func<Process, object>>() {
  42. { "ID",(p)=>p.Id},
  43. { "Name",(p)=>p.ProcessName},
  44. { "Threads",(p)=>p.Threads.Count},
  45. { "Virtual Memory",(p)=>p.VirtualMemorySize64},
  46. { "Working Memory",(p)=>p.WorkingSet64},
  47. });
  48. tableView.RowOffset = ro;
  49. tableView.ColumnOffset = co;
  50. tableView.EnsureValidScrollOffsets ();
  51. }
  52. }
  53. }