Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ 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; }
public Rectangle Bounds { get; set; }

public void Reset()
{
CurrentIndex = 0;
CurrentPageIndex = 0;
SelectedIndex = 0;
PreviousSelectedIndex = 0;
RowCount = 0;
Expand Down
46 changes: 28 additions & 18 deletions src/Task.Monitor.System/Controls/ListView/ListView.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Drawing;
using System.Drawing;
using Task.Monitor.Cli.Utils;

namespace Task.Monitor.System.Controls.ListView;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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++;
}
}
Expand Down Expand Up @@ -431,9 +441,8 @@ internal void InsertItems(ListViewItem[] items)
protected override void OnDraw()
{
FrameClear();

CalculateViewPortBounds();

if (ShowColumnHeaders) {
DrawHeader();
}
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/taskmon/Assets/Themes/Ayu.theme
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/taskmon/Assets/Themes/Catppuccin.theme
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/taskmon/Assets/Themes/Cobalt2.theme
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/taskmon/Assets/Themes/Dracula Official.theme
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/taskmon/Assets/Themes/Green Beautiful 2.theme
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/taskmon/Assets/Themes/MSDOS.theme
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/taskmon/Assets/Themes/Night Owl.theme
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 22 additions & 22 deletions src/taskmon/Assets/Themes/Nord.theme
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/taskmon/Assets/Themes/One Dark Pro.theme
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/taskmon/Assets/Themes/Shades of Purple.theme
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/taskmon/Assets/Themes/SynthWave 84.theme
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/taskmon/Assets/Themes/Tokyo Night.theme
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/taskmon/Assets/Themes/macOS Classic.theme
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/taskmon/Gui/Controls/HeaderControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/taskmon/Gui/HelpScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
6 changes: 0 additions & 6 deletions src/taskmon/Process/Processor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/taskmon/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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);
Expand Down
Loading