diff --git a/src/Task.Monitor.System/Controls/ListView/ListView.ViewPort.cs b/src/Task.Monitor.System/Controls/ListView/ListView.ViewPort.cs index 9656b32..963ab2f 100644 --- a/src/Task.Monitor.System/Controls/ListView/ListView.ViewPort.cs +++ b/src/Task.Monitor.System/Controls/ListView/ListView.ViewPort.cs @@ -4,7 +4,7 @@ namespace Task.Monitor.System.Controls.ListView; public sealed class ViewPort { - public int CurrentIndex { get; set; } + public int CurrentPageIndex { get; set; } public int SelectedIndex { get; set; } public int PreviousSelectedIndex { get; set; } public int RowCount { get; set; } @@ -12,7 +12,7 @@ public sealed class ViewPort public void Reset() { - CurrentIndex = 0; + CurrentPageIndex = 0; SelectedIndex = 0; PreviousSelectedIndex = 0; RowCount = 0; diff --git a/src/Task.Monitor.System/Controls/ListView/ListView.cs b/src/Task.Monitor.System/Controls/ListView/ListView.cs index 3c486fa..7b84fb0 100644 --- a/src/Task.Monitor.System/Controls/ListView/ListView.cs +++ b/src/Task.Monitor.System/Controls/ListView/ListView.cs @@ -1,4 +1,4 @@ -using System.Drawing; +using System.Drawing; using Task.Monitor.Cli.Utils; namespace Task.Monitor.System.Controls.ListView; @@ -52,6 +52,16 @@ private void CalculateViewPortBounds() : Y; viewPort.Bounds = new Rectangle(X, y, Width, Height); + + if (viewPort.SelectedIndex >= items.Count) { + viewPort.SelectedIndex = items.Count - 1; + } + if (viewPort.PreviousSelectedIndex >= items.Count) { + viewPort.PreviousSelectedIndex = items.Count - 1; + } + if (viewPort.CurrentPageIndex > Math.Max(0, items.Count - viewPort.RowCount)) { + viewPort.CurrentPageIndex = Math.Max(0, items.Count - viewPort.RowCount); + } } internal void ClearColumnHeaders() => columnHeaders.Clear(); @@ -82,9 +92,9 @@ private void DoScroll(ConsoleKey consoleKey, out bool redrawAllItems) viewPort.PreviousSelectedIndex = viewPort.SelectedIndex; viewPort.SelectedIndex++; - if (viewPort.SelectedIndex - viewPort.CurrentIndex >= viewPort.RowCount) { - if (viewPort.CurrentIndex <= items.Count - viewPort.Bounds.Height + 1) { - viewPort.CurrentIndex++; + if (viewPort.SelectedIndex - viewPort.CurrentPageIndex >= viewPort.RowCount) { + if (viewPort.CurrentPageIndex <= items.Count - viewPort.Bounds.Height + 1) { + viewPort.CurrentPageIndex++; redrawAllItems = true; } } @@ -96,8 +106,8 @@ private void DoScroll(ConsoleKey consoleKey, out bool redrawAllItems) viewPort.PreviousSelectedIndex = viewPort.SelectedIndex; viewPort.SelectedIndex--; - if (viewPort.SelectedIndex <= viewPort.CurrentIndex - 1 && viewPort.CurrentIndex != 0) { - viewPort.CurrentIndex--; + if (viewPort.SelectedIndex <= viewPort.CurrentPageIndex - 1 && viewPort.CurrentPageIndex != 0) { + viewPort.CurrentPageIndex--; redrawAllItems = true; } } @@ -115,8 +125,8 @@ private void DoScroll(ConsoleKey consoleKey, out bool redrawAllItems) viewPort.SelectedIndex = items.Count - 1; } - if (viewPort.SelectedIndex - viewPort.CurrentIndex >= viewPort.RowCount) { - viewPort.CurrentIndex = Math.Min(items.Count - viewPort.RowCount, viewPort.SelectedIndex); + if (viewPort.SelectedIndex - viewPort.CurrentPageIndex >= viewPort.RowCount) { + viewPort.CurrentPageIndex = Math.Min(items.Count - viewPort.RowCount, viewPort.SelectedIndex - viewPort.RowCount + 1); redrawAllItems = true; } } @@ -133,8 +143,8 @@ private void DoScroll(ConsoleKey consoleKey, out bool redrawAllItems) viewPort.SelectedIndex = 0; } - if (viewPort.SelectedIndex <= viewPort.CurrentIndex - 1 && viewPort.CurrentIndex != 0) { - viewPort.CurrentIndex = Math.Max(0, viewPort.SelectedIndex); + if (viewPort.SelectedIndex <= viewPort.CurrentPageIndex - 1 && viewPort.CurrentPageIndex != 0) { + viewPort.CurrentPageIndex = Math.Max(0, viewPort.SelectedIndex); redrawAllItems = true; } } @@ -320,11 +330,11 @@ private void DrawItems() int n = 0; for (int i = 0; i < viewPort.RowCount; i++) { - int pid = i + viewPort.CurrentIndex; + int pos = i + viewPort.CurrentPageIndex; - if (pid < ItemCount) { - ListViewItem item = Items[pid]; - DrawItem(item, viewPort.Bounds.Y + n, highlight: pid == viewPort.SelectedIndex); + if (pos < ItemCount) { + ListViewItem item = Items[pos]; + DrawItem(item, viewPort.Bounds.Y + n, highlight: pos == viewPort.SelectedIndex); n++; } } @@ -431,9 +441,8 @@ internal void InsertItems(ListViewItem[] items) protected override void OnDraw() { FrameClear(); - CalculateViewPortBounds(); - + if (ShowColumnHeaders) { DrawHeader(); } @@ -521,16 +530,17 @@ private void RedrawItem() frame.Clear(); ListViewItem selectedItem = items[viewPort.SelectedIndex]; + DrawItem( selectedItem, - viewPort.Bounds.Y + viewPort.SelectedIndex - viewPort.CurrentIndex, + viewPort.Bounds.Y + viewPort.SelectedIndex - viewPort.CurrentPageIndex, highlight: true); if (viewPort.PreviousSelectedIndex != viewPort.SelectedIndex) { ListViewItem previousSelectedItem = items[viewPort.PreviousSelectedIndex]; DrawItem( previousSelectedItem, - viewPort.Bounds.Y + viewPort.PreviousSelectedIndex - viewPort.CurrentIndex, + viewPort.Bounds.Y + viewPort.PreviousSelectedIndex - viewPort.CurrentPageIndex, highlight: false); } diff --git a/src/taskmon/Assets/Themes/Ayu.theme b/src/taskmon/Assets/Themes/Ayu.theme index 2688ef5..deec2a9 100644 --- a/src/taskmon/Assets/Themes/Ayu.theme +++ b/src/taskmon/Assets/Themes/Ayu.theme @@ -6,7 +6,7 @@ background-highlight=#3b5070 col-cmd-normal-user-space=#59a6e0 col-cmd-low-priority=#0000FF -col-cmd-high-cpu=#000000 +col-cmd-high-cpu=#ffa759 col-cmd-io-bound=#2b7489 col-cmd-script=#e3b341 col-user-current-non-root=#95e6cb diff --git a/src/taskmon/Assets/Themes/Catppuccin.theme b/src/taskmon/Assets/Themes/Catppuccin.theme index 952e56e..ee3e1ef 100644 --- a/src/taskmon/Assets/Themes/Catppuccin.theme +++ b/src/taskmon/Assets/Themes/Catppuccin.theme @@ -6,7 +6,7 @@ background-highlight=#3b5070 col-cmd-normal-user-space=#89b4fa col-cmd-low-priority=#0000FF -col-cmd-high-cpu=#000000 +col-cmd-high-cpu=#cba6f7 col-cmd-io-bound=#2b7489 col-cmd-script=#e3b341 col-user-current-non-root=#cdd6f4 diff --git a/src/taskmon/Assets/Themes/Cobalt2.theme b/src/taskmon/Assets/Themes/Cobalt2.theme index 1f62bb7..97938ec 100644 --- a/src/taskmon/Assets/Themes/Cobalt2.theme +++ b/src/taskmon/Assets/Themes/Cobalt2.theme @@ -6,7 +6,7 @@ background-highlight=#0050A4 col-cmd-normal-user-space=#a5ff90 col-cmd-low-priority=#ff628c -col-cmd-high-cpu=#e1efff +col-cmd-high-cpu=#ba55d3 col-cmd-io-bound=#e1efff col-cmd-script=#80ffbb col-user-current-non-root=#0088ff diff --git a/src/taskmon/Assets/Themes/Dracula Official.theme b/src/taskmon/Assets/Themes/Dracula Official.theme index 5da1ce2..10e040d 100644 --- a/src/taskmon/Assets/Themes/Dracula Official.theme +++ b/src/taskmon/Assets/Themes/Dracula Official.theme @@ -6,7 +6,7 @@ background-highlight=#3b5070 col-cmd-normal-user-space=#50fa7b col-cmd-low-priority=#0000FF -col-cmd-high-cpu=#ff79c6 +col-cmd-high-cpu=#bd93f9 col-cmd-io-bound=#bd93f9 col-cmd-script=#e3b341 col-user-current-non-root=#f8f8f2 diff --git a/src/taskmon/Assets/Themes/Green Beautiful 2.theme b/src/taskmon/Assets/Themes/Green Beautiful 2.theme index 88f457c..7f3bf8b 100644 --- a/src/taskmon/Assets/Themes/Green Beautiful 2.theme +++ b/src/taskmon/Assets/Themes/Green Beautiful 2.theme @@ -6,7 +6,7 @@ background-highlight=#228b22 col-cmd-normal-user-space=#FDFD96 col-cmd-low-priority=#115d33 -col-cmd-high-cpu=#000000 +col-cmd-high-cpu=#4cbb17 col-cmd-io-bound=#c3f550 col-cmd-script=#93dc5c col-user-current-non-root=#8dd06c diff --git a/src/taskmon/Assets/Themes/MSDOS.theme b/src/taskmon/Assets/Themes/MSDOS.theme index a08f951..07fb51b 100644 --- a/src/taskmon/Assets/Themes/MSDOS.theme +++ b/src/taskmon/Assets/Themes/MSDOS.theme @@ -6,7 +6,7 @@ background-highlight=#00FFFF col-cmd-normal-user-space=#FFFF00 col-cmd-low-priority=#C0C0C0 -col-cmd-high-cpu=#000000 +col-cmd-high-cpu=#FF0000 col-cmd-io-bound=#FF0000 col-cmd-script=#FFFF00 col-user-current-non-root=#C0C0C0 diff --git a/src/taskmon/Assets/Themes/Night Owl.theme b/src/taskmon/Assets/Themes/Night Owl.theme index b726d82..da8a865 100644 --- a/src/taskmon/Assets/Themes/Night Owl.theme +++ b/src/taskmon/Assets/Themes/Night Owl.theme @@ -6,7 +6,7 @@ background-highlight=#1d3b53 ; editor.selectionBackground col-cmd-normal-user-space=#ecc48d ; tokenColors: string col-cmd-low-priority=#82AAFF ; tokenColors: constant -col-cmd-high-cpu=#c5e478 ; tokenColors: variable +col-cmd-high-cpu=#F78C6C ; tokenColors: variable col-cmd-io-bound=#7fdbca ; tokenColors: punctuation col-cmd-script=#7fdbca ; tokenColors: support col-user-current-non-root=#637777 ; tokenColors: comment diff --git a/src/taskmon/Assets/Themes/Nord.theme b/src/taskmon/Assets/Themes/Nord.theme index 38110bf..759918e 100644 --- a/src/taskmon/Assets/Themes/Nord.theme +++ b/src/taskmon/Assets/Themes/Nord.theme @@ -2,37 +2,37 @@ colour-mode=indexed background=transparent -background-highlight=#434c5ecc ; editor.selectionBackground +background-highlight=#434c5ecc -col-cmd-normal-user-space=#A3BE8C ; tokenColors: string -col-cmd-low-priority=#81A1C1 ; tokenColors: constant -col-cmd-high-cpu=#81A1C1 ; tokenColors: variable -col-cmd-io-bound=#ECEFF4 ; tokenColors: punctuation -col-cmd-script=#8FBCBB ; tokenColors: support -col-user-current-non-root=#616E88 ; tokenColors: comment -col-user-other-non-root=#88C0D0 ; tokenColors: support.function -col-user-system=#ECEFF4 ; tokenColors: punctuation.definition.parameters -col-user-root=#ECEFF4 ; tokenColors: punctuation.definition.parameters +col-cmd-normal-user-space=#A3BE8C +col-cmd-low-priority=#81A1C1 +col-cmd-high-cpu=#8FBCBB +col-cmd-io-bound=#ECEFF4 +col-cmd-script=#8FBCBB +col-user-current-non-root=#616E88 +col-user-other-non-root=#88C0D0 +col-user-system=#ECEFF4 +col-user-root=#ECEFF4 -command-foreground=#d8dee9 ; tab.activeForeground -command-background=#3b4252 ; tab.activeBackground +command-foreground=#d8dee9 +command-background=#3b4252 -delta-highlight-colour=#5E81AC ; tokencolors: meta +delta-highlight-colour=#5E81AC error=#db61a2 -foreground=#8FBCBB ; tokenColors: entity -foreground-highlight=#81a1c199 ; editor.wordHighlightStrongBackground +foreground=#8FBCBB +foreground-highlight=#81a1c199 -menubar-foreground=#d8dee9 ; tab.activeForeground -menubar-background=#3b4252 ; tab.activeBackground +menubar-foreground=#d8dee9 +menubar-background=#3b4252 -range-high-background=#8FBCBB ; tokenColors: variable -range-low-background=#616E88 ; tokenColors: comment -range-mid-background=#81A1C1 ; tokenColors: keyword +range-high-background=#8FBCBB +range-low-background=#616E88 +range-mid-background=#81A1C1 range-high-foreground=#222222 range-low-foreground=#222222 range-mid-foreground=#222222 -header-background=#3b4252 ; tab.activeBackground -header-foreground=#d8dee9 ; tab.activeForeground +header-background=#3b4252 +header-foreground=#d8dee9 diff --git a/src/taskmon/Assets/Themes/One Dark Pro.theme b/src/taskmon/Assets/Themes/One Dark Pro.theme index a2afc69..666a23c 100644 --- a/src/taskmon/Assets/Themes/One Dark Pro.theme +++ b/src/taskmon/Assets/Themes/One Dark Pro.theme @@ -6,7 +6,7 @@ background-highlight=##3b5070 col-cmd-normal-user-space=#61afef col-cmd-low-priority=#0000FF -col-cmd-high-cpu=#222222 +col-cmd-high-cpu=#c678dd col-cmd-io-bound=#2b7489 col-cmd-script=#e3b341 col-user-current-non-root=#61afef diff --git a/src/taskmon/Assets/Themes/Shades of Purple.theme b/src/taskmon/Assets/Themes/Shades of Purple.theme index f33e37d..4ef20f2 100644 --- a/src/taskmon/Assets/Themes/Shades of Purple.theme +++ b/src/taskmon/Assets/Themes/Shades of Purple.theme @@ -6,7 +6,7 @@ background-highlight=#B362FF col-cmd-normal-user-space=#A5FF90 col-cmd-low-priority=#FF628C -col-cmd-high-cpu=#E1EFFF +col-cmd-high-cpu=#B362FF col-cmd-io-bound=#E1EFFF col-cmd-script=#80FFBB col-user-current-non-root=#B362FF diff --git a/src/taskmon/Assets/Themes/SynthWave 84.theme b/src/taskmon/Assets/Themes/SynthWave 84.theme index 388bd01..542227e 100644 --- a/src/taskmon/Assets/Themes/SynthWave 84.theme +++ b/src/taskmon/Assets/Themes/SynthWave 84.theme @@ -6,7 +6,7 @@ background-highlight=#fede5d ; editor.selectionBackground col-cmd-normal-user-space=#ff8b39 ; tokenColors: string col-cmd-low-priority=#f97e72 ; tokenColors: constant -col-cmd-high-cpu=#ff7edb ; tokenColors: variable +col-cmd-high-cpu=#36f9f6 ; tokenColors: variable col-cmd-io-bound=#b6b1b1 ; tokenColors: punctuation col-cmd-script=#36f9f6 ; tokenColors: support col-user-current-non-root=#848bbd ; tokenColors: comment diff --git a/src/taskmon/Assets/Themes/Tokyo Night.theme b/src/taskmon/Assets/Themes/Tokyo Night.theme index ddcda05..5b23df6 100644 --- a/src/taskmon/Assets/Themes/Tokyo Night.theme +++ b/src/taskmon/Assets/Themes/Tokyo Night.theme @@ -6,7 +6,7 @@ background-highlight=##3b5070 col-cmd-normal-user-space=#9ece6a col-cmd-low-priority=#0000FF -col-cmd-high-cpu=#000000 +col-cmd-high-cpu=#bb9af7 col-cmd-io-bound=#2b7489 col-cmd-script=#e3b341 col-user-current-non-root=#a9b1d6 diff --git a/src/taskmon/Assets/Themes/macOS Classic.theme b/src/taskmon/Assets/Themes/macOS Classic.theme index 123c9f1..ba82b4f 100644 --- a/src/taskmon/Assets/Themes/macOS Classic.theme +++ b/src/taskmon/Assets/Themes/macOS Classic.theme @@ -6,7 +6,7 @@ background-highlight=#004a9e col-cmd-normal-user-space=#ffffff col-cmd-low-priority=#b5cea8 -col-cmd-high-cpu=#ff453a +col-cmd-high-cpu=#AC98AD col-cmd-io-bound=#ffd60a col-cmd-script=#b5cea8 col-user-current-non-root=#76BA53 diff --git a/src/taskmon/Gui/Controls/HeaderControl.cs b/src/taskmon/Gui/Controls/HeaderControl.cs index 8fb0e7e..af50d88 100644 --- a/src/taskmon/Gui/Controls/HeaderControl.cs +++ b/src/taskmon/Gui/Controls/HeaderControl.cs @@ -153,11 +153,11 @@ private void OnDrawInternal() } #endif string cpuName = systemStatistics.CpuName; -#if __APPLE__ + if (systemStatistics.CpuFrequency > 0) { cpuName += $" @ {systemStatistics.CpuFrequency / 1000.0:0.00} GHz"; } -#endif + string cpuInfo = $"{cpuName} ({coreBreakdown})"; if (appConfig.UseIrixReporting) { diff --git a/src/taskmon/Gui/HelpScreen.cs b/src/taskmon/Gui/HelpScreen.cs index 0ee7499..0a05252 100644 --- a/src/taskmon/Gui/HelpScreen.cs +++ b/src/taskmon/Gui/HelpScreen.cs @@ -96,7 +96,7 @@ protected override void OnLoad() colourHelpText.AppendLine("Process and Path Colours:".ToColour(fg, bg)); colourHelpText.AppendLine("Normal process".ToColour(theme.ColumnCommandNormalUserSpace, bg)); colourHelpText.AppendLine("Low priority (nice) process".ToColour(theme.ColumnCommandLowPriority, bg)); - colourHelpText.AppendLine("High Cpu usage (> 1 core)".ToColour(theme.RangeHighForeground, theme.RangeHighBackground)); + colourHelpText.AppendLine("High Cpu usage (> 1 core)".ToColour(theme.ColumnCommandHighCpu, bg)); colourHelpText.AppendLine("I/O bound process".ToColour(theme.ColumnCommandIoBound, bg)); colourHelpText.Append("Metric ".ToColour(fg, bg)); colourHelpText.Append("Low ".ToColour(theme.RangeLowForeground, theme.RangeLowBackground)); diff --git a/src/taskmon/Process/Processor.cs b/src/taskmon/Process/Processor.cs index 6c81c39..0f61f7d 100644 --- a/src/taskmon/Process/Processor.cs +++ b/src/taskmon/Process/Processor.cs @@ -140,12 +140,6 @@ private void RunInternal(CancellationToken cancellationToken) GetNetworkStats(ref prevNetworkStats); foreach (ProcessInfo processInfo in processService.GetProcesses()) { -#if __WIN32__ - // On Windows, ignore the system "idle" process auto assigned to Pid 0. - if (isWindows && processInfo.Pid == 0) { - continue; - } -#endif processInfoMap.TryAdd(processInfo.Pid, processInfo); processCount++; threadCount += processInfo.ThreadCount; diff --git a/src/taskmon/Program.cs b/src/taskmon/Program.cs index 79125a2..14e7760 100644 --- a/src/taskmon/Program.cs +++ b/src/taskmon/Program.cs @@ -46,7 +46,7 @@ private static int Main(string[] args) if (args.Any(arg => arg.Equals("--debug", StringComparison.CurrentCultureIgnoreCase))) { OutputWriter.Out.WriteLine($"Waiting for debugger attach to Pid {Environment.ProcessId}"); - while (false == Debugger.IsAttached) { + while (!Debugger.IsAttached) { Thread.Sleep(DebugWait); } diff --git a/tests/Task.Monitor.System.Tests/Controls/ListView/ListView.ViewPortTests.cs b/tests/Task.Monitor.System.Tests/Controls/ListView/ListView.ViewPortTests.cs index 2d373a3..e93b608 100644 --- a/tests/Task.Monitor.System.Tests/Controls/ListView/ListView.ViewPortTests.cs +++ b/tests/Task.Monitor.System.Tests/Controls/ListView/ListView.ViewPortTests.cs @@ -11,7 +11,7 @@ public void Should_Construct_ViewPort() ViewPort viewPort = new(); Assert.Equal(new Rectangle(0, 0, 0, 0), viewPort.Bounds); - Assert.Equal(0, viewPort.CurrentIndex); + Assert.Equal(0, viewPort.CurrentPageIndex); Assert.Equal(0, viewPort.RowCount); Assert.Equal(0, viewPort.SelectedIndex); Assert.Equal(0, viewPort.PreviousSelectedIndex); @@ -22,7 +22,7 @@ public void Should_Reset_ViewPort() { ViewPort viewPort = new() { Bounds = new Rectangle(1, 1, 80, 24), - CurrentIndex = 1, + CurrentPageIndex = 1, PreviousSelectedIndex = 2, RowCount = 24, SelectedIndex = 1 @@ -31,7 +31,7 @@ public void Should_Reset_ViewPort() viewPort.Reset(); Assert.Equal(new Rectangle(0, 0, 0, 0), viewPort.Bounds); - Assert.Equal(0, viewPort.CurrentIndex); + Assert.Equal(0, viewPort.CurrentPageIndex); Assert.Equal(0, viewPort.RowCount); Assert.Equal(0, viewPort.SelectedIndex); Assert.Equal(0, viewPort.PreviousSelectedIndex);