Skip to content

Commit 7b042ff

Browse files
committed
Merge branch 'develop'
2 parents 658632c + d62b13b commit 7b042ff

File tree

4 files changed

+52
-12
lines changed

4 files changed

+52
-12
lines changed

Ansi.php

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace MaplePHP\Prompts;
44

5+
use Exception;
56
use InvalidArgumentException;
67

78
/**
@@ -143,52 +144,72 @@ public function clearDown(): string
143144

144145
/**
145146
* Clear line
146-
*
147+
*
147148
* @return string
149+
* @throws Exception
148150
*/
149151
public function clearLine(): string
150152
{
153+
if (!self::isSupported()) {
154+
throw new Exception("Ansi not supported by OS", 1);
155+
}
151156
return "\033[2K";
152157
}
153158

154159
/**
155160
* Move cursor to specified line
156-
*
161+
*
157162
* @param int $line
158163
* @return string
164+
* @throws Exception
159165
*/
160166
public function moveCursorTo(int $line): string
161167
{
168+
if (!self::isSupported()) {
169+
throw new Exception("Ansi not supported by OS", 1);
170+
}
162171
return "\033[{$line}A";
163172
}
164173

165174
/**
166175
* Move cursor down
167-
*
176+
*
168177
* @return string
178+
* @throws Exception
169179
*/
170180
public function cursorDown(): string
171181
{
182+
if (!self::isSupported()) {
183+
throw new Exception("Ansi not supported by OS", 1);
184+
}
172185
return "\033[1B";
173186
}
174187

175188
/**
176189
* Arrow up key
177-
*
190+
*
178191
* @return string
192+
* @throws Exception
179193
*/
180194
public function keyUp(): string
181195
{
196+
if (!self::isSupported()) {
197+
throw new Exception("Ansi not supported by OS", 1);
198+
}
182199
return "\033[A";
183200
}
184201

185202
/**
186203
* Arrow down key
187-
*
204+
*
188205
* @return string
206+
* @throws Exception
189207
*/
190208
public function keyDown(): string
191209
{
210+
if (!self::isSupported()) {
211+
throw new Exception("Ansi not supported by OS", 1);
212+
}
192213
return "\033[B";
193214
}
194215

@@ -204,21 +225,29 @@ public function keyEnter(): string
204225

205226
/**
206227
* Escape key
207-
*
228+
*
208229
* @return string
230+
* @throws Exception
209231
*/
210232
public function keyEscape(): string
211233
{
234+
if (!self::isSupported()) {
235+
throw new Exception("Ansi not supported by OS", 1);
236+
}
212237
return "\033";
213238
}
214239

215240
/**
216241
* Symbol: checkbox
217-
*
242+
*
218243
* @return string
244+
* @throws Exception
219245
*/
220246
public function checkbox(): string
221247
{
248+
if (!self::isSupported()) {
249+
throw new Exception("Ansi not supported by OS", 1);
250+
}
222251
return "\xE2\x9C\x94";
223252
}
224253

@@ -232,11 +261,15 @@ final public static function isSupported(): bool
232261
{
233262
if (is_null(self::$hasAnsi)) {
234263
if (stripos(PHP_OS, 'WIN') === 0) {
264+
265+
self::$hasAnsi = false;
266+
/*
235267
$osVersion = php_uname('v');
236268
if (preg_match('/build (\d+)/i', $osVersion, $matches)) {
237269
$buildNumber = (int)$matches[1];
238270
self::$hasAnsi = ($buildNumber >= 10586);
239271
}
272+
*/
240273
} else {
241274
self::$hasAnsi = (getenv('TERM') && str_contains(getenv('TERM'), 'xterm'));
242275
}

Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Command
2020

2121
public function __construct()
2222
{
23-
$this->stream = new Stream(Stream::STDIN, "r");
23+
$this->stream = new Stream(Stream::STDOUT);
2424
$this->stty = new SttyWrapper();
2525
$this->ansi = new Ansi();
2626
}

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# MaplePHP Prompts
22

3-
PHP Prompts is an interactive, lightweight, and easy-to-use CLI (Command Line Interface) PHP library. It provides a way to create and manage user prompts in a command-line environment, enabling the collection of various types of user input with validation and feedback.
3+
PHP Prompts is a pretty, interactive, lightweight, and user-friendly CLI (Command Line Interface) PHP library designed for seamless use across Linux, Unix, Darwin, and Windows. It allows you to create and manage user prompts in a command-line environment, enabling the collection of various types of input with built-in validation and feedback.
44

55
![Prompt demo](http://wazabii.se/github-assets/maplephp-prompt-v2.gif)
66

7+
_Note that the prompt may not look as polished on Windows as on Unix, but it will work just as well._
8+
79
### Table of Contents
810
- [Installation](#installation)
911
- [Usage Example](#usage-example)

composer.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
{
22
"name": "maplephp/prompts",
33
"type": "library",
4-
"version": "v1.0.3",
5-
"description": "PHP Prompts is an interactive, lightweight and very easy to CLI (Command Line Interface) PHP library.",
4+
"version": "v1.0.4",
5+
"description": "PHP Prompts is a pretty, interactive, lightweight, and user-friendly CLI (Command Line Interface) PHP library designed for seamless use across Linux, Unix, Darwin, and Windows.",
66
"keywords": [
77
"php",
88
"cli",
99
"command line",
1010
"prompt",
1111
"lightweight",
12-
"cross-platform"
12+
"cross-platform",
13+
"cross-os",
14+
"Linux",
15+
"Unix",
16+
"Darwin",
17+
"windows"
1318
],
1419
"homepage": "https://wazabii.se",
1520
"license": "Apache-2.0",

0 commit comments

Comments
 (0)