Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Feature: Add the ability to parse text into spans - #140

Merged
dantleech merged 28 commits into
php-tui:mainfrom
KennedyTedesco:span-parser
Nov 19, 2023
Merged

Feature: Add the ability to parse text into spans#140
dantleech merged 28 commits into
php-tui:mainfrom
KennedyTedesco:span-parser

Conversation

@KennedyTedesco

@KennedyTedesco KennedyTedesco commented Nov 19, 2023

Copy link
Copy Markdown
Contributor

Following: #136

With this new implementation, users now have two options for formatting their texts:

  1. Using style methods
  2. Parsing directly

So, this style:

image

Can be achieved by doing either:

Line::fromSpans([
    Span::fromString('Hello ')->black()->onBlue()->bold()->italic(),
    Span::fromString('Wor')->white()->onRed()->crossedout(),
    Span::fromString('ld')->black()->onBlue()->bold()->italic(),
    Span::fromString(' PHP'),
]),

or:

Line::parse('<fg=black;bg=blue;options=bold,italic>Hello <fg=white;bg=red;options=crossedout>Wor</>ld</> PHP')

Other examples:

// Style methods
$title = Title::fromLine(Line::fromSpans([
    Span::fromString('Titles')->red()->onWhite(),
]));

// Parsing instead:
$title = Title::parse('<fg=red;bg=white>Titles</>');

Comment thread src/Model/Parseable.php Outdated
@dantleech

Copy link
Copy Markdown
Collaborator

Nice work! Looks good from a quick once over ,will have a better look later.

Comment thread example/demo/src/Page/BlocksPage.php Outdated
Comment thread src/Model/Widget/Line.php
Comment thread src/Model/Widget/SpanParser.php Outdated
Comment thread src/Model/Widget/SpanParser.php
Comment thread src/Model/Widget/SpanParser.php
Comment thread src/Model/Widget/Text.php Outdated
Comment thread tests/Unit/Model/Widget/SpanParserTest.php Outdated
Comment thread src/Model/Widget/SpanParser.php
@dantleech
dantleech merged commit a5c51d3 into php-tui:main Nov 19, 2023
@dantleech

Copy link
Copy Markdown
Collaborator

Nice work!

@KennedyTedesco
KennedyTedesco deleted the span-parser branch November 19, 2023 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants