1: | <?php declare(strict_types=1); |
2: | |
3: | namespace Salient\Contract\Console\Format; |
4: | |
5: | use Salient\Contract\Console\ConsoleInterface as Console; |
6: | use Salient\Contract\Core\Immutable; |
7: | |
8: | /** |
9: | * @api |
10: | */ |
11: | interface FormatterInterface extends Immutable, HasTag |
12: | { |
13: | /** |
14: | * Check if the formatter removes escapes from strings |
15: | */ |
16: | public function removesEscapes(): bool; |
17: | |
18: | /** |
19: | * Check if the formatter wraps strings after formatting |
20: | * |
21: | * Returns `false` if strings are wrapped after inline formatting tags are |
22: | * removed. |
23: | */ |
24: | public function wrapsAfterFormatting(): bool; |
25: | |
26: | /** |
27: | * Get an instance that removes escapes from strings |
28: | * |
29: | * @return static |
30: | */ |
31: | public function withRemoveEscapes(bool $remove = true); |
32: | |
33: | /** |
34: | * Get an instance that wraps strings after formatting |
35: | * |
36: | * @return static |
37: | */ |
38: | public function withWrapAfterFormatting(bool $value = true); |
39: | |
40: | /** |
41: | * Get the format applied to a given tag |
42: | * |
43: | * @param FormatterInterface::TAG_* $tag |
44: | */ |
45: | public function getTagFormat(int $tag): FormatInterface; |
46: | |
47: | /** |
48: | * Get the format applied to a given message level and type |
49: | * |
50: | * @param Console::LEVEL_* $level |
51: | * @param Console::TYPE_* $type |
52: | */ |
53: | public function getMessageFormat( |
54: | int $level, |
55: | int $type = Console::TYPE_STANDARD |
56: | ): MessageFormatInterface; |
57: | |
58: | /** |
59: | * Get the prefix applied to a given message level and type |
60: | * |
61: | * @param Console::LEVEL_* $level |
62: | * @param Console::TYPE_* $type |
63: | */ |
64: | public function getMessagePrefix( |
65: | int $level, |
66: | int $type = Console::TYPE_STANDARD |
67: | ): string; |
68: | |
69: | /** |
70: | * Format and optionally reflow a string with inline formatting tags |
71: | * |
72: | * @param int|array{int,int}|null $wrapTo - `int`: wrap the string to the |
73: | * given width |
74: | * - `array{int,int}`: wrap the string to `[ <first_line_width>, <width> ]` |
75: | * - `null` (default): do not wrap the string |
76: | * |
77: | * Integers less than or equal to `0` are added to the width of the target |
78: | * and replaced with the result. |
79: | * @param bool $unformat If `true`, inline formatting tags are reapplied |
80: | * after the string is formatted. |
81: | */ |
82: | public function format( |
83: | string $string, |
84: | bool $unwrap = false, |
85: | $wrapTo = null, |
86: | bool $unformat = false, |
87: | string $break = "\n" |
88: | ): string; |
89: | |
90: | /** |
91: | * Format a unified diff |
92: | */ |
93: | public function formatDiff(string $diff): string; |
94: | |
95: | /** |
96: | * Format a console message |
97: | * |
98: | * Inline formatting tags in `$msg1` and `$msg2` have no special meaning; |
99: | * call {@see format()} first if necessary. |
100: | * |
101: | * @param Console::LEVEL_* $level |
102: | * @param Console::TYPE_* $type |
103: | */ |
104: | public function formatMessage( |
105: | string $msg1, |
106: | ?string $msg2 = null, |
107: | int $level = Console::LEVEL_INFO, |
108: | int $type = Console::TYPE_STANDARD |
109: | ): string; |
110: | } |
111: |