1: <?php declare(strict_types=1);
2:
3: namespace Salient\Contract\Console;
4:
5: use Salient\Contract\Console\ConsoleInterface as Console;
6: use Salient\Contract\Core\Immutable;
7:
8: /**
9: * @api
10: */
11: interface ConsoleFormatterInterface extends Immutable
12: {
13: /**
14: * Get an instance with the given spinner state array
15: *
16: * @param array{int<0,max>,float}|null $state
17: * @param-out array{int<0,max>,float} $state
18: * @return static
19: */
20: public function withSpinnerState(?array &$state);
21:
22: /**
23: * Get an instance that unescapes text
24: *
25: * @return static
26: */
27: public function withUnescape(bool $value = true);
28:
29: /**
30: * Check if text is unescaped
31: */
32: public function getUnescape(): bool;
33:
34: /**
35: * Get an instance that wraps text after formatting
36: *
37: * @return static
38: */
39: public function withWrapAfterApply(bool $value = true);
40:
41: /**
42: * Check if text is wrapped after formatting
43: */
44: public function getWrapAfterApply(): bool;
45:
46: /**
47: * Get the format applied to a tag
48: *
49: * @param ConsoleTag::* $tag
50: */
51: public function getTagFormat(int $tag): ConsoleFormatInterface;
52:
53: /**
54: * Get the format applied to a message level and type
55: *
56: * @param Console::LEVEL_* $level
57: * @param Console::TYPE_* $type
58: */
59: public function getMessageFormat(
60: int $level,
61: int $type = Console::TYPE_STANDARD
62: ): ConsoleMessageFormatInterface;
63:
64: /**
65: * Get the prefix applied to a message level and type
66: *
67: * @param Console::LEVEL_* $level
68: * @param Console::TYPE_* $type
69: */
70: public function getMessagePrefix(
71: int $level,
72: int $type = Console::TYPE_STANDARD
73: ): string;
74:
75: /**
76: * Format a string that may contain inline formatting tags
77: *
78: * Paragraphs outside preformatted blocks are optionally wrapped to a given
79: * width, and backslash-escaped punctuation characters and line breaks are
80: * preserved.
81: *
82: * Escaped line breaks may have a leading space, so the following are
83: * equivalent:
84: *
85: * ```
86: * Text with a \
87: * hard line break.
88: *
89: * Text with a\
90: * hard line break.
91: * ```
92: *
93: * @param array{int,int}|int|null $wrapToWidth If `null` (the default), text
94: * is not wrapped.
95: *
96: * If `$wrapToWidth` is an `array`, the first line of text is wrapped to the
97: * first value, and text in subsequent lines is wrapped to the second value.
98: *
99: * Widths less than or equal to `0` are added to the width reported by the
100: * target, and text is wrapped to the result.
101: * @param bool $unformat If `true`, formatting tags are reapplied after text
102: * is unwrapped and/or wrapped.
103: */
104: public function format(
105: string $string,
106: bool $unwrap = false,
107: $wrapToWidth = null,
108: bool $unformat = false,
109: string $break = "\n"
110: ): string;
111:
112: /**
113: * Format a console message
114: *
115: * @param Console::LEVEL_* $level
116: * @param Console::TYPE_* $type
117: */
118: public function formatMessage(
119: string $msg1,
120: ?string $msg2 = null,
121: int $level = Console::LEVEL_INFO,
122: int $type = Console::TYPE_STANDARD
123: ): string;
124:
125: /**
126: * Format a unified diff
127: */
128: public function formatDiff(string $diff): string;
129: }
130: