-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from FRACerqueira/v4.0.3
V4.0.3
- Loading branch information
Showing
54 changed files
with
932 additions
and
151 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
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
14 changes: 14 additions & 0 deletions
14
Samples/AlternateScreenSamples/AlternateScreenSamples.csproj
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,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> |
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,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(); | ||
|
||
} | ||
} | ||
} |
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
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); | ||
} | ||
|
||
} | ||
} |
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,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); | ||
} | ||
} | ||
} |
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,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; } | ||
|
||
} | ||
} |
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,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.
Oops, something went wrong.