├── assets
├── title.png
├── output.png
├── ascii-icon.png
├── example1.png
├── example2.png
├── example3.png
├── example4.png
├── example5.png
├── example6.png
├── example7.png
└── ansivtconsole.netcore.widget.gif
├── AnsiVtConsole.NetCore
├── assets
│ ├── title.png
│ ├── example1.png
│ ├── example2.png
│ ├── example3.png
│ ├── example4.png
│ ├── example5.png
│ ├── example6.png
│ ├── example7.png
│ ├── output.png
│ ├── ascii-icon.png
│ └── ansivtconsole.netcore.widget.gif
├── Component
│ ├── Parser
│ │ ├── NonRecursiveFunctionalGrammar
│ │ │ ├── TreeNode.cs
│ │ │ ├── TreePath.cs
│ │ │ ├── Rule.cs
│ │ │ ├── SyntacticBlockList.cs
│ │ │ └── SyntacticBlock.cs
│ │ └── ANSI
│ │ │ ├── ANSIParser.cs
│ │ │ └── ansi-seq-patterns.txt
│ ├── Console
│ │ ├── BufferedOperationNotAvailableException.cs
│ │ ├── LineSplitList.cs
│ │ ├── Color4BitMap.cs
│ │ ├── Warn.cs
│ │ ├── ActualWorkArea.cs
│ │ ├── Error.cs
│ │ ├── Inp.cs
│ │ ├── EchoSequenceList.cs
│ │ ├── InputMap.cs
│ │ ├── StringSegment.cs
│ │ ├── Cursor.cs
│ │ ├── Unicode.cs
│ │ ├── EchoSequence.cs
│ │ ├── ASCII.cs
│ │ ├── Logger.cs
│ │ ├── ColorSettings.cs
│ │ ├── TextColor.cs
│ │ └── WorkArea.cs
│ ├── Settings
│ │ ├── SettingsBuilder.cs
│ │ ├── WorkAreaSettings.cs
│ │ └── AnsiVtConsoleSettings.cs
│ ├── UI
│ │ └── WorkAreaScrollEventArgs.cs
│ ├── Widgets
│ │ ├── IAnimatedWidget.cs
│ │ ├── Animatics
│ │ │ ├── Easings
│ │ │ │ ├── Easing.cs
│ │ │ │ └── Linear.cs
│ │ │ ├── Animations
│ │ │ │ └── IntAnimation.cs
│ │ │ ├── AnimationGroup.cs
│ │ │ ├── Animation.cs
│ │ │ ├── TimeLine.cs
│ │ │ ├── IAnimation.cs
│ │ │ ├── Animator.cs
│ │ │ └── ValueAnimation.cs
│ │ ├── OptionsBuilder.cs
│ │ ├── Texts
│ │ │ ├── Timers
│ │ │ │ ├── TimerOptionsBuilder.cs
│ │ │ │ └── TextTimer.cs
│ │ │ ├── TypeWriting
│ │ │ │ ├── TypeWriterOptionsBuilder.cs
│ │ │ │ └── TypeWriter.cs
│ │ │ ├── AnimatedText.cs
│ │ │ ├── Text.cs
│ │ │ └── Coloring
│ │ │ │ └── Gradient.cs
│ │ ├── AnimatedOptionsBuilder.cs
│ │ ├── Models
│ │ │ └── Rgb.cs
│ │ ├── IWidget.cs
│ │ ├── Bars
│ │ │ └── GradientBar.cs
│ │ └── AnimatedWidget.cs
│ ├── EchoDirective
│ │ └── CommandMap.cs
│ └── Script
│ │ └── CSharpScriptEngine.cs
├── Lib
│ ├── TargetPlatform.cs
│ ├── EventArgs.cs
│ ├── RuntimeEnvironment.cs
│ ├── Process
│ │ └── ProcessCounter.cs
│ ├── StrExt.cs
│ ├── TextFileReader.cs
│ └── Str.cs
├── LICENSE.md
└── IAnsiVtConsole.cs
├── AnsiVtConsole.NetCore.Imaging
├── assets
│ ├── title.png
│ ├── output.png
│ ├── smiley.png
│ ├── ascii-icon.png
│ ├── example1.png
│ ├── example2.png
│ ├── example3.png
│ ├── example4.png
│ ├── example5.png
│ ├── example6.png
│ └── example7.png
├── LICENSE.md
└── Component
│ └── Widgets
│ └── Images
│ └── Image.cs
├── Examples
├── AnsiVtConsole.NetCore.Examples.Widgets
│ ├── Program.cs
│ ├── assets
│ │ └── smiley.png
│ ├── Pages
│ │ ├── Images.cs
│ │ ├── Intro.cs
│ │ └── Title.cs
│ ├── AnsiVtConsole.NetCore.Examples.Widgets.csproj
│ ├── Demo.cs
│ ├── LICENSE.md
│ └── DemoPage.cs
└── AnsiVtConsole.NetCore.Examples.ANSI
│ ├── AnsiVtConsole.NetCore.Examples.ANSI.csproj
│ └── LICENSE.md
├── AnsiVtConsole.NetCore.CommandLine
├── assets
│ └── ascii-icon.png
├── Properties
│ └── launchSettings.json
├── Program.cs
├── Config
│ └── appSettings.json
├── Out.cs
├── LICENSE.md
└── AnsiVtConsole.NetCore.CommandLine.csproj
├── publish-nuget.bat
├── publish-nuget-imaging.bat
├── LICENSE.md
├── .gitattributes
├── Component
└── Parser
│ └── ANSI
│ └── ansi-seq-patterns.txt
└── AnsiVtConsole.NetCore.sln
/assets/title.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/assets/title.png
--------------------------------------------------------------------------------
/assets/output.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/assets/output.png
--------------------------------------------------------------------------------
/assets/ascii-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/assets/ascii-icon.png
--------------------------------------------------------------------------------
/assets/example1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/assets/example1.png
--------------------------------------------------------------------------------
/assets/example2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/assets/example2.png
--------------------------------------------------------------------------------
/assets/example3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/assets/example3.png
--------------------------------------------------------------------------------
/assets/example4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/assets/example4.png
--------------------------------------------------------------------------------
/assets/example5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/assets/example5.png
--------------------------------------------------------------------------------
/assets/example6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/assets/example6.png
--------------------------------------------------------------------------------
/assets/example7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/assets/example7.png
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/assets/title.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/AnsiVtConsole.NetCore/assets/title.png
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/assets/example1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/AnsiVtConsole.NetCore/assets/example1.png
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/assets/example2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/AnsiVtConsole.NetCore/assets/example2.png
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/assets/example3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/AnsiVtConsole.NetCore/assets/example3.png
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/assets/example4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/AnsiVtConsole.NetCore/assets/example4.png
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/assets/example5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/AnsiVtConsole.NetCore/assets/example5.png
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/assets/example6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/AnsiVtConsole.NetCore/assets/example6.png
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/assets/example7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/AnsiVtConsole.NetCore/assets/example7.png
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/assets/output.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/AnsiVtConsole.NetCore/assets/output.png
--------------------------------------------------------------------------------
/assets/ansivtconsole.netcore.widget.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/assets/ansivtconsole.netcore.widget.gif
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/assets/ascii-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/AnsiVtConsole.NetCore/assets/ascii-icon.png
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore.Imaging/assets/title.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/AnsiVtConsole.NetCore.Imaging/assets/title.png
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore.Imaging/assets/output.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/AnsiVtConsole.NetCore.Imaging/assets/output.png
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore.Imaging/assets/smiley.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/AnsiVtConsole.NetCore.Imaging/assets/smiley.png
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore.Imaging/assets/ascii-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/AnsiVtConsole.NetCore.Imaging/assets/ascii-icon.png
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore.Imaging/assets/example1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/AnsiVtConsole.NetCore.Imaging/assets/example1.png
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore.Imaging/assets/example2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/AnsiVtConsole.NetCore.Imaging/assets/example2.png
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore.Imaging/assets/example3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/AnsiVtConsole.NetCore.Imaging/assets/example3.png
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore.Imaging/assets/example4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/AnsiVtConsole.NetCore.Imaging/assets/example4.png
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore.Imaging/assets/example5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/AnsiVtConsole.NetCore.Imaging/assets/example5.png
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore.Imaging/assets/example6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/AnsiVtConsole.NetCore.Imaging/assets/example6.png
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore.Imaging/assets/example7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/AnsiVtConsole.NetCore.Imaging/assets/example7.png
--------------------------------------------------------------------------------
/Examples/AnsiVtConsole.NetCore.Examples.Widgets/Program.cs:
--------------------------------------------------------------------------------
1 | using AnsiVtConsole.NetCore.Examples.Widgets;
2 |
3 | new Demo().Run(new AnsiVtConsole.NetCore.AnsiVtConsole());
4 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore.CommandLine/assets/ascii-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/AnsiVtConsole.NetCore.CommandLine/assets/ascii-icon.png
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/assets/ansivtconsole.netcore.widget.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/AnsiVtConsole.NetCore/assets/ansivtconsole.netcore.widget.gif
--------------------------------------------------------------------------------
/Examples/AnsiVtConsole.NetCore.Examples.Widgets/assets/smiley.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/Examples/AnsiVtConsole.NetCore.Examples.Widgets/assets/smiley.png
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore.CommandLine/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "profiles": {
3 | "out text": {
4 | "commandName": "Project",
5 | "commandLineArgs": "out text"
6 | }
7 | }
8 | }
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Parser/NonRecursiveFunctionalGrammar/TreeNode.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/franck-gaspoz/AnsiVtConsole.NetCore/HEAD/AnsiVtConsole.NetCore/Component/Parser/NonRecursiveFunctionalGrammar/TreeNode.cs
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Console/BufferedOperationNotAvailableException.cs:
--------------------------------------------------------------------------------
1 | namespace AnsiVtConsole.NetCore.Component.Console
2 | {
3 | sealed class BufferedOperationNotAvailableException : Exception
4 | {
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Settings/SettingsBuilder.cs:
--------------------------------------------------------------------------------
1 | namespace AnsiVtConsole.NetCore_ConsoleApp.Component.Settings
2 | {
3 | ///
4 | /// TODO : settings builder pattern (fluent design)
5 | ///
6 | sealed class SettingsBuilder
7 | {
8 |
9 | }
10 | }
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Lib/TargetPlatform.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable CS1591
2 |
3 | namespace AnsiVtConsole.NetCore.Lib
4 | {
5 | ///
6 | /// based on System.Runtime.RuntimeEnvironment
7 | ///
8 | public enum TargetPlatform
9 | {
10 | FreeBSD,
11 | Linux,
12 | OSX,
13 | Windows,
14 | Any,
15 | Unspecified
16 | }
17 | }
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/UI/WorkAreaScrollEventArgs.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable CS1591
2 |
3 | namespace AnsiVtConsole.NetCore.Component.UI;
4 |
5 | public sealed class WorkAreaScrollEventArgs
6 | : EventArgs
7 | {
8 | public readonly int DeltaX;
9 | public readonly int DeltaY;
10 |
11 | public WorkAreaScrollEventArgs(int deltaX, int deltaY)
12 | {
13 | DeltaX = deltaX;
14 | DeltaY = deltaY;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Widgets/IAnimatedWidget.cs:
--------------------------------------------------------------------------------
1 | namespace AnsiVtConsole.NetCore.Component.Widgets;
2 |
3 | ///
4 | /// widget that has a regulart threaded update
5 | ///
6 | public interface IAnimatedWidget : IWidget
7 | {
8 | ///
9 | /// frames per seconds
10 | ///
11 | double FPS { get; }
12 |
13 | ///
14 | /// is running
15 | ///
16 | bool IsRunning { get; }
17 | }
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore.CommandLine/Program.cs:
--------------------------------------------------------------------------------
1 | using CommandLine.NetCore.Services.CmdLine;
2 |
3 | namespace AnsiVtConsole.NetCore.CommandLine;
4 |
5 | ///
6 | /// main class
7 | ///
8 | public class Program
9 | {
10 | ///
11 | /// command line
12 | ///
13 | /// arguments
14 | /// exit code
15 | public static int Main(string[] args)
16 | => new CommandLineInterfaceBuilder()
17 | .Build(args)
18 | .Run();
19 | }
--------------------------------------------------------------------------------
/Examples/AnsiVtConsole.NetCore.Examples.Widgets/Pages/Images.cs:
--------------------------------------------------------------------------------
1 | using AnsiVtConsole.NetCore.Imaging.Component.Widgets.Images;
2 |
3 | namespace AnsiVtConsole.NetCore.Examples.Widgets.Pages;
4 |
5 | sealed class Images : DemoPage
6 | {
7 | public override void Run()
8 | {
9 | SubTitle("Images with AnsiVtConsole.NetCore.Imaging(br)");
10 |
11 | var img1 = new Image("assets/smiley.png", 32, 16, false, (x, y, c) => "☻")
12 | .Add(_);
13 |
14 | _.Out.SetCursorPos(img1.Width!.Value, img1.Y);
15 |
16 | var img2 = new Image("assets/smiley.png", 16, 16)
17 | .Add(_);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Lib/EventArgs.cs:
--------------------------------------------------------------------------------
1 | namespace AnsiVtConsole.NetCore.Lib
2 | {
3 | ///
4 | /// generic event args + IsCanceled information
5 | ///
6 | /// event arg type
7 | sealed class EventArgs : EventArgs
8 | {
9 | public T? Value { get; set; }
10 |
11 | public bool IsCanceled { get; set; }
12 |
13 | public EventArgs(T? val) => Value = val;
14 |
15 | public EventArgs() { }
16 |
17 | public void Recycle()
18 | {
19 | Value = default;
20 | IsCanceled = false;
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Settings/WorkAreaSettings.cs:
--------------------------------------------------------------------------------
1 | using AnsiVtConsole.NetCore.Component.UI;
2 |
3 | namespace AnsiVtConsole.NetCore.Component.Settings;
4 |
5 | ///
6 | /// work area settings
7 | ///
8 | public sealed class WorkAreaSettings
9 | {
10 | #pragma warning disable CS1591
11 | public EventHandler? ViewSizeChanged { get; set; }
12 |
13 | public EventHandler? WorkAreaScrolled { get; set; }
14 |
15 | public bool EnableConstraintConsolePrintInsideWorkArea { get; set; } = false;
16 |
17 | public bool RedrawUIElementsEnabled = true;
18 |
19 | #pragma warning restore CS1591
20 | }
21 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore.CommandLine/Config/appSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Microsoft.Hosting.Lifetime": "Error"
5 | }
6 | },
7 | "App": {
8 | "Title": "out",
9 | "ReleaseDate": "01/12/2023"
10 | },
11 | "Commands": {
12 | "out": {
13 | "Description": "output a text using AinsiVtConsole. Enable ansi markup and ansi vt sequences",
14 | "Syntax": {
15 | "text": "text"
16 | },
17 | "Options": {
18 | "--raw": "get the raw text showing non printable characters",
19 | "--err": "output to the error stream instead of the standard output stream"
20 | }
21 | }
22 | },
23 | "GlobalOptions": {
24 |
25 | }
26 | }
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Widgets/Animatics/Easings/Easing.cs:
--------------------------------------------------------------------------------
1 | namespace AnsiVtConsole.NetCore.Component.Widgets.Animatics.Easings;
2 |
3 | ///
4 | /// easing function
5 | ///
6 | public abstract class Easing
7 | {
8 | ///
9 | /// get the time line position ratio from begin to end according to the easing function
10 | ///
11 | /// animation
12 | /// progress
13 | /// fps
14 | /// the value
15 | public abstract double GetPosition(
16 | ValueAnimation animation,
17 | double progress,
18 | double fps);
19 | }
20 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Widgets/Animatics/Easings/Linear.cs:
--------------------------------------------------------------------------------
1 | #define dbg
2 |
3 | namespace AnsiVtConsole.NetCore.Component.Widgets.Animatics.Easings;
4 |
5 | ///
6 | /// linear easing function
7 | ///
8 | public class Linear : Easing
9 | {
10 | ///
11 | public override double GetPosition(
12 | ValueAnimation animation,
13 | double progress,
14 | double fps)
15 | {
16 | var position = Math.Max(
17 | 1,
18 | progress / animation.Duration);
19 |
20 | #if dbg
21 | System.Diagnostics.Debug.WriteLine($"easing {GetType().Name} : position = {position}");
22 | #endif
23 | return position;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Console/LineSplitList.cs:
--------------------------------------------------------------------------------
1 | namespace AnsiVtConsole.NetCore.Component.Console
2 | {
3 | sealed class LineSplitList
4 | {
5 | public readonly List Splits;
6 |
7 | public readonly EchoSequenceList? PrintSequences;
8 |
9 | public readonly int CursorIndex;
10 |
11 | public readonly int CursorLineIndex;
12 |
13 | public LineSplitList(
14 | List splits,
15 | EchoSequenceList? printSequences,
16 | int cursorIndex = -1,
17 | int cursorLineIndex = -1)
18 | {
19 | Splits = splits;
20 | PrintSequences = printSequences;
21 | CursorIndex = cursorIndex;
22 | CursorLineIndex = cursorLineIndex;
23 | }
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/EchoDirective/CommandMap.cs:
--------------------------------------------------------------------------------
1 | namespace AnsiVtConsole.NetCore.Component.EchoDirective
2 | {
3 | ///
4 | /// these map attribute a echo command delegate to an echo directive syntax
5 | ///
6 | sealed class CommandMap
7 | {
8 | public Dictionary<
9 | string,
10 | (EchoDirectiveProcessor.SimpleCommandDelegate? simpleCommand,
11 | EchoDirectiveProcessor.CommandDelegate? command,
12 | object? parameter)>? Map;
13 |
14 | public CommandMap(Dictionary<
15 | string,
16 | (EchoDirectiveProcessor.SimpleCommandDelegate? simpleCommand,
17 | EchoDirectiveProcessor.CommandDelegate? command,
18 | object? parameter)> map)
19 | => Map = map;
20 |
21 | }
22 | }
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Widgets/OptionsBuilder.cs:
--------------------------------------------------------------------------------
1 | namespace AnsiVtConsole.NetCore.Component.Widgets;
2 |
3 | ///
4 | /// generic option builder
5 | ///
6 | /// type of builded widget
7 | public class OptionsBuilder
8 | where T : class, IWidget
9 | {
10 | ///
11 | /// builded widget
12 | ///
13 | public T Widget { get; protected set; }
14 |
15 | ///
16 | /// type writer options builder
17 | ///
18 | /// widget
19 | public OptionsBuilder(T widget)
20 | => Widget = widget;
21 |
22 | ///
23 | /// build the configured object
24 | ///
25 | /// the configured object
26 | public T Build() => Widget;
27 | }
28 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Parser/NonRecursiveFunctionalGrammar/TreePath.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable CS1591
2 |
3 | namespace AnsiVtConsole.NetCore.Component.Parser.NonRecursiveFunctionalGrammar
4 | {
5 | public sealed class TreePath : List
6 | {
7 | public Rule? Rule;
8 |
9 | public int Index;
10 |
11 | public TreePath(Rule? rule, int index)
12 | {
13 | Rule = rule;
14 | Index = index;
15 | }
16 |
17 | public TreePath(Rule? rule, int index, IEnumerable o) : base(o)
18 | {
19 | Rule = rule;
20 | Index = index;
21 | }
22 |
23 | public override string ToString() => $"<#{Rule?.ID}> " + string.Join(' ', this.Select(x => x.Label));
24 |
25 | public string Key => string.Join('-', this.Select(x => x.ID));
26 | }
27 | }
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Console/Color4BitMap.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable CS1591
2 |
3 | namespace AnsiVtConsole.NetCore.Component.Console
4 | {
5 | ///
6 | /// 4 bits colors map - see https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit
7 | ///
8 | public enum Color4BitMap
9 | {
10 | // 3 bits
11 |
12 | darkgray = 0b0,
13 | gray = 0b1111,
14 | red = 0b1,
15 | green = 0b10,
16 | yellow = 0b11,
17 | blue = 0b100,
18 | magenta = 0b101,
19 | cyan = 0b110,
20 | white = 0b111,
21 |
22 | // 4 bits
23 |
24 | black = 0b1000,
25 | darkred = 0b1001,
26 | darkgreen = 0b1010,
27 | darkyellow = 0b1011,
28 | darkblue = 0b1100,
29 | darkmagenta = 0b1101,
30 | darkcyan = 0b1110,
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Widgets/Texts/Timers/TimerOptionsBuilder.cs:
--------------------------------------------------------------------------------
1 | using AnsiVtConsole.NetCore.Component.Widgets.Texts.Timers;
2 |
3 | namespace AnsiVtConsole.NetCore.Component.Widgets;
4 |
5 | ///
6 | /// timer option builder
7 | ///
8 | public class TimerOptionsBuilder : OptionsBuilder
9 | {
10 | ///
11 | /// type writer options builder
12 | ///
13 | /// widget
14 | public TimerOptionsBuilder(TextTimer widget)
15 | : base(widget) { }
16 |
17 | ///
18 | /// set the pattern (allowed while running)
19 | ///
20 | /// pattern
21 | /// this object
22 | public TextTimer Pattern(string pattern)
23 | {
24 | Widget.SetPattern(pattern);
25 | return Widget;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Widgets/AnimatedOptionsBuilder.cs:
--------------------------------------------------------------------------------
1 | namespace AnsiVtConsole.NetCore.Component.Widgets;
2 |
3 | ///
4 | /// generic option builder
5 | ///
6 | /// type of builded widget
7 | public class AnimatedOptionsBuilder : OptionsBuilder
8 | where T : class, IAnimatedWidget
9 | {
10 | ///
11 | /// type writer options builder
12 | ///
13 | /// widget
14 | public AnimatedOptionsBuilder(T widget)
15 | : base(widget) { }
16 |
17 | ///
18 | /// fps
19 | ///
20 | /// fps
21 | /// this object
22 | public AnimatedOptionsBuilder Fps(double fps)
23 | {
24 | var o = Widget as AnimatedWidget>;
25 | o!.SetFPS(fps);
26 | return this;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/publish-nuget.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | cls
3 | echo --------------------------------------------------------------------------------------
4 | echo publish-nuget
5 | echo --------------------------------------------------------------------------------------
6 | echo tag the version and publish the corresponding nuget from version to github and nuget
7 | echo parameter: version tag
8 | echo example: publish-nuget 1.0.15
9 | echo nugetkey=%nugetkey%
10 | echo githubkey=%githubkey%
11 | echo version=%1
12 | echo --------------------------------------------------------------------------------------
13 |
14 | git tag -a v%1 -m v%1
15 | git push origin v%1
16 | nuget push AnsiVtConsole.NetCore/bin/Release/AnsiVtConsole.NetCore.%1.nupkg %nugetkey% -SkipDuplicate -Source https://api.nuget.org/v3/index.json -Verbosity detailed
17 | dotnet nuget push "AnsiVtConsole.NetCore/bin/Release/AnsiVtConsole.NetCore.%1.nupkg" --skip-duplicate --api-key %githubkey% --source "github"
18 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Lib/RuntimeEnvironment.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable CS1591
2 |
3 | using System.Runtime.InteropServices;
4 |
5 | namespace AnsiVtConsole.NetCore.Lib
6 | {
7 | public static class RuntimeEnvironment
8 | {
9 | public static OSPlatform? OSType
10 | {
11 | get
12 | {
13 | OSPlatform? oSPlatform = null;
14 | if (RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD))
15 | oSPlatform = OSPlatform.FreeBSD;
16 | if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
17 | oSPlatform = OSPlatform.Windows;
18 | if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
19 | oSPlatform = OSPlatform.OSX;
20 | if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
21 | oSPlatform = OSPlatform.Linux;
22 | return oSPlatform;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/publish-nuget-imaging.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | cls
3 | echo --------------------------------------------------------------------------------------
4 | echo publish-nuget
5 | echo --------------------------------------------------------------------------------------
6 | echo tag the version and publish the corresponding nuget from version to github and nuget
7 | echo parameter: version tag
8 | echo example: publish-nuget 1.0.15
9 | echo nugetkey=%nugetkey%
10 | echo githubkey=%githubkey%
11 | echo version=%1
12 | echo --------------------------------------------------------------------------------------
13 |
14 | rem git tag -a v%1 -m v%1
15 | rem git push origin v%1
16 | nuget push AnsiVtConsole.NetCore.Imaging/bin/Release/AnsiVtConsole.NetCore.Imaging.%1.nupkg %nugetkey% -SkipDuplicate -Source https://api.nuget.org/v3/index.json -Verbosity detailed
17 | dotnet nuget push "AnsiVtConsole.NetCore.Imaging/bin/Release/AnsiVtConsole.NetCore.Imaging.%1.nupkg" --skip-duplicate --api-key %githubkey% --source "github"
18 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Console/Warn.cs:
--------------------------------------------------------------------------------
1 | namespace AnsiVtConsole.NetCore.Component.Console;
2 |
3 | class Warn
4 | {
5 | readonly ConsoleTextWriterWrapper _out;
6 | readonly Error _err;
7 |
8 | public Warn(
9 | ConsoleTextWriterWrapper outStream,
10 | Error err)
11 | {
12 | _out = outStream;
13 | _err = err;
14 | }
15 |
16 | public void Log(string text = "") => LogInternal(text, false);
17 |
18 | public void LogLine(string text = "") => LogInternal(text, true);
19 |
20 | public void LogLine(IEnumerable texts)
21 | {
22 | foreach (var s in texts)
23 | _err.LogLine(s);
24 | }
25 |
26 | public void Log(IEnumerable texts)
27 | {
28 | foreach (var s in texts)
29 | _err.Log(s);
30 | }
31 |
32 | void LogInternal(string text, bool lineBreak = false)
33 | {
34 | lock (_out.Lock!)
35 | {
36 | _out.Write(text, lineBreak);
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Examples/AnsiVtConsole.NetCore.Examples.ANSI/AnsiVtConsole.NetCore.Examples.ANSI.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net6.0
6 | enable
7 | enable
8 | 1.0.21.0
9 | 1.0.21.0
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | contentFiles/any/;content/
25 | PreserveNewest
26 | true
27 | True
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Console/ActualWorkArea.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable CS1591
2 |
3 | namespace AnsiVtConsole.NetCore.Component.Console
4 | {
5 | ///
6 | /// acutal work area
7 | ///
8 | public sealed class ActualWorkArea
9 | {
10 | public readonly string Id;
11 | public readonly int Left;
12 | public readonly int Top;
13 | public readonly int Right;
14 | public readonly int Bottom;
15 |
16 | public ActualWorkArea(string id, int left, int top, int right, int bottom)
17 | {
18 | Id = id;
19 | Left = left;
20 | Right = right;
21 | Top = top;
22 | Bottom = bottom;
23 | }
24 |
25 | public void Deconstruct(out string id, out int left, out int top, out int right, out int bottom)
26 | {
27 | id = Id;
28 | left = Left;
29 | right = Right;
30 | top = Top;
31 | bottom = Bottom;
32 | }
33 | }
34 | }
35 | #pragma warning restore CS1591
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Console/Error.cs:
--------------------------------------------------------------------------------
1 | namespace AnsiVtConsole.NetCore.Component.Console;
2 |
3 | sealed class Error
4 | {
5 | readonly ConsoleTextWriterWrapper _out;
6 |
7 | public Error(ConsoleTextWriterWrapper outStream)
8 | => _out = outStream;
9 |
10 | public void Log(string text = "") => LogInternal(text, false);
11 |
12 | public void LogLine(string text = "") => LogInternal(text, true);
13 |
14 | public void LogLine(IEnumerable texts)
15 | {
16 | foreach (var s in texts)
17 | LogLine(s);
18 | }
19 |
20 | public void Log(IEnumerable texts)
21 | {
22 | foreach (var s in texts)
23 | Log(s);
24 | }
25 |
26 | void LogInternal(string text, bool lineBreak = false)
27 | {
28 | lock (_out.Lock!)
29 | {
30 | _out.RedirectToErr = true;
31 | if (!lineBreak)
32 | _out.Write(text);
33 | else
34 | _out.WriteLine(text);
35 | _out.RedirectToErr = false;
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Parser/NonRecursiveFunctionalGrammar/Rule.cs:
--------------------------------------------------------------------------------
1 | namespace AnsiVtConsole.NetCore.Component.Parser.NonRecursiveFunctionalGrammar
2 | {
3 | ///
4 | /// rule
5 | ///
6 | public sealed class Rule : List
7 | {
8 | static int _counter = 0;
9 | static readonly object _counterLock = new();
10 | #pragma warning disable CS1591
11 | public int ID;
12 |
13 | public TreePath TreePath;
14 |
15 | public string Key => TreePath.Key;
16 |
17 | #pragma warning disable CS8618
18 | public Rule() => Init();
19 | #pragma warning restore CS8618
20 |
21 | #pragma warning disable CS8618
22 | public Rule(IEnumerable range) : base(range) => Init();
23 | #pragma warning restore CS8618
24 | #pragma warning restore CS1591
25 |
26 | void Init()
27 | {
28 | TreePath = new TreePath(this, -1);
29 | lock (_counterLock)
30 | {
31 | ID = _counter;
32 | _counter++;
33 | }
34 | }
35 | }
36 | }
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Parser/NonRecursiveFunctionalGrammar/SyntacticBlockList.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable CS1591
2 |
3 | namespace AnsiVtConsole.NetCore.Component.Parser.NonRecursiveFunctionalGrammar
4 | {
5 | public sealed class SyntacticBlockList : List
6 | {
7 | public bool IsSelected;
8 |
9 | public SyntacticBlockList Clone()
10 | {
11 | var r = new SyntacticBlockList();
12 | r.AddRange(this);
13 | r.IsSelected = IsSelected;
14 | return r;
15 | }
16 |
17 | ///
18 | /// get the real length of the text without ansi sequences non printed characters
19 | ///
20 | /// length of visible part of the text
21 | public int GetTextLength() => GetText().Length;
22 |
23 | ///
24 | /// gets the text part of the syntactic elements
25 | ///
26 | /// string without ansi sequences
27 | public string GetText() => string.Join("", this.Where(x => !x.IsANSISequence).Select(x => x.Text));
28 | }
29 | }
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Parser/NonRecursiveFunctionalGrammar/SyntacticBlock.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable CS1591
2 |
3 | using AnsiVtConsole.NetCore.Component.Console;
4 |
5 | namespace AnsiVtConsole.NetCore.Component.Parser.NonRecursiveFunctionalGrammar
6 | {
7 | public sealed class SyntacticBlock
8 | {
9 | public string Text;
10 |
11 | public int Index;
12 |
13 | public TreePath? SyntacticRule;
14 |
15 | public bool IsSelected;
16 |
17 | public bool IsANSISequence;
18 |
19 | public SyntacticBlock(
20 | int index,
21 | TreePath? syntacticRule,
22 | string text,
23 | bool isSelected = false,
24 | bool isANSISequence = true)
25 | {
26 | Index = index;
27 | SyntacticRule = syntacticRule;
28 | Text = text;
29 | IsSelected = isSelected;
30 | IsANSISequence = isANSISequence;
31 | }
32 |
33 | public override string ToString() => $"{Index}->{Index + Text.Length - 1} : \"{ASCII.GetNonPrintablesCodesAsLabel(Text, false)}\" == {SyntacticRule}";
34 | }
35 | }
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Widgets/Texts/TypeWriting/TypeWriterOptionsBuilder.cs:
--------------------------------------------------------------------------------
1 | namespace AnsiVtConsole.NetCore.Component.Widgets.Texts.TypeWriting;
2 |
3 | ///
4 | /// type options writer builder
5 | ///
6 | public sealed class TypeWriterOptionsBuilder : AnimatedOptionsBuilder
7 | {
8 | ///
9 | /// type writer options builder
10 | ///
11 | /// type writer
12 | public TypeWriterOptionsBuilder(TypeWriter typeWriter)
13 | : base(typeWriter) { }
14 |
15 | ///
16 | /// cursor
17 | ///
18 | /// cursor
19 | /// this object
20 | public TypeWriterOptionsBuilder Cursor(string cursor)
21 | {
22 | Widget.SetCursor(cursor);
23 | return this;
24 | }
25 |
26 | ///
27 | /// text
28 | ///
29 | /// text
30 | /// this object
31 | public TypeWriterOptionsBuilder Text(string text)
32 | {
33 | Widget.SetText(text);
34 | return this;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/Examples/AnsiVtConsole.NetCore.Examples.Widgets/AnsiVtConsole.NetCore.Examples.Widgets.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net6.0
6 | enable
7 | enable
8 | 1.0.21.0
9 | 1.0.21.0
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | contentFiles/any/;content/
26 | PreserveNewest
27 | true
28 | True
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Widgets/Animatics/Animations/IntAnimation.cs:
--------------------------------------------------------------------------------
1 | using AnsiVtConsole.NetCore.Component.Widgets.Animatics.Easings;
2 |
3 | namespace AnsiVtConsole.NetCore.Component.Widgets.Animatics.Animations;
4 |
5 | ///
6 | /// int animation
7 | ///
8 | public sealed class IntAnimation : ValueAnimation
9 | {
10 | ///
11 | public IntAnimation(
12 | int from,
13 | int to,
14 | double duration,
15 | int increment = 1,
16 | Easing? easing = null) : base(from, to, duration, increment, easing) { }
17 |
18 | ///
19 | public IntAnimation(
20 | int to,
21 | double duration,
22 | int increment = 1,
23 | Easing? easing = null) : base(to, duration, increment, easing) { }
24 |
25 | ///
26 | public override void SetValueAt(double position)
27 | {
28 | var value = Math.Min(
29 | Math.Max(From, To),
30 | Math.Abs(To - From)
31 | * (position / Duration)
32 | + Math.Min(From, To)
33 | );
34 |
35 | var intValue = (int)Math.Max(
36 | Math.Min(From, To),
37 | value
38 | );
39 |
40 | SetValue(intValue);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Console/Inp.cs:
--------------------------------------------------------------------------------
1 | using sc = System.Console;
2 |
3 | namespace AnsiVtConsole.NetCore.Component.Console;
4 |
5 | ///
6 | /// input prompter
7 | ///
8 | public class Inp
9 | {
10 | readonly ConsoleTextWriterWrapper _out;
11 |
12 | ///
13 | /// output stream to be used for the prompt
14 | ///
15 | /// a console text writer
16 | public Inp(ConsoleTextWriterWrapper @out) => _out = @out;
17 |
18 | ///
19 | /// display a prompt and read a line from standard input
20 | ///
21 | /// prompt
22 | /// inputed line if any
23 | public string? Readln(string? prompt = null)
24 | {
25 | lock (_out.Lock!)
26 | {
27 | if (prompt != null)
28 | _out.Write(prompt);
29 | }
30 | return sc.ReadLine();
31 | }
32 |
33 | ///
34 | /// wait for a key to be pressed
35 | ///
36 | /// a prompt message or default if omitted
37 | public void WaitKeyPress(string? prompt = "press a key to continue...")
38 | {
39 | _out.WriteLine(prompt!);
40 | while (!sc.KeyAvailable)
41 | Thread.Yield();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore.CommandLine/Out.cs:
--------------------------------------------------------------------------------
1 |
2 | using CommandLine.NetCore.Services.CmdLine.Arguments;
3 | using CommandLine.NetCore.Services.CmdLine.Commands;
4 |
5 | namespace AnsiVtConsole.NetCore.CommandLine;
6 |
7 | class Out : Command
8 | {
9 | public Out(Dependencies dependencies) : base(dependencies)
10 | {
11 | }
12 |
13 | protected override CommandResult Execute(ArgSet args) =>
14 |
15 | // echo [--err]
16 |
17 | For(Param())
18 | .Do(() => OutAnsi)
19 |
20 | // echo --raw [--esc-only] [--hexa] [--err]
21 |
22 | .For(Param(), Opt("raw"), Opt("esc-only", true), Opt("hexa", true))
23 | .Do(() => OutRaw)
24 |
25 | .Options(Opt("err"))
26 |
27 | .With(args);
28 |
29 |
30 | void OutAnsi(Param textParam, Opt errOpt)
31 | => DoOut(textParam.Value!, errOpt.IsSet, false, false, false);
32 |
33 | void OutRaw(Param textParam, Opt errOpt, Opt escOpt, Opt hexaOpt)
34 | => DoOut(textParam.Value!, errOpt.IsSet, true, escOpt.IsSet, hexaOpt.IsSet);
35 |
36 | void DoOut(string text, bool err, bool raw, bool esc, bool hexa)
37 | {
38 | var console = new AnsiVtConsole();
39 |
40 | if (raw)
41 | text = console.Out.GetRawText(text, esc, hexa);
42 |
43 | if (!err)
44 | console.Out.WriteLine(text);
45 | else
46 | console.Logger.LogError(text);
47 | }
48 | }
--------------------------------------------------------------------------------
/Examples/AnsiVtConsole.NetCore.Examples.Widgets/Pages/Intro.cs:
--------------------------------------------------------------------------------
1 | namespace AnsiVtConsole.NetCore.Examples.Widgets.Pages;
2 |
3 | sealed class Intro : DemoPage
4 | {
5 | public override void Run()
6 | {
7 | TypeWriter("Welcome to the demonstration program of AnsiVtCore.NetCore")
8 | .Add(_)
9 | .Wait()
10 | .Wait(500);
11 |
12 | _.Out.WriteLine();
13 |
14 | TypeWrite("This program show examples of using (bon,b=green,f=white)WIDGETS components(tdoff)");
15 |
16 | _.Out.WriteLine();
17 |
18 | TypeWrite("Widgets are elements drawn on console with:(br)");
19 |
20 | _.Out.WriteLine();
21 |
22 | var dot = "(f=yellow)►(f=white)";
23 | TypeWrite($" {dot} live update");
24 | TypeWrite($" {dot} ANSI markup and sequences");
25 | TypeWrite($" {dot} animations");
26 | TypeWrite($" {dot} functionalities");
27 |
28 | _.Out.WriteLine();
29 |
30 | var remCol = "(tdoff,f=darkcyan)";
31 | var higCol = "(uon,bon,f=magenta)";
32 | TypeWrite($"{remCol}░ Widgets are composable together and the {higCol}Animator{remCol} class can animate any of their properties");
33 | TypeWrite($"{remCol}░ Widgets mecanism is {higCol}thread safe{remCol} thus several widgets can play simultaneously");
34 |
35 | _.Out.WriteLine().WriteLine();
36 |
37 | TypeWrite("░ this demo will auto play, juste have a seat and watch. Let's go now");
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Console/EchoSequenceList.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable CS1591
2 |
3 | using System.Collections;
4 | using System.Text;
5 |
6 | namespace AnsiVtConsole.NetCore.Component.Console
7 | {
8 | public sealed class EchoSequenceList : IEnumerable
9 | {
10 | public readonly List List
11 | = new();
12 |
13 | public void Add(EchoSequence printSequence) => List.Add(printSequence);
14 |
15 | public override string ToString()
16 | {
17 | var r = new StringBuilder();
18 | foreach (var printSequence in List)
19 | r.AppendLine(printSequence.ToString());
20 | return r.ToString();
21 | }
22 |
23 | public string ToStringPattern()
24 | {
25 | var r = new StringBuilder();
26 | foreach (var printSequence in List)
27 | r.Append(printSequence.ToStringPattern());
28 | return r.ToString();
29 | }
30 |
31 | public IEnumerator GetEnumerator() => List.GetEnumerator();
32 |
33 | IEnumerator IEnumerable.GetEnumerator() => List.GetEnumerator();
34 |
35 | public int TextLength
36 | {
37 | get
38 | {
39 | var n = 0;
40 | foreach (var seq in List)
41 | {
42 | if (seq.IsText)
43 | n += seq.Length;
44 | }
45 |
46 | return n;
47 | }
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Widgets/Texts/AnimatedText.cs:
--------------------------------------------------------------------------------
1 | namespace AnsiVtConsole.NetCore.Component.Widgets.Texts;
2 |
3 | ///
4 | /// animated text
5 | ///
6 | public sealed class AnimatedText : AnimatedWidget>
7 | {
8 | readonly Func _frameContent;
9 |
10 | ///
11 | /// animated text
12 | ///
13 | /// fps
14 | /// func that gives each frame content
15 | public AnimatedText(
16 | double fps,
17 | Func frameContent)
18 | : base(fps, new Text(string.Empty)) => _frameContent = frameContent;
19 |
20 | ///
21 | /// animated text
22 | ///
23 | /// cursor x
24 | /// cursor y
25 | /// fps
26 | /// func that gives each frame content
27 | public AnimatedText(
28 | int x,
29 | int y,
30 | double fps,
31 | Func frameContent)
32 | : base(x, y, fps, new Text(string.Empty))
33 | => _frameContent = frameContent;
34 |
35 | ///
36 | protected override bool IsEnd() => false;
37 |
38 | ///
39 | protected override void RenderFrame()
40 | => SetText(_frameContent());
41 |
42 | ///
43 | protected override string RenderWidget(string render)
44 | => render;
45 |
46 | ///
47 | protected override void StartInit() { }
48 | }
49 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Widgets/Texts/Text.cs:
--------------------------------------------------------------------------------
1 | namespace AnsiVtConsole.NetCore.Component.Widgets.Texts;
2 |
3 | ///
4 | /// text widget
5 | ///
6 | public sealed class Text : Widget>
7 | {
8 | string? _value;
9 | ///
10 | /// text
11 | ///
12 | public string Value
13 | {
14 | get => _value!;
15 | set
16 | {
17 | _value = value;
18 | TextChanged?.Invoke(this, new EventArgs());
19 | }
20 | }
21 |
22 | ///
23 | public override void SetText(string text)
24 | => Value = text;
25 |
26 | ///
27 | public override string GetText()
28 | => Value;
29 |
30 | ///
31 | /// text changed event
32 | ///
33 | public event EventHandler TextChanged;
34 |
35 | ///
36 | /// widget text
37 | ///
38 | /// cursor x
39 | /// cursor y
40 | /// text
41 | public Text(int x, int y, string text) : base(x, y)
42 | {
43 | Value = text;
44 | TextChanged += OnTextChanged;
45 | }
46 |
47 | ///
48 | /// widget text
49 | ///
50 | /// text
51 | public Text(string text) : base(null)
52 | {
53 | Value = text;
54 | TextChanged += OnTextChanged;
55 | }
56 |
57 | void OnTextChanged(object? sender, EventArgs e)
58 | {
59 | lock (Console!.Out.Lock)
60 | {
61 | Update();
62 | }
63 | }
64 |
65 | ///
66 | protected override string RenderWidget() => Value;
67 | }
68 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Widgets/Models/Rgb.cs:
--------------------------------------------------------------------------------
1 | namespace AnsiVtConsole.NetCore.Component.Widgets.Models;
2 |
3 | ///
4 | /// rgb color values
5 | ///
6 | public sealed class Rgb
7 | {
8 | int _r;
9 | ///
10 | /// red
11 | ///
12 | public int R
13 | {
14 | get => _r;
15 | set => _r = value;
16 | }
17 |
18 | int _g;
19 | ///
20 | /// green
21 | ///
22 | public int G
23 | {
24 | get => _g;
25 | set => _g = value;
26 | }
27 |
28 | int _b;
29 | ///
30 | /// blue
31 | ///
32 | public int B
33 | {
34 | get => _b;
35 | set => _b = value;
36 | }
37 |
38 | ///
39 | /// Rgb
40 | ///
41 | /// red
42 | /// green
43 | /// blue
44 | public Rgb(int r = 0, int g = 0, int b = 0)
45 | {
46 | _r = r;
47 | _g = g;
48 | _b = b;
49 | }
50 |
51 | ///
52 | /// set from another Rgb
53 | ///
54 | /// rgb
55 | /// this object
56 | public Rgb Set(Rgb rgb)
57 | {
58 | _r = rgb.R;
59 | _g = rgb.G;
60 | _b = rgb.B;
61 | return this;
62 | }
63 |
64 | ///
65 | /// set from rgb
66 | ///
67 | /// red
68 | /// green
69 | /// blue
70 | /// this object
71 | public Rgb Set(int r = 0, int g = 0, int b = 0)
72 | {
73 | _r = r;
74 | _g = g;
75 | _b = b;
76 | return this;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Widgets/IWidget.cs:
--------------------------------------------------------------------------------
1 | namespace AnsiVtConsole.NetCore.Component.Widgets;
2 |
3 | ///
4 | /// widget abstract
5 | ///
6 | public interface IWidget
7 | {
8 | ///
9 | /// wrapped widget
10 | ///
11 | IWidget? WrappedWidget { get; }
12 |
13 | ///
14 | /// set the text of the deepest wrapped widget in the hierarchy
15 | ///
16 | /// text
17 | void SetText(string text);
18 |
19 | ///
20 | /// get the text of the deepest wrapped widget in the hierarchy
21 | ///
22 | ///
23 | string GetText();
24 |
25 | ///
26 | /// fixed location X if any else location when rendered (origin 0)
27 | ///
28 | int X { get; }
29 |
30 | ///
31 | /// fixed location Y if any else else location when rendered (origin 0)
32 | ///
33 | int Y { get; }
34 |
35 | ///
36 | /// right location X after rendering (origin 0) else -1
37 | ///
38 | int RightX { get; }
39 |
40 | ///
41 | /// bottom location Y after rendering (origin 0) else -1
42 | ///
43 | int BottomY { get; }
44 |
45 | ///
46 | /// render the widget
47 | ///
48 | /// the console to render to
49 | /// the render of the widget
50 | string Render(IAnsiVtConsole console);
51 |
52 | ///
53 | /// update the display of the widget previously attached to a console (already rendered)
54 | ///
55 | void Update(bool shouldHideCursor = true);
56 |
57 | ///
58 | /// set parent widget
59 | ///
60 | /// parent
61 | void SetParent(IWidget parent);
62 | }
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Console/InputMap.cs:
--------------------------------------------------------------------------------
1 | namespace AnsiVtConsole.NetCore.Component.Console
2 | {
3 | sealed class InputMap
4 | {
5 | public const int ExactMatch = 0;
6 | public const int NoMatch = -1;
7 | public const int PartialMatch = 1;
8 |
9 | public readonly string? Text;
10 | public readonly object? Code;
11 | ///
12 | /// -1 : no match, 0 : exact match , 1: partial match
13 | ///
14 | public readonly Func? MatchInput;
15 | public readonly bool CaseSensitiveMatch;
16 |
17 | public InputMap(string text, bool caseSensitiveMatch = false)
18 | {
19 | Text = text;
20 | CaseSensitiveMatch = caseSensitiveMatch;
21 | }
22 |
23 | public InputMap(string text, object code, bool caseSensitiveMatch = false)
24 | {
25 | Text = text;
26 | Code = code;
27 | CaseSensitiveMatch = caseSensitiveMatch;
28 | }
29 |
30 | public InputMap(Func matchInput, object code)
31 | {
32 | MatchInput = matchInput;
33 | Code = code;
34 | }
35 |
36 | public int Match(string input, ConsoleKeyInfo key)
37 | {
38 | if (Text != null)
39 | {
40 | if (Text.Equals(input, CaseSensitiveMatch ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase))
41 | return ExactMatch;
42 | if (Text.StartsWith(input, CaseSensitiveMatch ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase))
43 | return PartialMatch;
44 | return NoMatch;
45 | }
46 | else
47 | {
48 | return (MatchInput == null) ? -1 : MatchInput(input, key);
49 | }
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Widgets/Bars/GradientBar.cs:
--------------------------------------------------------------------------------
1 | using AnsiVtConsole.NetCore.Component.Widgets.Texts.Coloring;
2 |
3 | namespace AnsiVtConsole.NetCore.Component.Widgets.Bars;
4 |
5 | ///
6 | /// animatable raimbow bar
7 | ///
8 | public sealed class GradientBar : Widget>
9 | {
10 | ///
11 | /// bar char
12 | ///
13 | public char BarChar { get; private set; } = DefaultBarChar;
14 |
15 | ///
16 | /// raimbow
17 | ///
18 | public Gradient Gradient => (Gradient)WrappedWidget!;
19 |
20 | const char DefaultBarChar = '─';
21 |
22 | ///
23 | /// length
24 | ///
25 | public int Length { get; private set; }
26 |
27 | ///
28 | /// gradient bar
29 | ///
30 | /// length
31 | /// character used to draw the bar
32 | public GradientBar(int length, char? barChar = null)
33 | : base(new Gradient(GetBarText(length, barChar ?? DefaultBarChar)))
34 | {
35 | Length = length;
36 | BarChar = barChar ?? DefaultBarChar;
37 | }
38 |
39 | ///
40 | /// gradient bar
41 | ///
42 | /// cursor x
43 | /// cursor y
44 | /// length
45 | /// character used to draw the bar
46 | public GradientBar(int x, int y, int length, char? barChar = null)
47 | : base(
48 | x,
49 | y,
50 | new Gradient(GetBarText(length, barChar ?? DefaultBarChar)))
51 | {
52 | Length = length;
53 | BarChar = barChar ?? DefaultBarChar;
54 | }
55 |
56 | static string GetBarText(int length, char barChar)
57 | => "".PadLeft(length, barChar);
58 |
59 | ///
60 | protected override string RenderWidget(string render)
61 | => render;
62 | }
63 |
--------------------------------------------------------------------------------
/Examples/AnsiVtConsole.NetCore.Examples.Widgets/Demo.cs:
--------------------------------------------------------------------------------
1 | using AnsiVtConsole.NetCore.Examples.Widgets.Pages;
2 |
3 | using static AnsiVtConsole.NetCore.Component.Console.ANSI;
4 |
5 | namespace AnsiVtConsole.NetCore.Examples.Widgets;
6 |
7 | sealed class Demo : DemoPage
8 | {
9 | readonly Title _title;
10 |
11 | readonly List<(DemoPage demo, int waitForNextPage)> _demos = new();
12 |
13 | readonly bool _isAutomatic = true;
14 | int _cursorTop;
15 | const int DefWait = 6;
16 |
17 | public Demo()
18 | {
19 | _title = new Title();
20 | _demos.AddRange(new List<(DemoPage, int)>()
21 | {
22 | (_title,0),
23 | (new Intro(),8),
24 | (new Images(),DefWait)
25 | });
26 | }
27 |
28 | public override void Run()
29 | {
30 | _.Out.ClearScreen();
31 | _.Out.HideCur();
32 |
33 | var lastDemo = _demos.Last().demo;
34 | do
35 | {
36 | foreach (var (demo, waitForNextPage) in _demos)
37 | {
38 | demo.Run(_);
39 | if (_cursorTop == 0)
40 | _cursorTop = _.Out.CursorTop;
41 |
42 | if (_isAutomatic)
43 | WaitBeforeNextPage(waitForNextPage);
44 | else
45 | WaitKeyBeforeNextPage();
46 | }
47 |
48 | _title.Animation!.Stop();
49 | _.Out.CursorHome();
50 | }
51 | while (true);
52 | }
53 |
54 | void WaitBeforeNextPage(int waitForNextPage)
55 | {
56 | _.Out.Write(DECTCEMShow);
57 | if (waitForNextPage > 0)
58 | WaitPage(waitForNextPage);
59 | NextPage();
60 | }
61 |
62 | void WaitKeyBeforeNextPage()
63 | {
64 | _.Out.Write(DECTCEMShow);
65 | _.Inp.WaitKeyPress();
66 | NextPage();
67 | }
68 |
69 | void NextPage() => _.Out.Write(
70 | CUP(1, _cursorTop + 1)
71 | + ED(0)
72 | + CUP(1, _cursorTop + 1)
73 | + DECTCEMShow);
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Widgets/Animatics/AnimationGroup.cs:
--------------------------------------------------------------------------------
1 | using System.Linq.Expressions;
2 |
3 | namespace AnsiVtConsole.NetCore.Component.Widgets.Animatics;
4 |
5 | ///
6 | /// value animation group - usefull to setup properties for a set of animations in one time
7 | ///
8 | public sealed class AnimationGroup
9 | {
10 | ///
11 | /// animations
12 | ///
13 | public IReadOnlyList Animations => _animations;
14 |
15 | readonly List _animations = new();
16 |
17 | ///
18 | /// animation group
19 | ///
20 | /// animations in the group
21 | public AnimationGroup(params IAnimation[] animations)
22 | => _animations.AddRange(animations);
23 |
24 | ///
25 | /// add target property of a class to animations in the group
26 | ///
27 | /// linq expression that reference the target property of an object: () => obj.a.b.. Expression0<Func<ValueTypeglt;>>
28 | /// this object
29 | public AnimationGroup For(LambdaExpression expression)
30 | {
31 | foreach (var anim in _animations)
32 | anim.For(expression);
33 | return this;
34 | }
35 |
36 | ///
37 | /// add target property of a class to animation in the group
38 | ///
39 | /// property name
40 | /// this object
41 | public AnimationGroup For(string propertyName)
42 | {
43 | foreach (var anim in _animations)
44 | anim.For(propertyName);
45 | return this;
46 | }
47 |
48 | ///
49 | /// setup target(s) for animations in the group
50 | ///
51 | /// one or several targets
52 | /// this object
53 | public AnimationGroup Target(params object[] targets)
54 | {
55 | foreach (var anim in _animations)
56 | anim.Target(targets);
57 | return this;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Console/StringSegment.cs:
--------------------------------------------------------------------------------
1 | using AnsiVtConsole.NetCore.Lib;
2 |
3 | namespace AnsiVtConsole.NetCore.Component.Console
4 | {
5 | sealed class StringSegment
6 | {
7 | public string Text { get; private set; }
8 | public int X { get; private set; }
9 | public int Y { get; private set; }
10 | public int Length { get; private set; }
11 |
12 | public Dictionary? Map;
13 |
14 | public void SetText(string text, bool updateCoords = false)
15 | {
16 | Text = text;
17 | if (updateCoords)
18 | {
19 | Length = text.Length;
20 | Y = X + Length;
21 | }
22 | }
23 |
24 | public StringSegment(string text, int x, int y, int length)
25 | {
26 | Text = text;
27 | X = x;
28 | Y = y;
29 | Length = length;
30 | }
31 |
32 | public StringSegment(string text, int x, int y)
33 | {
34 | Text = text;
35 | X = x;
36 | Y = y;
37 | Length = y - x + 1;
38 | }
39 |
40 | public StringSegment(string text, int x, int y, int length, Dictionary map)
41 | {
42 | Text = text;
43 | X = x;
44 | Y = y;
45 | Length = length;
46 | if (map != null && map.Count > 0)
47 | Map = new Dictionary { map };
48 | }
49 |
50 | public StringSegment(string text, int x, int y, Dictionary map)
51 | {
52 | Text = text;
53 | X = x;
54 | Y = y;
55 | Length = y - x + 1;
56 | if (map != null && map.Count > 0)
57 | Map = new Dictionary { map };
58 | }
59 |
60 | ///
61 | /// warn: this is intensively used in error messages...
62 | ///
63 | /// text representation of a StringSegment
64 | public override string ToString() =>
65 | //return $"pos={X},{Y} l={Length} Text={Text}"; // warn: this is intensively used in error messages...
66 | Text;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Lib/Process/ProcessCounter.cs:
--------------------------------------------------------------------------------
1 | namespace AnsiVtConsole.NetCore.Lib.Process
2 | {
3 | ///
4 | /// process counter usable with ProcessWrapper
5 | ///
6 | sealed class ProcessCounter
7 | {
8 | int _counter;
9 |
10 | readonly object _counterLock = new();
11 |
12 | public static bool Log { get; set; } = true;
13 |
14 | public int Counter
15 | {
16 | get
17 | {
18 | lock (_counterLock)
19 | {
20 | return _counter;
21 | }
22 | }
23 | }
24 |
25 | public int GetCounter() => _counter;
26 |
27 | public ProcessCounter() => _counter = 0;
28 |
29 | public void Increase()
30 | {
31 | lock (_counterLock)
32 | {
33 | _counter++;
34 | if (Log)
35 | System.Diagnostics.Debug.WriteLine("ProcessCounter:Increased = " + _counter);
36 | }
37 | }
38 |
39 | public void Decrease()
40 | {
41 | lock (_counterLock)
42 | {
43 | _counter--;
44 | if (Log)
45 | System.Diagnostics.Debug.WriteLine("ProcessCounter:Decreased = " + _counter);
46 | }
47 | }
48 |
49 | public void WaitForLessThan(int N)
50 | {
51 | if (Log)
52 | System.Diagnostics.Debug.WriteLine("ProcessCounter:WaitForLessThan " + N);
53 | var t = new Thread(() => WaitForLessThanNInternal(N));
54 | t.Start();
55 | t.Join();
56 | }
57 |
58 | void WaitForLessThanNInternal(int n)
59 | {
60 | var end = false;
61 | while (!end)
62 | {
63 | int v;
64 | lock (_counterLock)
65 | {
66 | v = GetCounter();
67 | if (v < n)
68 | end = true;
69 | if (!end)
70 | {
71 | Thread.Yield();
72 | Thread.Sleep(50);
73 | }
74 | }
75 | }
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/Examples/AnsiVtConsole.NetCore.Examples.Widgets/Pages/Title.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 |
3 | using AnsiVtConsole.NetCore.Component.Widgets.Animatics;
4 | using AnsiVtConsole.NetCore.Component.Widgets.Animatics.Animations;
5 | using AnsiVtConsole.NetCore.Component.Widgets.Bars;
6 | using AnsiVtConsole.NetCore.Component.Widgets.Texts.Coloring;
7 |
8 | namespace AnsiVtConsole.NetCore.Examples.Widgets.Pages;
9 |
10 | sealed class Title : DemoPage
11 | {
12 | public Animation? Animation { get; private set; }
13 |
14 | public override void Run()
15 | {
16 | var str = @"
17 | ___ _ __ __ _ ___ _ _ _ _ ___
18 | / \ _ _ ___(_)\ \ / /| |_ / __| ___ _ _ ___ ___ | | ___ | \| | ___ | |_ / __| ___ _ _ ___
19 | | - || ' \ (_-/| | \ / | _|| (__ / _ \| ' \ (_-// _ \| |/ -_) _ | . |/ -_)| _|| (__ / _ \| '_|/ -_)
20 | |_|_||_||_|/__/|_| \_/ \__| \___|\___/|_||_|/__/\___/|_|\___| (_) |_|\_|\___| \__| \___|\___/|_| \___|
21 | ";
22 | Gradient Setup(Gradient raimbow)
23 | => raimbow
24 | .Origin(0, 0, 128)
25 | .CyclicGradient(4, 9, 14);
26 |
27 | Gradient RaimbowText(string str)
28 | => Setup(new Gradient(str));
29 |
30 | var title = RaimbowText(str).Add(_);
31 |
32 | RaimbowText($" AnsiVtConsole.NetCore v{Assembly.GetExecutingAssembly().GetName().Version}").Add(_);
33 |
34 | _.Out.WriteLine();
35 |
36 | var bar = new GradientBar(113);
37 | Setup(bar.Gradient);
38 | bar.Add(_);
39 |
40 | _.Out.WriteLine();
41 | _.Out.WriteLine();
42 |
43 | var anims =
44 | new AnimationGroup(
45 | new IntAnimation(0, 255, 2000d)
46 | .For(() => bar.Gradient.OriginRGB.R),
47 | new IntAnimation(0, 255, 2000d)
48 | .For(() => bar.Gradient.OriginRGB.G),
49 | new IntAnimation(128, 255, 2000d)
50 | .For(() => bar.Gradient.OriginRGB.B))
51 | .Target(bar.Gradient.OriginRGB);
52 |
53 | Animation = new Animation()
54 | .Add(
55 | new TimeLine()
56 | .Loop()
57 | .AutoReverse()
58 | .Add(anims)
59 | .Update(bar)
60 | )
61 | .Start();
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | AnsiVtConsole.NetCore Copyright (c) 2023 franck gaspoz (franck.gaspoz@gmail.com)
2 | Licence Free MIT
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the « Software »), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED « AS IS », WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 |
22 | ------------------------------------------------------------------------------------------------------
23 |
24 | AnsiVtConsole.NetCore Copyright (c) 2023 franck gaspoz (franck.gaspoz@gmail.com)
25 | Licence Libre MIT
26 |
27 | L’autorisation est accordée, gracieusement, à toute personne acquérant une copie
28 | de ce logiciel et des fichiers de documentation associés (le « logiciel »), de commercialiser
29 | le logiciel sans restriction, notamment les droits d’utiliser, de copier, de modifier,
30 | de fusionner, de publier, de distribuer, de sous-licencier et / ou de vendre des copies du logiciel,
31 | ainsi que d’autoriser les personnes auxquelles la logiciel est fournie à le faire,
32 | sous réserve des conditions suivantes :
33 |
34 | La déclaration de copyright ci-dessus et la présente autorisation doivent être incluses dans
35 | toutes copies ou parties substantielles du logiciel.
36 |
37 | LE LOGICIEL EST FOURNI « TEL QUEL », SANS GARANTIE D’AUCUNE SORTE, EXPLICITE OU IMPLICITE,
38 | NOTAMMENT SANS GARANTIE DE QUALITÉ MARCHANDE, D’ADÉQUATION À UN USAGE PARTICULIER ET D’ABSENCE
39 | DE CONTREFAÇON. EN AUCUN CAS, LES AUTEURS OU TITULAIRES DU DROIT D’AUTEUR NE SERONT RESPONSABLES
40 | DE TOUT DOMMAGE, RÉCLAMATION OU AUTRE RESPONSABILITÉ, QUE CE SOIT DANS LE CADRE D’UN CONTRAT,
41 | D’UN DÉLIT OU AUTRE, EN PROVENANCE DE, CONSÉCUTIF À OU EN RELATION AVEC LE LOGICIEL OU SON UTILISATION,
42 | OU AVEC D’AUTRES ÉLÉMENTS DU LOGICIEL.
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/LICENSE.md:
--------------------------------------------------------------------------------
1 | AnsiVtConsole.NetCore Copyright (c) 2023 franck gaspoz (franck.gaspoz@gmail.com)
2 | Licence Free MIT
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the « Software »), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED « AS IS », WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 |
22 | ------------------------------------------------------------------------------------------------------
23 |
24 | AnsiVtConsole.NetCore Copyright (c) 2023 franck gaspoz (franck.gaspoz@gmail.com)
25 | Licence Libre MIT
26 |
27 | L’autorisation est accordée, gracieusement, à toute personne acquérant une copie
28 | de ce logiciel et des fichiers de documentation associés (le « logiciel »), de commercialiser
29 | le logiciel sans restriction, notamment les droits d’utiliser, de copier, de modifier,
30 | de fusionner, de publier, de distribuer, de sous-licencier et / ou de vendre des copies du logiciel,
31 | ainsi que d’autoriser les personnes auxquelles la logiciel est fournie à le faire,
32 | sous réserve des conditions suivantes :
33 |
34 | La déclaration de copyright ci-dessus et la présente autorisation doivent être incluses dans
35 | toutes copies ou parties substantielles du logiciel.
36 |
37 | LE LOGICIEL EST FOURNI « TEL QUEL », SANS GARANTIE D’AUCUNE SORTE, EXPLICITE OU IMPLICITE,
38 | NOTAMMENT SANS GARANTIE DE QUALITÉ MARCHANDE, D’ADÉQUATION À UN USAGE PARTICULIER ET D’ABSENCE
39 | DE CONTREFAÇON. EN AUCUN CAS, LES AUTEURS OU TITULAIRES DU DROIT D’AUTEUR NE SERONT RESPONSABLES
40 | DE TOUT DOMMAGE, RÉCLAMATION OU AUTRE RESPONSABILITÉ, QUE CE SOIT DANS LE CADRE D’UN CONTRAT,
41 | D’UN DÉLIT OU AUTRE, EN PROVENANCE DE, CONSÉCUTIF À OU EN RELATION AVEC LE LOGICIEL OU SON UTILISATION,
42 | OU AVEC D’AUTRES ÉLÉMENTS DU LOGICIEL.
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore.Imaging/LICENSE.md:
--------------------------------------------------------------------------------
1 | AnsiVtConsole.NetCore Copyright (c) 2023 franck gaspoz (franck.gaspoz@gmail.com)
2 | Licence Free MIT
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the « Software »), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED « AS IS », WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 |
22 | ------------------------------------------------------------------------------------------------------
23 |
24 | AnsiVtConsole.NetCore Copyright (c) 2023 franck gaspoz (franck.gaspoz@gmail.com)
25 | Licence Libre MIT
26 |
27 | L’autorisation est accordée, gracieusement, à toute personne acquérant une copie
28 | de ce logiciel et des fichiers de documentation associés (le « logiciel »), de commercialiser
29 | le logiciel sans restriction, notamment les droits d’utiliser, de copier, de modifier,
30 | de fusionner, de publier, de distribuer, de sous-licencier et / ou de vendre des copies du logiciel,
31 | ainsi que d’autoriser les personnes auxquelles la logiciel est fournie à le faire,
32 | sous réserve des conditions suivantes :
33 |
34 | La déclaration de copyright ci-dessus et la présente autorisation doivent être incluses dans
35 | toutes copies ou parties substantielles du logiciel.
36 |
37 | LE LOGICIEL EST FOURNI « TEL QUEL », SANS GARANTIE D’AUCUNE SORTE, EXPLICITE OU IMPLICITE,
38 | NOTAMMENT SANS GARANTIE DE QUALITÉ MARCHANDE, D’ADÉQUATION À UN USAGE PARTICULIER ET D’ABSENCE
39 | DE CONTREFAÇON. EN AUCUN CAS, LES AUTEURS OU TITULAIRES DU DROIT D’AUTEUR NE SERONT RESPONSABLES
40 | DE TOUT DOMMAGE, RÉCLAMATION OU AUTRE RESPONSABILITÉ, QUE CE SOIT DANS LE CADRE D’UN CONTRAT,
41 | D’UN DÉLIT OU AUTRE, EN PROVENANCE DE, CONSÉCUTIF À OU EN RELATION AVEC LE LOGICIEL OU SON UTILISATION,
42 | OU AVEC D’AUTRES ÉLÉMENTS DU LOGICIEL.
--------------------------------------------------------------------------------
/Examples/AnsiVtConsole.NetCore.Examples.ANSI/LICENSE.md:
--------------------------------------------------------------------------------
1 | AnsiVtConsole.NetCore Copyright (c) 2022 franck gaspoz (franck.gaspoz@gmail.com)
2 | Licence Free MIT
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the « Software »), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED « AS IS », WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 |
22 | ------------------------------------------------------------------------------------------------------
23 |
24 | AnsiVtConsole.NetCore Copyright (c) 2022 franck gaspoz (franck.gaspoz@gmail.com)
25 | Licence Libre MIT
26 |
27 | L’autorisation est accordée, gracieusement, à toute personne acquérant une copie
28 | de ce logiciel et des fichiers de documentation associés (le « logiciel »), de commercialiser
29 | le logiciel sans restriction, notamment les droits d’utiliser, de copier, de modifier,
30 | de fusionner, de publier, de distribuer, de sous-licencier et / ou de vendre des copies du logiciel,
31 | ainsi que d’autoriser les personnes auxquelles la logiciel est fournie à le faire,
32 | sous réserve des conditions suivantes :
33 |
34 | La déclaration de copyright ci-dessus et la présente autorisation doivent être incluses dans
35 | toutes copies ou parties substantielles du logiciel.
36 |
37 | LE LOGICIEL EST FOURNI « TEL QUEL », SANS GARANTIE D’AUCUNE SORTE, EXPLICITE OU IMPLICITE,
38 | NOTAMMENT SANS GARANTIE DE QUALITÉ MARCHANDE, D’ADÉQUATION À UN USAGE PARTICULIER ET D’ABSENCE
39 | DE CONTREFAÇON. EN AUCUN CAS, LES AUTEURS OU TITULAIRES DU DROIT D’AUTEUR NE SERONT RESPONSABLES
40 | DE TOUT DOMMAGE, RÉCLAMATION OU AUTRE RESPONSABILITÉ, QUE CE SOIT DANS LE CADRE D’UN CONTRAT,
41 | D’UN DÉLIT OU AUTRE, EN PROVENANCE DE, CONSÉCUTIF À OU EN RELATION AVEC LE LOGICIEL OU SON UTILISATION,
42 | OU AVEC D’AUTRES ÉLÉMENTS DU LOGICIEL.
--------------------------------------------------------------------------------
/Examples/AnsiVtConsole.NetCore.Examples.Widgets/LICENSE.md:
--------------------------------------------------------------------------------
1 | AnsiVtConsole.NetCore Copyright (c) 2022 franck gaspoz (franck.gaspoz@gmail.com)
2 | Licence Free MIT
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the « Software »), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED « AS IS », WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 |
22 | ------------------------------------------------------------------------------------------------------
23 |
24 | AnsiVtConsole.NetCore Copyright (c) 2022 franck gaspoz (franck.gaspoz@gmail.com)
25 | Licence Libre MIT
26 |
27 | L’autorisation est accordée, gracieusement, à toute personne acquérant une copie
28 | de ce logiciel et des fichiers de documentation associés (le « logiciel »), de commercialiser
29 | le logiciel sans restriction, notamment les droits d’utiliser, de copier, de modifier,
30 | de fusionner, de publier, de distribuer, de sous-licencier et / ou de vendre des copies du logiciel,
31 | ainsi que d’autoriser les personnes auxquelles la logiciel est fournie à le faire,
32 | sous réserve des conditions suivantes :
33 |
34 | La déclaration de copyright ci-dessus et la présente autorisation doivent être incluses dans
35 | toutes copies ou parties substantielles du logiciel.
36 |
37 | LE LOGICIEL EST FOURNI « TEL QUEL », SANS GARANTIE D’AUCUNE SORTE, EXPLICITE OU IMPLICITE,
38 | NOTAMMENT SANS GARANTIE DE QUALITÉ MARCHANDE, D’ADÉQUATION À UN USAGE PARTICULIER ET D’ABSENCE
39 | DE CONTREFAÇON. EN AUCUN CAS, LES AUTEURS OU TITULAIRES DU DROIT D’AUTEUR NE SERONT RESPONSABLES
40 | DE TOUT DOMMAGE, RÉCLAMATION OU AUTRE RESPONSABILITÉ, QUE CE SOIT DANS LE CADRE D’UN CONTRAT,
41 | D’UN DÉLIT OU AUTRE, EN PROVENANCE DE, CONSÉCUTIF À OU EN RELATION AVEC LE LOGICIEL OU SON UTILISATION,
42 | OU AVEC D’AUTRES ÉLÉMENTS DU LOGICIEL.
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore.CommandLine/LICENSE.md:
--------------------------------------------------------------------------------
1 | AnsiVtConsole.NetCore Copyright (c) December 2022 franck gaspoz (franck.gaspoz@gmail.com)
2 | Licence Free MIT
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the « Software »), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED « AS IS », WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 |
22 | ------------------------------------------------------------------------------------------------------
23 |
24 | AnsiVtConsole.NetCore Copyright (c) December 2022 franck gaspoz (franck.gaspoz@gmail.com)
25 | Licence Libre MIT
26 |
27 | L’autorisation est accordée, gracieusement, à toute personne acquérant une copie
28 | de ce logiciel et des fichiers de documentation associés (le « logiciel »), de commercialiser
29 | le logiciel sans restriction, notamment les droits d’utiliser, de copier, de modifier,
30 | de fusionner, de publier, de distribuer, de sous-licencier et / ou de vendre des copies du logiciel,
31 | ainsi que d’autoriser les personnes auxquelles la logiciel est fournie à le faire,
32 | sous réserve des conditions suivantes :
33 |
34 | La déclaration de copyright ci-dessus et la présente autorisation doivent être incluses dans
35 | toutes copies ou parties substantielles du logiciel.
36 |
37 | LE LOGICIEL EST FOURNI « TEL QUEL », SANS GARANTIE D’AUCUNE SORTE, EXPLICITE OU IMPLICITE,
38 | NOTAMMENT SANS GARANTIE DE QUALITÉ MARCHANDE, D’ADÉQUATION À UN USAGE PARTICULIER ET D’ABSENCE
39 | DE CONTREFAÇON. EN AUCUN CAS, LES AUTEURS OU TITULAIRES DU DROIT D’AUTEUR NE SERONT RESPONSABLES
40 | DE TOUT DOMMAGE, RÉCLAMATION OU AUTRE RESPONSABILITÉ, QUE CE SOIT DANS LE CADRE D’UN CONTRAT,
41 | D’UN DÉLIT OU AUTRE, EN PROVENANCE DE, CONSÉCUTIF À OU EN RELATION AVEC LE LOGICIEL OU SON UTILISATION,
42 | OU AVEC D’AUTRES ÉLÉMENTS DU LOGICIEL.
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/IAnsiVtConsole.cs:
--------------------------------------------------------------------------------
1 | using AnsiVtConsole.NetCore.Component.Console;
2 | using AnsiVtConsole.NetCore.Component.Settings;
3 |
4 | namespace AnsiVtConsole.NetCore;
5 |
6 | ///
7 | /// AnsiVtConsole interface
8 | ///
9 | public interface IAnsiVtConsole
10 | {
11 | ///
12 | /// settings of the console
13 | ///
14 | public AnsiVtConsoleSettings Settings { get; }
15 |
16 | ///
17 | /// work area settings
18 | ///
19 | public WorkAreaSettings WorkAreaSettings { get; }
20 |
21 | ///
22 | /// input prompter
23 | ///
24 | public Inp Inp { get; }
25 |
26 | ///
27 | /// default colors and predefined colors sets
28 | ///
29 | ColorSettings Colors { get; }
30 |
31 | ///
32 | /// system standard err stream wrapper
33 | ///
34 | TextWriterWrapper StdErr { get; }
35 |
36 | ///
37 | /// standard input stream
38 | ///
39 | TextReader In { get; }
40 |
41 | ///
42 | /// cursor controler
43 | ///
44 | Cursor Cursor { get; }
45 |
46 | ///
47 | /// output stream
48 | ///
49 | ConsoleTextWriterWrapper Out { get; }
50 |
51 | ///
52 | /// work area
53 | ///
54 | WorkArea WorkArea { get; }
55 |
56 | ///
57 | /// logger
58 | ///
59 | Logger Logger { get; }
60 |
61 | ///
62 | /// terminates current process
63 | ///
64 | /// return code
65 | void Exit(int r = 0);
66 |
67 | ///
68 | /// output infos about the system and the console host
69 | ///
70 | void Infos();
71 |
72 | ///
73 | /// redirects outputs to a file
74 | ///
75 | /// file path - set null to disable redirect
76 | void RedirectErr(string? filepath = null);
77 |
78 | ///
79 | /// redirects errors to a stream writer
80 | ///
81 | /// stream writer - set null to disable redirect
82 | void RedirectErr(StreamWriter? sw);
83 |
84 | ///
85 | /// redirects outputs to a file
86 | ///
87 | /// file path - set null to disable redirect
88 | void RedirectOut(string? filepath = null);
89 |
90 | ///
91 | /// redirects outputs to a stream writer
92 | ///
93 | /// stream writer - set null to disable redirect
94 | void RedirectOut(StreamWriter? sw);
95 | }
96 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/Examples/AnsiVtConsole.NetCore.Examples.Widgets/DemoPage.cs:
--------------------------------------------------------------------------------
1 | using AnsiVtConsole.NetCore.Component.Widgets.Texts;
2 | using AnsiVtConsole.NetCore.Component.Widgets.Texts.Timers;
3 | using AnsiVtConsole.NetCore.Component.Widgets.Texts.TypeWriting;
4 |
5 | using static AnsiVtConsole.NetCore.Component.Console.ANSI;
6 |
7 | namespace AnsiVtConsole.NetCore.Examples.Widgets;
8 |
9 | abstract class DemoPage
10 | {
11 | #pragma warning disable CS8618
12 | protected IAnsiVtConsole _;
13 | #pragma warning restore CS8618
14 |
15 | public void Run(IAnsiVtConsole console)
16 | {
17 | _ = console;
18 | Run();
19 | }
20 |
21 | protected static TypeWriter TypeWriter(string text)
22 | => new(
23 | $"{SGR_SetForegroundColor4bits(SGR_4BitsColors.White, true)}{text}",
24 | 10000,
25 | $"{SGR_SetForegroundColor4bits(SGR_4BitsColors.Green, true)}█(rsf)");
26 |
27 | protected TypeWriter TypeWrite(string text)
28 | => TypeWriter(text).Add(_).Wait();
29 |
30 | public abstract void Run();
31 |
32 | protected static void Wait(int delay) => Thread.Sleep(delay);
33 |
34 | protected void WaitPage(int waitForNextPage)
35 | {
36 | PleaseWait(waitForNextPage);
37 | Thread.Sleep(waitForNextPage * 1000);
38 | }
39 |
40 | protected void SubTitle(string text)
41 | {
42 | TypeWrite($"(f=white){text}");
43 | _.Out.WriteLine();
44 | }
45 |
46 | protected void PleaseWait(int waitForNextPage)
47 | {
48 | _.Out.WriteLine().WriteLine();
49 |
50 | var tipsAnim = TipsAnim();
51 |
52 | var tt = new TextTimer(
53 | tipsAnim.RightX + 1,
54 | tipsAnim.BottomY,
55 | "(bkf,f=yellow)This page will automatically update in {0}(f=yellow) seconds...(rsf)",
56 | 2,
57 | TimeSpan.FromSeconds(waitForNextPage * 100),
58 | (duration) => GetDurationText(duration))
59 | .Add(_!);
60 | tt
61 | .OnStop += (o, e) => tipsAnim.Stop();
62 | tt.Wait();
63 | }
64 |
65 | protected AnimatedText TipsAnim()
66 | => new AnimatedText(5, () => GetTipsFrame())
67 | .Add(_!);
68 |
69 | int _tipIndex = 0;
70 | static readonly string[] _tipsFrames = new string[]
71 | {
72 | "► ",
73 | " ► ",
74 | " ►"
75 | };
76 |
77 | string GetTipsFrame()
78 | {
79 | var tip = _tipsFrames[_tipIndex++];
80 | _tipIndex %= 3;
81 | return tip;
82 | }
83 |
84 | static string GetDurationText(TimeSpan duration)
85 | {
86 | var seconds = duration.TotalSeconds;
87 | var text = seconds.ToString();
88 | var col = "";
89 | if (seconds <= 5) col = "(f=darkyellow)";
90 | if (seconds <= 3) col = "(f=red)";
91 | return col + text;
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Widgets/Animatics/Animation.cs:
--------------------------------------------------------------------------------
1 | namespace AnsiVtConsole.NetCore.Component.Widgets.Animatics;
2 |
3 | ///
4 | /// animation
5 | /// run parallely values animations grouped in one time line
6 | /// run sequencially times lines
7 | ///
8 | public sealed class Animation
9 | {
10 | ///
11 | /// animatables
12 | ///
13 | public IReadOnlyList TimeLines
14 | => _timeLines;
15 |
16 | readonly List _timeLines = new();
17 |
18 | double _fps = 10;
19 | ///
20 | /// frame per seconds
21 | ///
22 | public double Fps
23 | {
24 | get => _fps;
25 | set
26 | {
27 | if (IsRunning)
28 | throw new InvalidOperationException("can't change fps when running");
29 | _fps = value;
30 | }
31 | }
32 |
33 | ///
34 | /// is running
35 | ///
36 | public bool IsRunning { get; private set; }
37 |
38 | readonly Animator _animator;
39 |
40 | ///
41 | /// animation
42 | ///
43 | /// frames per seconds (default 10)
44 | public Animation(double? fps = null)
45 | {
46 | _animator = new(this);
47 | _fps = fps ?? 10;
48 | }
49 |
50 | ///
51 | /// add a time line to the animation
52 | ///
53 | /// time line
54 | /// this object
55 | public Animation Add(TimeLine timeline)
56 | {
57 | _timeLines.Add(timeline);
58 | return this;
59 | }
60 |
61 | ///
62 | /// starts animation
63 | ///
64 | /// this object
65 | public Animation Start()
66 | {
67 | _animator.OnStart += OnStart;
68 | _animator.OnStop += OnStop;
69 | _animator.Start();
70 | return this;
71 | }
72 |
73 | void OnStart(object? o, EventArgs e) => IsRunning = true;
74 |
75 | ///
76 | /// starts animation
77 | ///
78 | /// this object
79 | public Animation Stop()
80 | {
81 | _animator.Stop();
82 | return this;
83 | }
84 |
85 | void OnStop(object? o, EventArgs e)
86 | {
87 | IsRunning = false;
88 | _animator.OnStart -= OnStart;
89 | _animator.OnStop -= OnStop;
90 | }
91 |
92 | ///
93 | /// wait end of animation. blocks current thread
94 | ///
95 | /// this object
96 | public Animation Wait()
97 | {
98 | while (IsRunning)
99 | {
100 | Thread.Yield();
101 | }
102 | return this;
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Parser/ANSI/ANSIParser.cs:
--------------------------------------------------------------------------------
1 | using AnsiVtConsole.NetCore.Component.Parser.NonRecursiveFunctionalGrammar;
2 |
3 | namespace AnsiVtConsole.NetCore.Component.Parser.ANSI
4 | {
5 | ///
6 | /// ANSI parser. Use grammar defined in Component/Parser/ANSI/ansi-seq-patterns.txt
7 | ///
8 | public static class ANSIParser
9 | {
10 | #region attributes
11 |
12 | ///
13 | /// the grammar file name that must be loaded
14 | ///
15 | public const string GrammarFileName = "ansi-seq-patterns.txt";
16 |
17 | static readonly NonRecursiveFunctionGrammarParser _parser;
18 |
19 | #endregion
20 |
21 | #region init
22 |
23 | static ANSIParser()
24 | {
25 | var ap = System.Reflection.Assembly.GetExecutingAssembly().Location;
26 | var p = Path.Combine(
27 | Path.GetDirectoryName(ap)!,
28 | "Component",
29 | "Parser",
30 | "ANSI",
31 | GrammarFileName);
32 | var lines = File.ReadLines(p);
33 | _parser = new NonRecursiveFunctionGrammarParser(lines);
34 | }
35 |
36 | #endregion
37 |
38 | ///
39 | /// get the syntax block list of a text
40 | ///
41 | /// text to be parsed
42 | /// syntax block list
43 | public static SyntacticBlockList Parse(string s) => _parser.Parse(s);
44 |
45 | ///
46 | /// get the real length of the text without ansi sequences non printed characters
47 | ///
48 | /// text to be analyzed
49 | /// length of visible part of the text
50 | public static int GetTextLength(string s) => GetText(s).Length;
51 |
52 | ///
53 | /// gets the text part of the syntactic elements
54 | ///
55 | /// text to be analyzed
56 | /// string without ansi sequences
57 | public static string GetText(string s) => _parser.Parse(s).GetText();
58 |
59 | ///
60 | /// indicates wether or not a string starts with a known ansi sequence. the parsed syntax is assigned in the out parameter 'syntax'
61 | ///
62 | /// text to be parsed
63 | /// parsed syntax
64 | /// true if the given text starts with a known ansi sequence.
65 | public static bool StartsWithANSISequence(string s, out SyntacticBlockList syntax)
66 | {
67 | syntax = _parser.Parse(s);
68 | if (syntax.Count == 0)
69 | return false;
70 | return syntax[0].IsANSISequence;
71 | }
72 | }
73 | }
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Console/Cursor.cs:
--------------------------------------------------------------------------------
1 |
2 | using sc = System.Console;
3 | namespace AnsiVtConsole.NetCore.Component.Console;
4 |
5 | ///
6 | /// cursor control
7 | ///
8 | public class Cursor
9 | {
10 | readonly IAnsiVtConsole _console;
11 |
12 | ///
13 | /// a cursor attached to a console and an output stream
14 | ///
15 | /// console
16 | public Cursor(IAnsiVtConsole console) => _console = console;
17 |
18 | ///
19 | /// fix coordianates according to the console buffer size
20 | ///
21 | /// x
22 | /// y
23 | public void FixCoords(ref int x, ref int y)
24 | {
25 | lock (_console.Out.Lock!)
26 | {
27 | x = Math.Max(0, Math.Min(x, sc.BufferWidth - 1));
28 | y = Math.Max(0, Math.Min(y, sc.BufferHeight - 1));
29 | }
30 | }
31 |
32 | ///
33 | /// get an int value from a x string coordinate or the real cursor position if no or not valid parameter
34 | ///
35 | /// x
36 | /// x
37 | public int GetCursorX(object? x = null)
38 | {
39 | if (x != null && x is string s && !string.IsNullOrWhiteSpace(s))
40 | {
41 | if (int.TryParse(s, out var v))
42 | return v;
43 | else
44 | {
45 | if (_console.Settings.TraceCommandErrors)
46 | _console.Logger.LogError($"wrong cursor x: {x}");
47 | }
48 | }
49 | if (!_console.WorkArea.IsConsoleGeometryEnabled)
50 | return 0;
51 |
52 | lock (_console.Out.Lock!)
53 | {
54 | return sc.CursorLeft;
55 | }
56 | }
57 |
58 | ///
59 | /// get an int value from a y string coordinate or the real cursor position if no or not valid parameter
60 | ///
61 | /// y
62 | /// y
63 | public int GetCursorY(object? x = null)
64 | {
65 | if (x != null && x is string s && !string.IsNullOrWhiteSpace(s))
66 | {
67 | if (int.TryParse(s, out var v))
68 | return v;
69 | else
70 | {
71 | if (_console.Settings.TraceCommandErrors)
72 | _console.Logger.LogError($"wrong cursor y: {x}");
73 | }
74 | }
75 | if (!_console.WorkArea.IsConsoleGeometryEnabled)
76 | return 0;
77 |
78 | lock (_console.Out.Lock!)
79 | {
80 | return sc.CursorTop;
81 | }
82 | }
83 |
84 | ///
85 | /// hide cursor (not thread safe)
86 | ///
87 | public void Hide() => sc.CursorVisible = false;
88 |
89 | ///
90 | /// show cursor (not thread safe)
91 | ///
92 | public void Show() => sc.CursorVisible = true;
93 | }
94 |
--------------------------------------------------------------------------------
/AnsiVtConsole.NetCore/Component/Script/CSharpScriptEngine.cs:
--------------------------------------------------------------------------------
1 | using AnsiVtConsole.NetCore.Component.Console;
2 |
3 | using Microsoft.CodeAnalysis.CSharp.Scripting;
4 | using Microsoft.CodeAnalysis.Scripting;
5 |
6 | namespace AnsiVtConsole.NetCore.Component.Script
7 | {
8 | ///
9 | /// c# script engine
10 | ///
11 | public sealed class CSharpScriptEngine
12 | {
13 | readonly Dictionary> _csscripts = new();
14 |
15 | ///
16 | /// default script options
17 | ///
18 | public ScriptOptions DefaultScriptOptions;
19 |
20 | #pragma warning disable CS8618
21 |
22 | ///
23 | /// CSharpScriptEngine
24 | ///
25 | ///
26 | public CSharpScriptEngine(IAnsiVtConsole console) => Init(console);
27 |
28 | #pragma warning restore CS8618
29 |
30 | ///
31 | /// CSharpScriptEngine
32 | ///
33 | ///
34 | ///
35 | public CSharpScriptEngine(IAnsiVtConsole console, ScriptOptions defaultScriptOptions)
36 | {
37 | DefaultScriptOptions = defaultScriptOptions;
38 | Init(console);
39 | }
40 |
41 | void Init(IAnsiVtConsole console)
42 | {
43 | DefaultScriptOptions ??= ScriptOptions.Default;
44 | DefaultScriptOptions = DefaultScriptOptions
45 | .AddImports("System")
46 | .AddReferences(console.GetType().Assembly);
47 | }
48 |
49 | ///
50 | /// execute a csharp script
51 | ///
52 | /// source code
53 | /// output
54 | /// script options
55 | /// script return value
56 | public object? ExecCSharp(
57 | string csharpText,
58 | ConsoleTextWriterWrapper @out,
59 | ScriptOptions? scriptOptions = null
60 | )
61 | {
62 | try
63 | {
64 | scriptOptions ??= DefaultScriptOptions;
65 | var scriptKey = csharpText;
66 | if (!_csscripts.TryGetValue(scriptKey, out var script))
67 | {
68 | script = CSharpScript.Create