Created
October 14, 2021 14:10
-
-
Save allotmentandy/c1090e852c12aa6823a294f042567ad1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Console\Commands; | |
use Illuminate\Console\Command; | |
use function Termwind\ | |
{ | |
render | |
}; | |
class termwind extends Command | |
{ | |
/** | |
* The name and signature of the console command. | |
* | |
* @var string | |
*/ | |
protected $signature = 'termwind:name'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'example of termwind'; | |
/** | |
* Create a new command instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
/** | |
* Execute the console command. | |
* | |
* @return int | |
*/ | |
public function header() | |
{ | |
return "header"; | |
} | |
/** | |
* Execute the console command. | |
* | |
* @return int | |
*/ | |
public function handle() | |
{ | |
// clear the screen! | |
echo "\033c"; | |
// $console1 = new \Symfony\Component\Console\Terminal(); | |
// for($i=0; $i<=$console1->getWidth()-1; $i++) { echo "■";} | |
// for($i=0; $i<=getenv('COLUMNS')-1; $i++) { echo "■";} | |
// render ('<span class="">LOGO</span>'); | |
render( | |
" | |
████████╗███████╗██████╗ ███╗ ███╗██╗ ██╗██╗███╗ ██╗██████╗ | |
╚══██╔══╝██╔════╝██╔══██╗████╗ ████║██║ ██║██║████╗ ██║██╔══██╗ | |
██║ █████╗ ██████╔╝██╔████╔██║██║ █╗ ██║██║██╔██╗ ██║██║ ██║ | |
██║ ██╔══╝ ██╔══██╗██║╚██╔╝██║██║███╗██║██║██║╚██╗██║██║ ██║ | |
██║ ███████╗██║ ██║██║ ╚═╝ ██║╚███╔███╔╝██║██║ ╚████║██████╔╝ | |
╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚══╝╚══╝ ╚═╝╚═╝ ╚═══╝╚═════╝ | |
" | |
); | |
render('<span class="pl-110 text-color-green" > ' . date('D F Y') . '</span>'); | |
for ($i = 0;$i <= getenv('COLUMNS') - 1;$i++) | |
{ | |
echo "■"; | |
} | |
// for($i=0; $i<=getenv('COLUMNS')-1; $i++) { echo "_";} | |
// for($i=0; $i<=getenv('COLUMNS')-1; $i++) { echo "–";} | |
// exec("ls -la", $output); | |
// $this->comment( implode( PHP_EOL, $output ) ); | |
render('Termwind css for command line scripts using php artisan from laravel'); | |
for ($i = 0;$i <= getenv('COLUMNS') - 1;$i++) | |
{ | |
echo "_"; | |
} | |
// render('<div class="p-2 m-0 text-color-white bg-red">Hello World</div>'); | |
// render('<div class="p-2 m-0 italic text-color-white bg-blue">Hello World</div>'); | |
// render('<div class="p-2 m-0 font-bold text-color-black bg-white">Hello World</div>'); | |
// render('<div class="p-2 m-0 text-color-white bg-yellow">Hello World</div>'); | |
// render('<div class="p-2 m-0 text-color-white bg-gray-900">Hello World</div>'); | |
render('<div class="p-2 m-0 text-color-green bg-black">Hello World</div>'); | |
// render('<div class="p-2 m-0 text-color-white bg-green">Hello World</div>'); | |
// render('<div class="p-2 m-0 text-color-white bg-magenta">Hello World</div>'); | |
// render('<div class="p-2 m-0 text-color-black bg-cyan">Hello World</div>'); | |
// render('<div class="p-2 m-0 text-color-yellow bg-gray">Hello World</div>'); | |
$headers = ['Name', 'Awesomeness Level']; | |
$data = [['name' => 'Jim', 'awesomeness_level' => 'Meh', ], ['name' => 'Conchita', 'awesomeness_level' => 'Fabulous', ], ]; | |
$this->table($headers, $data); | |
render('<span class="underline">underline</span>'); | |
render('<span class="italic">italic</span>'); | |
render('<span class=""><a href="">link</a></span>'); | |
// $width = exec("stty size | awk '{print $2;}' ", $width); | |
// for($i=0; $i<=$width-1; $i++) { echo "+";} | |
//echo "🃏". $console1->getWidth() . PHP_EOL; | |
// for($i=0; $i<=$console1->getWidth()-1; $i++) { echo "■";} | |
for ($i = 0;$i <= getenv('COLUMNS') - 6;$i++) | |
{ | |
echo "■"; | |
} | |
echo ' andy'; | |
echo PHP_EOL; | |
echo PHP_EOL; | |
// for($i=0; $i<=getenv('COLUMNS')-1; $i++) { echo "▪";} | |
// for($i=0; $i<=getenv('COLUMNS')-1; $i++) { echo "–";} | |
// echo "line of text" . PHP_EOL; | |
// for($i=0; $i<=getenv('COLUMNS')-1; $i++) { echo "—";} | |
// for($i=0; $i<=getenv('COLUMNS')-1; $i++) { echo "☐";} | |
//echo "get env: ". $width = getenv('COLUMNS'); | |
// // multi-line html | |
render( | |
<<<'HTML' | |
<div class="m-0 p-0 text-color-black"> | |
<span class="bg-green text-color-black m-0 p-1" href="https://nunomaduro.com">nunomaduro.com</span> | |
<span class="bg-gray text-color-green m-0 p-1" href="https://nunomaduro.com">nunomaduro.com</span> | |
<span class="bg-gray text-color-black m-0 p-1" href="https://nunomaduro.com"> ■ ▪ – </span> | |
</div> | |
HTML | |
); | |
render('<div class="p-0 m-0 w-full text-color-white bg-green">Hello World</div>'); | |
echo PHP_EOL; | |
echo PHP_EOL; | |
echo "$"; | |
echo PHP_EOL; | |
$q = $this->ask('? press q to quit, s to search, m for menu, l for links, r for rss feed, j for json '); | |
if ($q == 'q') { | |
echo 'quitting...' . PHP_EOL; | |
$this->notify('Hello Web Artisan', 'Love beautiful code? We do too!'); | |
echo "\033c"; | |
} | |
if ($q == 's') { | |
$q = $this->ask('search for..'); | |
} | |
if ($q == 'm') { | |
$name = $this->choice( | |
'What is your name?', | |
['Taylor', 'Dayle'] | |
); | |
echo $name . PHP_EOL; | |
} | |
if ($q == 'l') { | |
echo "\033c"; | |
render('<div class="p-2 m-0 text-color-white bg-green">Links</div>'); | |
echo "https://github.com/nunomaduro/termwind"; | |
echo PHP_EOL; | |
echo $this->header(); | |
} | |
if ($q == 'j') { | |
echo "\033c"; | |
echo "json file:"; | |
//Assign JSON encoded string to a PHP variable | |
$age = '{"Poll":55,"Devid":40,"Akbar":68,"Cally":70}'; | |
// Decode JSON data to PHP associative array | |
$array = json_decode($age, true); | |
// Loop through the associative array | |
foreach($array as $key=>$value) | |
{ | |
echo $key . "=>" . $value . PHP_EOL; | |
} | |
} | |
if ($q == 'r') { | |
echo "\033c"; | |
echo 'rss feed'; | |
$url = "https://www.thetouristtrail.org/feed"; | |
if(isset($_POST['submit'])) { | |
if($_POST['feedurl'] != '') { | |
$url = $_POST['feedurl']; | |
} | |
} | |
$invalidurl = false; | |
if(@simplexml_load_file($url)) { | |
$feeds = simplexml_load_file($url); | |
}else{ | |
$invalidurl = true; | |
echo "<h2>Invalid RSS feed URL.</h2>"; | |
} | |
$c=0; | |
if(!empty($feeds)) { | |
$site = $feeds->channel->title; | |
$sitelink = $feeds->channel->link; | |
echo "<h2>".$site."</h2>"; | |
foreach ($feeds->channel->item as $item) { | |
$title = $item->title; | |
$link = $item->link; | |
$description = $item->description; | |
$postDate = $item->pubDate; | |
$pubDate = date('D, d M Y', strtotime($postDate)); | |
if($c>=5) { break; | |
} | |
echo PHP_EOL; | |
echo $title; | |
echo PHP_EOL; | |
echo $pubDate; | |
echo PHP_EOL; | |
// echo $link; | |
for($i=0; $i<=getenv('COLUMNS')-1; $i++) { echo "–"; | |
} | |
echo(strip_tags($description) ); | |
for($i=0; $i<=getenv('COLUMNS')-1; $i++) { echo "–"; | |
} | |
$c++; | |
} | |
}else{ | |
if(!$invalidurl) { | |
echo "<h2>No item found</h2>"; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment