-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
imp - Re-made screensaver selection as interactive TUI
--- We've used Terminaux's interactive TUI feature instead of the selection style to make using this feature easier than before. --- Type: imp Breaking: False Doc Required: False Part: 1/1
- Loading branch information
Showing
4 changed files
with
104 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// | ||
// Nitrocid KS Copyright (C) 2018-2024 Aptivi | ||
// | ||
// This file is part of Nitrocid KS | ||
// | ||
// Nitrocid KS is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Nitrocid KS is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY, without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
// | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Nitrocid.Languages; | ||
using Nitrocid.Misc.Screensaver; | ||
using Terminaux.Inputs.Interactive; | ||
using Terminaux.Reader; | ||
using Textify.General; | ||
|
||
namespace Nitrocid.Misc.Interactives | ||
{ | ||
internal class ScreensaverTui : BaseInteractiveTui<string>, IInteractiveTui<string> | ||
{ | ||
public override List<InteractiveTuiBinding> Bindings { get; set; } = | ||
[ | ||
// Operations | ||
new InteractiveTuiBinding("Preview", ConsoleKey.Enter, | ||
(saver, _) => PressAndBailHelper((string)saver)) | ||
]; | ||
|
||
/// <inheritdoc/> | ||
public override IEnumerable<string> PrimaryDataSource => | ||
ScreensaverManager.GetScreensaverNames(); | ||
|
||
/// <inheritdoc/> | ||
public override string GetInfoFromItem(string item) | ||
{ | ||
// Get an instance of the screensaver to grab its info from | ||
var screensaver = ScreensaverManager.GetScreensaver(item); | ||
|
||
// Generate the rendered text | ||
string name = screensaver.ScreensaverName; | ||
bool flashing = screensaver.ScreensaverContainsFlashingImages; | ||
|
||
// Render them to the second pane | ||
return | ||
Translate.DoTranslation("Screensaver name") + $": {name}" + CharManager.NewLine + | ||
Translate.DoTranslation("Screensaver contains flashing images") + $": {flashing}"; | ||
; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override void RenderStatus(string item) => | ||
InteractiveTuiStatus.Status = item; | ||
|
||
/// <inheritdoc/> | ||
public override string GetEntryFromItem(string item) => | ||
item; | ||
|
||
private static void PressAndBailHelper(string saver) | ||
{ | ||
ScreensaverManager.ShowSavers(saver); | ||
if (ScreensaverManager.inSaver) | ||
{ | ||
TermReader.ReadKey(); | ||
ScreensaverDisplayer.BailFromScreensaver(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters