Added AnsiLove for rendering messages with ANSI sequences

This commit is contained in:
Deon George 2023-12-19 15:16:10 +11:00
parent 0e5a04596a
commit 01107cd3dc
4 changed files with 2588 additions and 3 deletions

View File

@ -4,6 +4,7 @@ namespace App\Casts;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes; use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
class CompressedString implements CastsAttributes class CompressedString implements CastsAttributes
{ {
@ -20,6 +21,11 @@ class CompressedString implements CastsAttributes
*/ */
public function get($model,string $key,mixed $value,array $attributes): string public function get($model,string $key,mixed $value,array $attributes): string
{ {
static $converted = [];
if (Arr::get($converted,$key))
return $value;
// For stream resources, we to fseek in case we've already read it. // For stream resources, we to fseek in case we've already read it.
if (is_resource($value)) if (is_resource($value))
fseek($value,0); fseek($value,0);
@ -28,6 +34,8 @@ class CompressedString implements CastsAttributes
? stream_get_contents($value) ? stream_get_contents($value)
: $value; : $value;
$converted[$key] = TRUE;
return $value ? zstd_uncompress(base64_decode($value)) : ''; return $value ? zstd_uncompress(base64_decode($value)) : '';
} }

2555
public/ansilove/ansilove.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -112,6 +112,7 @@
<li>PHP/Laravel - the coding framework used to create this UI, and to enable the transfer of mail between systems</li> <li>PHP/Laravel - the coding framework used to create this UI, and to enable the transfer of mail between systems</li>
<li>jQuery - to help with the web UI</li> <li>jQuery - to help with the web UI</li>
<li>Highcharts - to render the graphs</li> <li>Highcharts - to render the graphs</li>
<li>AnsiLove - to render the messages, for when they have ANSI code sequences</li>
</ul> </ul>
<p>If you'd like to support enhancing Clearing Houz, <a href="https://buymeacoffee.com/dege">Buy me a coffee!</a></p> <p>If you'd like to support enhancing Clearing Houz, <a href="https://buymeacoffee.com/dege">Buy me a coffee!</a></p>

View File

@ -33,8 +33,8 @@ use App\Classes\FTN\Message;
<div class="row pb-2"> <div class="row pb-2">
<div class="col-8"> <div class="col-8">
<div class="pad pb-0"> <div class="p-2">
<pre class="highlight">{!! Message::tr($msg->msg).($msg->origin ? sprintf("\r * Origin: %s",$msg->origin) : '') !!}</pre> <div id="canvas"></div>
</div> </div>
</div> </div>
</div> </div>
@ -83,3 +83,24 @@ use App\Classes\FTN\Message;
</div> </div>
</div> </div>
@endif @endif
@section('page-scripts')
<script type="text/javascript" src="{{ asset('ansilove/ansilove.js') }}"></script>
<script type="text/javascript">
$(document).ready(function() {
var msg = new Uint8Array({!! json_encode(array_values(unpack('C*',str_replace("\r","\n",$msg->msg)))) !!});
retina = window.devicePixelRatio > 1;
AnsiLove.renderBytes(
msg,
function (canvas, sauce) {
console.log(canvas);
document.getElementById("canvas").appendChild(canvas);
},
{'font': '80x25', 'bits': 8, 'icecolors': 0, 'columns': 80}
);
});
</script>
@append