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