• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tempestphp / tempest-framework / 14024978163

23 Mar 2025 05:55PM UTC coverage: 79.391% (-0.05%) from 79.441%
14024978163

push

github

web-flow
feat(view): cache Blade and Twig templates in internal storage (#1061)

2 of 2 new or added lines in 2 files covered. (100.0%)

912 existing lines in 110 files now uncovered.

10478 of 13198 relevant lines covered (79.39%)

91.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

64.41
/src/Tempest/Console/src/Components/Interactive/MultipleChoiceComponent.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Console\Components\Interactive;
6

7
use Tempest\Console\Components\Concerns\HasErrors;
8
use Tempest\Console\Components\Concerns\HasState;
9
use Tempest\Console\Components\Concerns\HasTextBuffer;
10
use Tempest\Console\Components\Concerns\RendersControls;
11
use Tempest\Console\Components\OptionCollection;
12
use Tempest\Console\Components\Renderers\ChoiceRenderer;
13
use Tempest\Console\Components\Static\StaticMultipleChoiceComponent;
14
use Tempest\Console\Components\TextBuffer;
15
use Tempest\Console\HandlesKey;
16
use Tempest\Console\HasCursor;
17
use Tempest\Console\HasStaticComponent;
18
use Tempest\Console\InteractiveConsoleComponent;
19
use Tempest\Console\Key;
20
use Tempest\Console\Point;
21
use Tempest\Console\StaticConsoleComponent;
22
use Tempest\Console\Terminal\Terminal;
23

24
final class MultipleChoiceComponent implements InteractiveConsoleComponent, HasCursor, HasStaticComponent
25
{
26
    use HasErrors;
27
    use HasState;
28
    use HasTextBuffer;
29
    use RendersControls;
30

31
    private ChoiceRenderer $renderer;
32

33
    private OptionCollection $options;
34

35
    public function __construct(
13✔
36
        public string $label,
37
        iterable $options,
38
        public array $default = [],
39
    ) {
40
        $this->bufferEnabled = false;
13✔
41
        $this->options = new OptionCollection($options);
13✔
42
        $this->buffer = new TextBuffer();
13✔
43
        $this->renderer = new ChoiceRenderer(multiple: true);
13✔
44
        $this->updateQuery();
13✔
45
    }
46

47
    public StaticConsoleComponent $staticComponent {
48
        get => new StaticMultipleChoiceComponent(
49
            label: $this->label,
50
            options: $this->options->getRawOptions(),
51
            default: $this->default,
52
        );
53
    }
54

55
    public function render(Terminal $terminal): string
1✔
56
    {
57
        $this->updateQuery();
1✔
58

59
        return $this->renderer->render(
1✔
60
            terminal: $terminal,
1✔
61
            state: $this->state,
1✔
62
            label: $this->label,
1✔
63
            query: $this->buffer,
1✔
64
            options: $this->options,
1✔
65
            placeholder: 'Filter...',
1✔
66
            filtering: $this->bufferEnabled,
1✔
67
        );
1✔
68
    }
69

UNCOV
70
    private function getControls(): array
×
71
    {
UNCOV
72
        return [
×
UNCOV
73
            ...(
×
UNCOV
74
                $this->bufferEnabled
×
75
                    ? [
76
                        'esc' => 'select',
77
                    ] : [
78
                        '/' => 'filter',
79
                        'space' => 'select',
80
                    ]
UNCOV
81
            ),
×
UNCOV
82
            '↑' => 'up',
×
UNCOV
83
            '↓' => 'down',
×
UNCOV
84
            'enter' => $this->options->getSelectedOptions() === []
×
UNCOV
85
                ? 'skip'
×
UNCOV
86
                : 'confirm',
×
UNCOV
87
            'ctrl+c' => 'cancel',
×
UNCOV
88
        ];
×
89
    }
90

91
    private function updateQuery(): void
13✔
92
    {
93
        $this->options->filter($this->buffer->text);
13✔
94
    }
95

UNCOV
96
    public function getCursorPosition(Terminal $terminal): Point
×
97
    {
UNCOV
98
        return $this->renderer->getCursorPosition($terminal, $this->buffer);
×
99
    }
100

UNCOV
101
    public function cursorVisible(): bool
×
102
    {
UNCOV
103
        return $this->bufferEnabled;
×
104
    }
105

106
    #[HandlesKey]
5✔
107
    public function input(string $key): void
108
    {
109
        if (! $this->bufferEnabled && $key === '/') {
5✔
110
            $this->bufferEnabled = true;
2✔
111
            $this->updateQuery();
2✔
112

113
            return;
2✔
114
        }
115

116
        if (! $this->bufferEnabled) {
5✔
117
            match (mb_strtolower($key)) {
5✔
118
                ' ' => $this->options->toggleCurrent(),
5✔
UNCOV
119
                'h', 'k' => $this->options->previous(),
×
UNCOV
120
                'j', 'l' => $this->options->next(),
×
UNCOV
121
                default => null,
×
122
            };
5✔
123
            $this->updateQuery();
5✔
124

125
            return;
5✔
126
        }
127

128
        $this->buffer->input($key);
2✔
129
        $this->updateQuery();
2✔
130
    }
131

132
    #[HandlesKey(Key::ESCAPE)]
1✔
133
    public function stopFiltering(): void
134
    {
135
        $this->bufferEnabled = false;
1✔
136
    }
137

138
    #[HandlesKey(Key::ENTER)]
6✔
139
    public function enter(): array
140
    {
141
        return $this->options->getRawSelectedOptions($this->default);
6✔
142
    }
143

UNCOV
144
    #[HandlesKey(Key::UP)]
×
145
    #[HandlesKey(Key::HOME)]
146
    #[HandlesKey(Key::START_OF_LINE)]
147
    public function up(): void
148
    {
UNCOV
149
        $this->options->previous();
×
150
    }
151

152
    #[HandlesKey(Key::DOWN)]
4✔
153
    #[HandlesKey(Key::END)]
154
    #[HandlesKey(Key::END_OF_LINE)]
155
    public function down(): void
156
    {
157
        $this->options->next();
4✔
158
    }
159
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc