-
Notifications
You must be signed in to change notification settings - Fork 1
/
fauxton
88 lines (75 loc) · 2.25 KB
/
fauxton
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env php
<?php
/**
*
* fauxton-client console file
*
* @author Lochemem Bruno Michael
* @license Apache-2.0
*/
foreach (
[
__DIR__ . '/../autoload.php',
__DIR__ . '/../../autoload.php',
__DIR__ . '/../vendor/autoload.php',
__DIR__ . '/vendor/autoload.php',
__DIR__ . '/../../vendor/autoload.php'
] as $file
) {
if (file_exists($file)) {
define('AUTOLOAD_PHP_FILE', $file);
break;
}
}
if (!defined('AUTOLOAD_PHP_FILE')) {
fwrite(STDERR,
'You need to set up the project dependencies using the following commands:' . PHP_EOL .
'wget http://getcomposer.org/composer.phar' . PHP_EOL .
'php composer.phar install' . PHP_EOL
);
die(1);
}
require AUTOLOAD_PHP_FILE;
use Chemem\Fauxton\Console;
use Chemem\Fauxton\Config\State;
use \Chemem\Bingo\Functional\Algorithms as A;
use \Chemem\Bingo\Functional\Functors\Monads as M;
use \Chemem\Bingo\Functional\Functors\Monads\IO;
function errorHandler(string $msg, bool $type = false) : bool
{
$err = M\bind(function ($msg) use ($type) {
$handler = A\compose(
A\partial(A\concat, ' ', $type ? 'Exception' : 'Error:'),
A\partialRight(Console\color, $type ? 'red' : 'yellow'),
A\partial('printf', '%s'),
function ($content) : bool {
return $content > 0 ? true : false;
},
IO\IO
);
return $handler($msg);
}, IO\IO($msg));
return $err->exec();
}
set_exception_handler(function ($exception) {
return errorHandler($exception->getMessage(), true);
});
set_error_handler(function ($errno, $errstr) {
return errorHandler($errstr);
});
function main() : IO
{
$result = A\compose(
A\constantFunction(Console\replPrompt()),
A\constantFunction(M\mcompose(function ($fgets) {
$repl = A\compose($fgets, Console\execCmd, IO\IO);
return $repl(\STDIN);
}, IO\putStr)(IO\IO(null)))
);
return $result(null)->exec();
}
M\bind(function (string $msg) {
$result = A\compose(A\partial('printf', '%s'), IO\IO);
return $result($msg);
}, IO\IO(A\concat(\PHP_EOL, 'Fauxton Console', 'Built By Lochemem Bruno Michael', '')));
while (true) IO\_print(main());