Skip to content

Commit 5cd8b04

Browse files
committed
Basic ANSI color support
1 parent cffd2da commit 5cd8b04

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ Although this script doesn't implement any special features itself, there are so
3939

4040
For complete listing please take a look at [TechNet article about DOSKEY][3].
4141

42+
## ANSI colors
43+
44+
On **Windows 10** output comments are colored red if `shell.php` can access helper batch file `ansi_echo.bat`. Batch file takes two arguments: ANSI color code and text message with space characters replaced with `$!`.
45+
4246
## Ideas taken from [PsySH][4]
4347

4448
* `$_` contains result of last operation or `NULL`.

ansi_echo.bat

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@echo off
2+
setlocal
3+
set message=%2
4+
set message=%message:$!= %
5+
echo [%1%message%

shell.php

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
<?php
22
// Copyright (C) 2016 Grzegorz Kowalski, see LICENSE file
33

4-
function llecho($message) {
5-
echo "// $message\n";
4+
function llecho($message, $ansi_color = '31m') {
5+
if (strpos(php_uname(), 'Windows 10') !== false && file_exists('ansi_echo.bat')) {
6+
$message = strtr("// $message", array(
7+
'%' => '%%',
8+
'^' => '^^',
9+
'&' => '^&',
10+
'<' => '^<',
11+
'>' => '^>',
12+
'|' => '^|',
13+
' ' => "$!",
14+
));
15+
system("cmd /c ansi_echo.bat $ansi_color $message");
16+
} else {
17+
echo "// $message\n";
18+
}
619
}
720

821
function php_syntax_check_func($data, $stdin, $stdout, $stderr)

0 commit comments

Comments
 (0)