Giter VIP home page Giter VIP logo

Comments (9)

ividyon avatar ividyon commented on May 30, 2024 1

Looks like a great solution! I guess I'd call it something simpler like EscapeColorTokens or EscapeStyleCharacters, but yeah.

from promptplus.

FRACerqueira avatar FRACerqueira commented on May 30, 2024 1

@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:

Captura de tela 2023-09-19 171806

from promptplus.

FRACerqueira avatar FRACerqueira commented on May 30, 2024

@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.

ividyon avatar ividyon commented on May 30, 2024

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.

FRACerqueira avatar FRACerqueira commented on May 30, 2024

@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.

FRACerqueira avatar FRACerqueira commented on May 30, 2024

Good name for this feature!

from promptplus.

FRACerqueira avatar FRACerqueira commented on May 30, 2024

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.

ividyon avatar ividyon commented on May 30, 2024

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.

ividyon avatar ividyon commented on May 30, 2024

Looks great!

from promptplus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.