Comments (9)
Looks like a great solution! I guess I'd call it something simpler like EscapeColorTokens
or EscapeStyleCharacters
, but yeah.
from promptplus.
@ividyon , See the changes, what do you think??
//standard
PromptPlus.DoubleDash($"PromptPlus IgnoreColorTokens = false - Default value and usage");
PromptPlus.WriteLine("Valid[[]]formedColor_TokenAny[[RED ON WHITE]]Text[[/]]_[[YELLOW]]Othertext[[/]]");
PromptPlus.WriteLine("ValidformedColor_TokenAny[RED ON WHITE]Text[/]_[YELLOW]Othertext[/]");
PromptPlus.DoubleDash($"PromptPlus IgnoreColorTokens = true");
//global change IgnoreColorTokens
PromptPlus.IgnoreColorTokens = true;
//show text with no color!
PromptPlus.WriteLine("Valid[]formedColor_TokenAny[RED ON WHITE]Text[/]_[YELLOW]Othertext[/]");
//create context to IgnoreColorTokens = false
using (PromptPlus.AcceptColorTokens())
{
PromptPlus.DoubleDash($"PromptPlus with context IgnoreColorTokens = false");
//show text with color!
PromptPlus.WriteLine("ValidformedColor_TokenAny[RED ON WHITE]Text[/]_[YELLOW]Othertext[/]");
}
PromptPlus.IgnoreColorTokens = false;
//create context to IgnoreColorTokens = true
using (PromptPlus.EscapeColorTokens())
{
PromptPlus.DoubleDash($"PromptPlus with context IgnoreColorTokens = true");
//show text with color
PromptPlus.WriteLine("ValidformedColor_TokenAny[RED ON WHITE]Text[/]_[YELLOW]Othertext[/]");
}
//restore original value IgnoreColorTokens
output:
from promptplus.
@ividyon , hi!
PromptPlus also has commands for coloring parts of text. To know the colored parts of the text, the characters '[' and ']' are used to delimit the color commands. (https://fracerqueira.github.io/PromptPlus/#colors)
I will investigate a way to have a global functionality to define these delimiters so as not to have an overhead for the end user.
To get around this problem you must use '[[' and ']]'
Maybe an extension like: PromptPlus.RawWriteLine / PromptPlus.RawWrite to skip color engine parse
from promptplus.
Being able to provide an optional parameter to output methods like WriteLine, DoubleDash etc. which runs an inbuilt replacer for [
and ]
(and other control characters PromptPlus may have) would be ideal, as well as public API access to such a filter function.
For now I wrote my own string extension for it:
public static class StringExtensions
{
public static string PromptPlusEscape(this string str)
{
return str.Replace("[", "[[").Replace("]", "]]");
}
}
But ideally such a thing should not be "polluting" the string function space, but rather be self-contained within PromptPlus.
from promptplus.
@ividyon , 'm working on this implementation.
The implementation so far looks like this:
//local change AcceptMalformedColorToken
using (PromptPlus.IgnoreMalformedColorToken())
{
PromptPlus.WriteLine("MalformedColorToken_AnyText[c4201]_Othertext");
PromptPlus.WriteLine("ValidformedColorToken_Any[RED ON WHITE]Text[/]_[YELLOW]Othertext[/]");
}
//global change AcceptMalformedColorToken
PromptPlus.AcceptMalformedColorToken = true;
.
.
.
PromptPlus.WriteLine("MalformedColorToken_AnyText[c4201]_Othertext[/]");
PromptPlus.WriteLine("ValidformedColorToken_Any[RED ON WHITE]Text[/]_[YELLOW]Othertext[/]");
.
.
.
PromptPlus.AcceptMalformedColorToken = false;
from promptplus.
Good name for this feature!
from promptplus.
Fixed scheduled for publication 4.0.6:
//global change IgnoreErrorColorTokens
PromptPlus.IgnoreErrorColorTokens = true;
//write text with char token
PromptPlus.WriteLine("MalformedColorToken_AnyText[c4201]_Othertext[/]");
//show text with color
PromptPlus.WriteLine("ValidformedColor_TokenAny[RED ON WHITE]Text[/]_[YELLOW]Othertext[/]");
PromptPlus.IgnoreErrorColorTokens = false;
//change local IgnoreErrorColorTokens
using (PromptPlus.EscapeColorTokens())
{
//write text with char token
PromptPlus.WriteLine("MalformedColor_TokenAnyText[c4201]_Othertext");
//show text with color
PromptPlus.WriteLine("ValidformedColor_TokenAny[RED ON WHITE]Text[/]_[YELLOW]Othertext[/]");
}
//restore original value IgnoreErrorColorTokens
from promptplus.
Is it possible to have this in reverse?
So, if color tokens are set to be ignored globally, have a "using" clause that enables them within it.
Also I realized that, if you're actually ignoring the tokens instead of escaping them with [[, then "escape" isn't really the right term, Ignore would be.
So "IgnoreColorTokens" and "AcceptColorTokens".
from promptplus.
Looks great!
from promptplus.
Related Issues (20)
- Add command HideRange to not show range in the Slider Control
- Add Styles command for custom colors on all controls
- Table control does not render correctly when it does not support Unicode
- Refinement of Unicode symbol rendering in all controls
- Optional value refinement for generic class
- Optimize the WaitControl control (for cancel correctly tasks)
- Remove Control Pipeline to use PipeAndFilter component
- PromptPlus output becomes messy from inside Parallel.ForEach or Parallel.Invoke functions HOT 4
- PromptPlus output ignores moved cursor position by asynchronous operations
- PromptPlus.WriteLine does not print stringified JSON HOT 1
- Exception when try delete[F3] in empty colletion in AddTolist/AddtoMaskEditList control
- Edit[F2] Immutable item in AddTolist/AddtoMaskEditList control
- CTRL-V (paste data) does not show input in some controls
- Add TargetFramework .NET8
- Review method names for clarity
- Review EastAsia-Width function (Better understand how it works and research implementations) HOT 1
- Color Token accepts ':' to separate foreground color from background color
- Review Licences and Credits
- Add command Styles for custom color in the WaitProcess/WaitTime control
- Add global StyleSchema Ranger/Lines for custom color
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from promptplus.