shelix/scripts/Tree_view
2024-02-26 00:37:44 +01:00

104 lines
3.4 KiB
PHP
Executable File

#!/usr/bin/php
<?php
/*
╔-----------------------------------------------------------------------╗
║ ║
║ This file is part of the Shelix IDE. ║
║ Copyright (C) 2024 NVRM webdev23 https://github.com/webdev23 ║
║ ║
║ This program is free software: you can redistribute it and/or modify ║
║ it under the terms of the GNU General Public License as published by ║
║ the Free Software Foundation, either version 3 of the License, or ║
║ (at your option) any later version. ║
║ ║
║ This program is distributed in the hope that it will be useful, ║
║ but WITHOUT ANY WARRANTY; without even the implied warranty of ║
║ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ║
║ GNU General Public License for more details. ║
║ ║
║ You should have received a copy of the GNU General Public License ║
║ along with this program. If not, see <http://www.gnu.org/licenses/>. ║
╚-----------------------------------------------------------------------╝*/
// $B = system("tmux capturep -pt 1");
// echo $B;
ob_start();
$proc0 = proc_open(
"tmux capturep -pt 1 | tail -n +2",
[["pipe", "r"], ["pipe", "w"], ["pipe", "w"]],
$pipes
);
ob_clean();
$B = stream_get_contents($pipes[1]);
$B = explode(PHP_EOL, $B);
// Cursor Line number
$CLN = substr($B[count($B) - 3], strrpos($B[count($B) - 3], ' ') + 1);
function generateCondensedRepresentation(array $arrayOfStrings, int $widthDivisor = 1) {
$condensedOutput = [];
foreach ($arrayOfStrings as $key => $string) {
// Generate dots with proper indentation based on the length
$dots = str_repeat('.', strlen($string));
// Condense the dots by removing every $widthDivisor-th space
$condensedDots = preg_replace('/\s(?<=\s{' . ($widthDivisor - 1) . '})/', '', $dots);
// Store the condensed dots in an array
$condensedOutput[] = $condensedDots;
}
// Output the condensed dots with newline
echo implode(PHP_EOL, $condensedOutput);
}
// var_dump($B);
// var_dump($CLN);
// Example array of strings
// $arrayOfStrings = [
// "Short",
// " Medium length",
// " length",
// " Even longer",
// " This is the longest",
// " Short again",
// " Also short",
// " Another long one",
// " Not too long",
// "Short once more",
// "A bit longer",
// " Shortest"
// ];
generateCondensedRepresentation($B, 10);
echo "\n-----\n";
// Example usage with the provided $arrayOfStrings, width divisor of 4, and height divisor of 2
$arrayOfStrings = [
"Short",
" Medium length",
" length",
" Even longer",
" This is the longest",
" Short again",
" Also short",
" Another long one",
" Not too long",
"Short once more",
"A bit longer",
" Shortest"
];
// Use a width divisor of 4 and a height divisor of 2 for condensation
// generateCondensedRepresentation($arrayOfStrings, 2);