doti3/bar/src/base/block.php

126 lines
2.3 KiB
PHP

<?php
/**
* Get the hexa code of a color by its label.
*
* @param string $label
*
* @return string
*/
function color($label)
{
$colors = [
'music' => '#cccccc',
'date' => '#E9F1FF',
'info' => '#E9F1FF',
'critical' => '#FF474A',
'warning' => '#FF6836',
'normal' => '#B3FF6C',
];
return $colors[$label] ?? $colors['info'];
}
/**
* Create emoji with padding.
*
* @param mixed $char
*/
function pemoji($char)
{
return ' <span font=\'FontAwesome\'>'.IntlChar::chr($char).'</span> ';
}
/**
* Create emoji.
*
* @param mixed $char
*/
function emoji($char)
{
return '<span font=\'FontAwesome\'>'.IntlChar::chr($char).'</span>';
}
/**
* Creates span with padding.
*
* @param string $text
* @param string $foreground
* @param string $background
*
* @return string
*/
function pspan($text, $foreground = null, $background = null)
{
return span(sprintf(' %s ', $text), $foreground, $background);
}
/**
* Creates span with right padding.
*
* @param string $text
* @param string $foreground
* @param string $background
*
* @return string
*/
function rpspan($text, $foreground = null, $background = null)
{
return span(sprintf('%s ', $text), $foreground, $background);
}
/**
* Creates span with left padding.
*
* @param string $text
* @param string $foreground
* @param string $background
*
* @return string
*/
function lpspan($text, $foreground = null, $background = null)
{
return span(sprintf(' %s', $text), $foreground, $background);
}
/**
* Creates span.
*
* @param string $text
* @param string $foreground
* @param string $background
*
* @return string
*/
function span($text, $foreground = null, $background = null)
{
return sprintf(
'<span background=\'%s\' foreground=\'%s\'>%s</span>',
$background ?? '#333333',
$foreground ?? color('normal'),
$text
);
}
/**
* Returns a json of a block.
*
* @return string
*/
function block(string $name, array $options = [])
{
$options = array_merge(
[
'full_text' => '',
'align' => 'left',
'name' => $name,
'urgent' => false,
'separator' => false,
'separator_block_width' => 0,
],
$options
);
return stripslashes(json_encode($options, JSON_UNESCAPED_UNICODE))."\n";
}