Skip to content

Commit 220cb57

Browse files
committed
Add NotificationDemo example and disable maximize/minimize on notifications
Add standalone example app showcasing all notification features: severity levels, modal/persistent/multiline notifications, and dismiss-all. Disable maximize and minimize buttons on notification windows since they should only be closable.
1 parent ab5d806 commit 220cb57

3 files changed

Lines changed: 205 additions & 1 deletion

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\..\SharpConsoleUI\SharpConsoleUI.csproj" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="Spectre.Console" Version="0.54.0" />
16+
</ItemGroup>
17+
18+
</Project>
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
// -----------------------------------------------------------------------
2+
// NotificationDemo - Showcases the notification system
3+
// Demonstrates all severity levels, dismiss methods, modal notifications,
4+
// and timeout behavior.
5+
// -----------------------------------------------------------------------
6+
7+
using SharpConsoleUI;
8+
using SharpConsoleUI.Controls;
9+
using SharpConsoleUI.Core;
10+
using SharpConsoleUI.Drivers;
11+
using SharpConsoleUI.Layout;
12+
using Spectre.Console;
13+
using HorizontalAlignment = SharpConsoleUI.Layout.HorizontalAlignment;
14+
15+
namespace NotificationDemo;
16+
17+
class Program
18+
{
19+
static int Main(string[] args)
20+
{
21+
try
22+
{
23+
var driver = new NetConsoleDriver(RenderMode.Buffer);
24+
var windowSystem = new ConsoleWindowSystem(driver);
25+
26+
var mainWindow = new Window(windowSystem)
27+
{
28+
Title = "Notification Demo",
29+
Left = 2,
30+
Top = 1,
31+
Width = 50,
32+
Height = 22,
33+
BackgroundColor = Color.Grey11,
34+
ForegroundColor = Color.White
35+
};
36+
37+
var header = new MarkupControl(new List<string>
38+
{
39+
"[bold underline]Notification System Demo[/]",
40+
"",
41+
"Click buttons to trigger notifications.",
42+
"Dismiss via: [yellow]Close[/] button, title bar [yellow]\\[X][/],",
43+
"or press [yellow]Escape[/]."
44+
})
45+
{
46+
HorizontalAlignment = HorizontalAlignment.Left
47+
};
48+
mainWindow.AddControl(header);
49+
50+
// Info notification
51+
var infoBtn = new ButtonControl
52+
{
53+
Text = "Info Notification",
54+
Margin = new Margin { Top = 1, Left = 1 }
55+
};
56+
infoBtn.Click += (_, _) =>
57+
{
58+
windowSystem.NotificationStateService.ShowNotification(
59+
"Information",
60+
"This is an informational message.",
61+
NotificationSeverity.Info);
62+
};
63+
mainWindow.AddControl(infoBtn);
64+
65+
// Success notification
66+
var successBtn = new ButtonControl
67+
{
68+
Text = "Success Notification",
69+
Margin = new Margin { Left = 1 }
70+
};
71+
successBtn.Click += (_, _) =>
72+
{
73+
windowSystem.NotificationStateService.ShowNotification(
74+
"Success",
75+
"Operation completed successfully!",
76+
NotificationSeverity.Success);
77+
};
78+
mainWindow.AddControl(successBtn);
79+
80+
// Warning notification
81+
var warningBtn = new ButtonControl
82+
{
83+
Text = "Warning Notification",
84+
Margin = new Margin { Left = 1 }
85+
};
86+
warningBtn.Click += (_, _) =>
87+
{
88+
windowSystem.NotificationStateService.ShowNotification(
89+
"Warning",
90+
"Disk space is running low.",
91+
NotificationSeverity.Warning);
92+
};
93+
mainWindow.AddControl(warningBtn);
94+
95+
// Danger notification
96+
var dangerBtn = new ButtonControl
97+
{
98+
Text = "Danger Notification",
99+
Margin = new Margin { Left = 1 }
100+
};
101+
dangerBtn.Click += (_, _) =>
102+
{
103+
windowSystem.NotificationStateService.ShowNotification(
104+
"Error",
105+
"Connection to server lost!",
106+
NotificationSeverity.Danger);
107+
};
108+
mainWindow.AddControl(dangerBtn);
109+
110+
// Modal notification (blocks UI)
111+
var modalBtn = new ButtonControl
112+
{
113+
Text = "Modal Notification",
114+
Margin = new Margin { Top = 1, Left = 1 }
115+
};
116+
modalBtn.Click += (_, _) =>
117+
{
118+
windowSystem.NotificationStateService.ShowNotification(
119+
"Confirm",
120+
"This is modal - dismiss to continue.",
121+
NotificationSeverity.Warning,
122+
blockUi: true,
123+
timeout: null);
124+
};
125+
mainWindow.AddControl(modalBtn);
126+
127+
// No-timeout notification
128+
var persistentBtn = new ButtonControl
129+
{
130+
Text = "Persistent (no timeout)",
131+
Margin = new Margin { Left = 1 }
132+
};
133+
persistentBtn.Click += (_, _) =>
134+
{
135+
windowSystem.NotificationStateService.ShowNotification(
136+
"Persistent",
137+
"This won't auto-dismiss.",
138+
NotificationSeverity.Info,
139+
timeout: null);
140+
};
141+
mainWindow.AddControl(persistentBtn);
142+
143+
// Multiline notification
144+
var multilineBtn = new ButtonControl
145+
{
146+
Text = "Multiline Message",
147+
Margin = new Margin { Left = 1 }
148+
};
149+
multilineBtn.Click += (_, _) =>
150+
{
151+
windowSystem.NotificationStateService.ShowNotification(
152+
"Details",
153+
"Line 1: Build started\nLine 2: Compiling sources\nLine 3: Build succeeded",
154+
NotificationSeverity.Success,
155+
timeout: null);
156+
};
157+
mainWindow.AddControl(multilineBtn);
158+
159+
// Dismiss all
160+
var dismissAllBtn = new ButtonControl
161+
{
162+
Text = "Dismiss All",
163+
Margin = new Margin { Top = 1, Left = 1 }
164+
};
165+
dismissAllBtn.Click += (_, _) =>
166+
{
167+
windowSystem.NotificationStateService.DismissAll();
168+
};
169+
mainWindow.AddControl(dismissAllBtn);
170+
171+
windowSystem.AddWindow(mainWindow);
172+
windowSystem.SetActiveWindow(mainWindow);
173+
174+
return windowSystem.Run();
175+
}
176+
catch (Exception ex)
177+
{
178+
Console.Clear();
179+
Console.WriteLine($"Fatal error: {ex.Message}");
180+
Console.WriteLine(ex.StackTrace);
181+
return 1;
182+
}
183+
}
184+
}

SharpConsoleUI/Core/NotificationStateService.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,9 @@ private Window CreateNotificationWindow(
325325
InactiveBorderForegroundColor = severity.InactiveBorderForegroundColor(_windowSystem),
326326
ActiveTitleForegroundColor = severity.ActiveTitleForegroundColor(_windowSystem),
327327
InactiveTitleForegroundColor = severity.InactiveTitleForegroundColor(_windowSystem),
328-
IsResizable = false
328+
IsResizable = false,
329+
IsMaximizable = false,
330+
IsMinimizable = false
329331
};
330332

331333
if (blockUi)

0 commit comments

Comments
 (0)