Skip to content

Commit efcb6b7

Browse files
committed
Output color messages via powershell
1 parent 5cd8b04 commit efcb6b7

File tree

3 files changed

+5
-17
lines changed

3 files changed

+5
-17
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ For complete listing please take a look at [TechNet article about DOSKEY][3].
4141

4242
## ANSI colors
4343

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 `$!`.
44+
On **Windows 10** output comments are colored red.
4545

4646
## Ideas taken from [PsySH][4]
4747

ansi_echo.bat

-5
This file was deleted.

shell.php

+4-11
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,10 @@
22
// Copyright (C) 2016 Grzegorz Kowalski, see LICENSE file
33

44
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");
5+
if (strpos(php_uname(), 'Windows 10') !== false) {
6+
system('powershell "[Text.Encoding]::UTF8.GetString([convert]::FromBase64String(\"'
7+
. base64_encode('[' . $ansi_color . $message . '')
8+
.'\"))');
169
} else {
1710
echo "// $message\n";
1811
}

0 commit comments

Comments
 (0)