doti3/bar/src/base/block.php

101 lines
1.8 KiB
PHP
Raw Normal View History

2017-06-19 16:36:59 +02:00
<?php
2018-01-03 13:53:49 +01:00
/**
* Get the hexa code of a color by its label.
*
* @param string $label
*
* @return string
*/
2017-06-19 16:36:59 +02:00
function color($label)
{
$colors = [
2019-01-28 11:13:11 +01:00
'music' => '#cccccc',
2017-11-29 09:10:19 +01:00
'date' => '#E9F1FF',
2017-06-19 16:36:59 +02:00
'info' => '#E9F1FF',
'critical' => '#FF474A',
'warning' => '#FF6836',
'normal' => '#B3FF6C',
];
2017-12-15 17:43:15 +01:00
return $colors[$label] ?? $colors['info'];
2017-06-19 16:36:59 +02:00
}
2019-01-28 11:13:11 +01:00
/**
* 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);
}
2019-01-21 16:20:04 +01:00
/**
* 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
);
}
2018-01-03 13:53:49 +01:00
/**
* Returns a json of a block.
*
* @param string $name
2019-01-21 16:20:04 +01:00
* @param array $options
2018-01-03 13:53:49 +01:00
*
* @return string
*/
2017-06-19 16:36:59 +02:00
function block(string $name, array $options = [])
{
$options = array_merge(
[
'full_text' => '',
'align' => 'left',
'name' => $name,
'urgent' => false,
2019-01-28 11:13:11 +01:00
'separator' => false,
'separator_block_width' => 0,
2017-06-19 16:36:59 +02:00
],
$options
);
2018-01-03 13:53:49 +01:00
return stripslashes(json_encode($options, JSON_UNESCAPED_UNICODE));
2017-06-19 16:36:59 +02:00
}