Skip to content

Commit

Permalink
Merge pull request #47 from FRACerqueira/v4.0.3
Browse files Browse the repository at this point in the history
V4.0.3
  • Loading branch information
FRACerqueira authored Jul 31, 2023
2 parents 6123d6a + 19956a7 commit 7b112b6
Show file tree
Hide file tree
Showing 54 changed files with 932 additions and 151 deletions.
11 changes: 10 additions & 1 deletion PromptPlus.sln
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChartSamples", "Samples\Cha
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CalendarSamples", "Samples\CalendarSamples\CalendarSamples.csproj", "{248BA41C-17EF-42E3-A9B4-17FF7FA1311B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PipelineSamples", "Samples\PipelineSamples\PipelineSamples.csproj", "{184F90B1-EBF2-4D34-88B3-9D7A252CB2B4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PipelineSamples", "Samples\PipelineSamples\PipelineSamples.csproj", "{184F90B1-EBF2-4D34-88B3-9D7A252CB2B4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AlternateScreenSamples", "Samples\AlternateScreenSamples\AlternateScreenSamples.csproj", "{83BB7962-34D7-4F51-8856-94BDC7B68A64}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -349,6 +351,12 @@ Global
{184F90B1-EBF2-4D34-88B3-9D7A252CB2B4}.local|Any CPU.Build.0 = Debug|Any CPU
{184F90B1-EBF2-4D34-88B3-9D7A252CB2B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{184F90B1-EBF2-4D34-88B3-9D7A252CB2B4}.Release|Any CPU.Build.0 = Release|Any CPU
{83BB7962-34D7-4F51-8856-94BDC7B68A64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{83BB7962-34D7-4F51-8856-94BDC7B68A64}.Debug|Any CPU.Build.0 = Debug|Any CPU
{83BB7962-34D7-4F51-8856-94BDC7B68A64}.local|Any CPU.ActiveCfg = Debug|Any CPU
{83BB7962-34D7-4F51-8856-94BDC7B68A64}.local|Any CPU.Build.0 = Debug|Any CPU
{83BB7962-34D7-4F51-8856-94BDC7B68A64}.Release|Any CPU.ActiveCfg = Release|Any CPU
{83BB7962-34D7-4F51-8856-94BDC7B68A64}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -392,6 +400,7 @@ Global
{A0697CC0-24A0-48D4-BB7D-57A7DE3DBFAB} = {F85DFC6B-0BBA-4B8D-BBF7-8FE175FE165C}
{248BA41C-17EF-42E3-A9B4-17FF7FA1311B} = {F85DFC6B-0BBA-4B8D-BBF7-8FE175FE165C}
{184F90B1-EBF2-4D34-88B3-9D7A252CB2B4} = {F85DFC6B-0BBA-4B8D-BBF7-8FE175FE165C}
{83BB7962-34D7-4F51-8856-94BDC7B68A64} = {F85DFC6B-0BBA-4B8D-BBF7-8FE175FE165C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2E883401-DEB0-496F-A6BC-8AA0F44BC5B9}
Expand Down
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@
- [License](#license)
- [API Reference](https://fracerqueira.github.io/PromptPlus/apis/apis.html)

## What news in V4.0.2
## Whats news in V4.0.3
- New control to switch Alternate screen
- Fixed bug Console does not change foreground/background color correctly
- Fixed bug Control ProgressBar
- Not show gradient when setted ProgressBarType.Fill
- Improve testability of result classes/struct (Internal to public)

## Whats news in V4.0.2
- New Control Pipeline
- PromptPlus.Pipeline(T startvalue)
- Changed WaitControl to take context value in tasks and return context in result
Expand All @@ -41,7 +48,7 @@
- IsYesResponseKey(this ConsoleKeyInfo keyinfo)
- IsNoResponseKey(this ConsoleKeyInfo keyinfo)

## What's News in V4.0.1
## Whats news in V4.0.X

### Newest controls and color improvement and layout

Expand Down Expand Up @@ -73,6 +80,8 @@
- Progress bar with 8 types , gradient colors and spinner
- Browser File and Folder with multi-select, colors and spinner
- Treeview hierarchical structures with multi-select and colors
- Switch Alternate screen
- Execution pipeline with conditions

**All controls** have the same organization (see in action: [**Controls Snapshot**](#controls-snapshot)):
- input/filter (except Masked input) using **[GNU Readline](https://en.wikipedia.org/wiki/GNU_Readline) Emacs keyboard shortcuts**.
Expand Down Expand Up @@ -147,6 +156,11 @@ For each snapshot, the title is **name of projet** sample in folder **samples**

**Not have snapshot**

### Alternate screen

[**Top**](#table-of-contents) | [AlternateScreenSamples](https://github.com/FRACerqueira/PromptPlus/tree/main/Samples/AlternateScreenSamples)

![](./docs/images/alternatescreen1.gif)

### Input

Expand Down
14 changes: 14 additions & 0 deletions Samples/AlternateScreenSamples/AlternateScreenSamples.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Src\PromptPlus.csproj" />
</ItemGroup>

</Project>
44 changes: 44 additions & 0 deletions Samples/AlternateScreenSamples/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using PPlus;
using PPlus.Controls;

namespace AlternateScreenSamples
{
internal class Program
{
static void Main(string[] args)
{

PromptPlus.DoubleDash($"PromptPlus AlternateScreen");
PromptPlus.SetCursorPosition(0,PromptPlus.CursorTop+1);
PromptPlus.KeyPress("Press any key to Swith secondary screen", cfg =>
{
cfg.ShowTooltip(false);
})
.Run();

PromptPlus.AlternateScreen()
.ForegroundColor(ConsoleColor.White)
.BackgroundColor(ConsoleColor.Red)
.CustomAction((cts) =>
{
PromptPlus.WriteLine("This text run in secondary screen");
PromptPlus.WriteLines(2);
PromptPlus.KeyPress("Press any key to Swith primary screen", cfg =>
{
cfg.ShowTooltip(false);
})
.Run();
})
.Run();

PromptPlus.WriteLines(2);
PromptPlus.KeyPress("End Sample!, Press any key", cfg =>
{
cfg.ShowTooltip(false);
cfg.ApplyStyle(StyleControls.Tooltips, Style.Plain.Foreground(Style.Plain.Background.GetInvertedColor()));
})
.Run();

}
}
}
6 changes: 6 additions & 0 deletions Samples/ConsoleFeaturesSamples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ internal class Program
{
static void Main()
{
PromptPlus.Reset();
PromptPlus.Clear();


PromptPlus.WriteLine("[RGB(255,0,0) ON WHITE]Test[YELLOW] COLOR [/] BACK COLOR [/] other text");
PromptPlus.WriteLine("[#ff0000 ON WHITE]Test [YELLOW] COLOR [/] BACK COLOR [/] other text");
PromptPlus.WriteLine("[RED ON WHITE]Test[YELLOW] COLOR [/] BACK COLOR [/] other text");
Expand Down Expand Up @@ -43,6 +47,7 @@ static void Main()
cfg.Culture = new CultureInfo("en-us");
});


PromptPlus.SingleDash($"[yellow]Console Information[/]", DashOptions.DoubleBorder, 1 /*extra lines*/);
PromptPlus.WriteLine($"IsTerminal: {PromptPlus.IsTerminal}");
PromptPlus.WriteLine($"IsUnicodeSupported: {PromptPlus.IsUnicodeSupported}");
Expand Down Expand Up @@ -119,6 +124,7 @@ static void Main()
PromptPlus.WriteLine("|");
}
}

if (PromptPlus.ColorDepth >= ColorSystem.TrueColor)
{
PromptPlus.WriteLine();
Expand Down
110 changes: 110 additions & 0 deletions Src/Controls/AlternateScreen/AlternateScreenControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// ***************************************************************************************
// MIT LICENCE
// The maintenance and evolution is maintained by the PromptPlus project under MIT license
// ***************************************************************************************

using System;
using System.Threading;
using PPlus.Controls.Objects;

namespace PPlus.Controls
{
internal class AlternateScreenControl : BaseControl<bool>, IControlAlternateScreen
{
private readonly AlternateScreenOtions _options;
private bool _resultaction = false;

public AlternateScreenControl(IConsoleControl console, AlternateScreenOtions options) : base(console, options)
{
_options = options;
}

#region IControlAlternateScreen

public IControlAlternateScreen CustomAction(Action<CancellationToken> value)
{
_options.CustomAction = value;
return this;
}

public IControlAlternateScreen Config(Action<IPromptConfig> context)
{
context?.Invoke(_options);
return this;
}

public IControlAlternateScreen ForegroundColor(ConsoleColor value)
{
_options.ForeColor = value;
return this;
}

public IControlAlternateScreen BackgroundColor(ConsoleColor value)
{
_options.BackColor = value;
return this;
}

#endregion

public override void FinalizeControl(CancellationToken cancellationToken)
{
//none
}

public override void FinishTemplate(ScreenBuffer screenBuffer, bool result, bool aborted)
{
//none
}

public override string InitControl(CancellationToken cancellationToken)
{
if (_options.CustomAction == null)
{
throw new PromptPlusException("Not have process to run");
}

return string.Empty;
}

public override void InputTemplate(ScreenBuffer screenBuffer)
{
if (ConsolePlus.IsLegacy || !ConsolePlus.SupportsAnsi)
{
_resultaction = false;
}
_resultaction = true;

var curforecolor = ConsolePlus.ForegroundColor;
var curbackcolor = ConsolePlus.BackgroundColor;

try
{

ConsolePlus.ForegroundColor = _options.ForeColor;
ConsolePlus.BackgroundColor = _options.BackColor;
// Switch to alternate screen
ConsolePlus.IsControlText = true;
ConsolePlus.Write("\u001b[?1049h", clearrestofline: false);
ConsolePlus.IsControlText = false;
ConsolePlus.Clear();
_options.CustomAction.Invoke(CancellationToken);
}
finally
{
// Switch back to primary screen
ConsolePlus.IsControlText = true;
ConsolePlus.Write("\u001b[?1049l", clearrestofline: false);
ConsolePlus.IsControlText = false;
ConsolePlus.ForegroundColor = curforecolor;
ConsolePlus.BackgroundColor = curbackcolor;
}
}

public override ResultPrompt<bool> TryResult(CancellationToken cancellationToken)
{
return new ResultPrompt<bool>(_resultaction, false);
}

}
}
36 changes: 36 additions & 0 deletions Src/Controls/AlternateScreen/AlternateScreenExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// ***************************************************************************************
// MIT LICENCE
// The maintenance and evolution is maintained by the PromptPlus project under MIT license
// ***************************************************************************************

using PPlus.Controls;
using System;

namespace PPlus
{
public static partial class PromptPlus
{
/// <summary>
/// Create CustomAction Control
/// </summary>
/// <returns><see cref="IControlAlternateScreen"/></returns>
public static IControlAlternateScreen AlternateScreen()
{
return AlternateScreen(null);
}

/// <summary>
/// Create CustomAction Control
/// </summary>
/// <param name="config">The config action <see cref="IPromptConfig"/></param>
/// <returns><see cref="IControlAlternateScreen"/></returns>
public static IControlAlternateScreen AlternateScreen(Action<IPromptConfig> config)
{
var opt = new AlternateScreenOtions(true)
{
};
config?.Invoke(opt);
return new AlternateScreenControl(_consoledrive, opt);
}
}
}
28 changes: 28 additions & 0 deletions Src/Controls/AlternateScreen/AlternateScreenOtions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// ***************************************************************************************
// MIT LICENCE
// The maintenance and evolution is maintained by the PromptPlus project under MIT license
// ***************************************************************************************

using System;
using System.Threading;

namespace PPlus.Controls
{
internal class AlternateScreenOtions : BaseOptions
{
private AlternateScreenOtions()
{
throw new PromptPlusException("AlternateScreenOtions CTOR NotImplemented");
}

internal AlternateScreenOtions(bool showcursor) : base(showcursor)
{
}
public Action<CancellationToken> CustomAction { get; set; }

public ConsoleColor ForeColor { get; set; }

public ConsoleColor BackColor { get; set; }

}
}
51 changes: 51 additions & 0 deletions Src/Controls/AlternateScreen/IControlAlternateScreen.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// ***************************************************************************************
// MIT LICENCE
// The maintenance and evolution is maintained by the PromptPlus project under MIT license
// ***************************************************************************************

using System;
using System.Threading;

namespace PPlus.Controls
{
///<inheritdoc cref="IPromptControls{T}"/>
/// <summary>
/// Represents the interface with all Methods of the AlternateScreen control
/// </summary>

public interface IControlAlternateScreen: IPromptControls<bool>
{
/// <summary>
/// Action when console/terminal has Capability to swith to AlternateScreen buffer.
/// <br>If not has capability to swith AlternateScreen, the action not run and the control return false, otherwise the control return true</br>
/// </summary>
/// <param name="value">The action</param>
/// <returns><see cref="IControlAlternateScreen"/></returns>
IControlAlternateScreen CustomAction(Action<CancellationToken> value);


/// <summary>
/// Custom config the control.
/// </summary>
/// <param name="context">action to apply changes. <see cref="IPromptConfig"/></param>
/// <returns><see cref="IControlAlternateScreen"/></returns>
IControlAlternateScreen Config(Action<IPromptConfig> context);

/// <summary>
/// Set Foreground Color to AlternateScreen buffer.
/// </summary>
/// <param name="value">The Foreground</param>
/// <returns><see cref="IControlAlternateScreen"/></returns>
IControlAlternateScreen ForegroundColor(ConsoleColor value);

/// <summary>
/// Set Background Color to AlternateScreen buffer.
/// </summary>
/// <param name="value">The Background</param>
/// <returns><see cref="IControlAlternateScreen"/></returns>
IControlAlternateScreen BackgroundColor(ConsoleColor value);



}
}
File renamed without changes.
Loading

0 comments on commit 7b112b6

Please sign in to comment.