1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

[Theme] Add small caps options (not working?)

This commit is contained in:
Dave Davenport 2017-05-22 09:24:05 +02:00
parent 8616e4e8c6
commit dca5caaa47
7 changed files with 141 additions and 22 deletions

View file

@ -274,7 +274,7 @@ The different values are:
OldLace, Olive, OliveDrab, Orange, OrangeRed, Orchid, PaleGoldenRod, PaleGreen, PaleTurquoise, PaleVioletRed,
PapayaWhip, PeachPuff, Peru, Pink, Plum, PowderBlue, Purple, RebeccaPurple, Red, RosyBrown, RoyalBlue, SaddleBrown,
Salmon, SandyBrown, SeaGreen, SeaShell, Sienna, Silver, SkyBlue, SlateBlue, SlateGray, SlateGrey, Snow, SpringGreen,
SteelBlue, Tan, Teal, Thistle, Tomato, Turquoise, Violet, Wheat, White, WhiteSmoke, Yellow, YellowGreen
SteelBlue, Tan, Teal, Thistle, Tomato, Turquoise, Violet, Wheat, White, WhiteSmoke, Yellow, YellowGreen
For example:
@ -289,9 +289,15 @@ text: SeaGreen;
* Format: `(bold|italic|underline|strikethrough|none)`
Text style indicates how the text should be displayed. None indicates no style
Text style indicates how the highlighted text is emphasised. None indicates no emphasis
should be applied.
* `bold`: make the text thicker then the surrounding text.
* `italic`: put the highlighted text in script type (slanted).
* `underline`: put a line under the highlighted text.
* `strikethrough`: put a line through the highlighted text.
* `small caps`: emphasise the text using capitalization.
## Line style
* Format: `(dash|solid)`

View file

@ -443,7 +443,24 @@ Format: \fB(bold|italic|underline|strikethrough|none)\fR
.IP "" 0
.
.P
Text style indicates how the text should be displayed\. None indicates no style should be applied\.
Text style indicates how the highlighted text is emphasised\. None indicates no emphasis should be applied\.
.
.IP "\(bu" 4
\fBbold\fR: make the text thicker then the surrounding text\.
.
.IP "\(bu" 4
\fBitalic\fR: put the highlighted text in script type (slanted)\.
.
.IP "\(bu" 4
\fBunderline\fR: put a line under the highlighted text\.
.
.IP "\(bu" 4
\fBstrikethrough\fR: put a line through the highlighted text\.
.
.IP "\(bu" 4
\fBsmall caps\fR: emphasise the text using capitalization\.
.
.IP "" 0
.
.SH "Line style"
.

View file

@ -44,6 +44,8 @@ typedef enum
HL_UNDERLINE = 2,
/** strikethrough */
HL_STRIKETHROUGH = 16,
/** small caps */
HL_SMALL_CAPS = 32,
/** italic */
HL_ITALIC = 4,
/** color */

View file

@ -189,6 +189,7 @@ BOLD "bold"
UNDERLINE "underline"
ITALIC "italic"
STRIKETHROUGH "strikethrough"
SMALLCAPS "small caps"
/* ANGLES */
@ -461,6 +462,7 @@ if ( queue == NULL ){
<PROPERTIES>{ITALIC} { return T_ITALIC; }
<PROPERTIES>{UNDERLINE} { return T_UNDERLINE; }
<PROPERTIES>{STRIKETHROUGH} { return T_STRIKETHROUGH; }
<PROPERTIES>{SMALLCAPS} { return T_SMALLCAPS; }
<PROPERTIES>{ANGLE_DEG} { return T_ANGLE_DEG; }
<PROPERTIES>{ANGLE_RAD} { return T_ANGLE_RAD; }

View file

@ -174,6 +174,7 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b)
%token T_ITALIC "Italic"
%token T_UNDERLINE "Underline"
%token T_STRIKETHROUGH "Strikethrough"
%token T_SMALLCAPS "Small CAPS"
%token T_DASH "Dash"
%token T_SOLID "Solid"
@ -400,6 +401,7 @@ t_property_highlight_style
| T_UNDERLINE { $$ = HL_UNDERLINE; }
| T_STRIKETHROUGH { $$ = HL_STRIKETHROUGH; }
| T_ITALIC { $$ = HL_ITALIC; }
| T_SMALLCAPS { $$ = HL_SMALL_CAPS; }
;
/** Distance. */

View file

@ -39,28 +39,104 @@
#include "rofi.h"
#include "dialogs/script.h"
#include "helper.h"
#include "widgets/textbox.h"
#include "mode-private.h"
static char **get_script_output ( const char *command, unsigned int *length )
#define START_OF_HEADING '\x01'
#define START_OF_TEXT '\x02'
#define UNIT_SEPARATOR '\x1F'
typedef enum {
PARSING_ENTRIES = 0,
PARSING_HEADER = 1
} ParserMode;
typedef struct
{
unsigned int id;
ParserMode pmode;
char **cmd_list;
unsigned int cmd_list_length;
/** Display msg */
char *message;
char *prompt;
char *format;
gboolean markup_rows;
} ScriptModePrivateData;
static void parse_header ( Mode *sw, ScriptModePrivateData *pd, char *buffer, const ssize_t buffer_length )
{
if ( *buffer == START_OF_TEXT )
{
pd->pmode = PARSING_ENTRIES;
return;
}
char *unit_sep = strchr ( buffer, UNIT_SEPARATOR);
if ( unit_sep )
{
const char *command = buffer;
const char *value = unit_sep+1;
*unit_sep = '\0';
if ( strcmp ( command, "message" ) == 0 ) {
if ( pd->message ) g_free ( pd->message );
pd->message = g_strdup(value);
}
else if ( strcmp ( command, "prompt" ) == 0 ) {
if ( pd->prompt ) g_free ( pd->prompt );
pd->prompt = g_strdup(value);
sw->display_name = pd->prompt;
}
else if ( strcmp ( command, "markup_rows" ) == 0 ){
pd->markup_rows = strcasecmp( value, "true") == 0;
}
else if ( strcmp ( command, "format" ) == 0 ) {
if ( pd->format ) g_free ( pd->format );
pd->format = g_strdup(value);
}
}
}
static char **get_script_output ( Mode *sw, ScriptModePrivateData *pd, const char *command, unsigned int *length )
{
// Default to parsing entries.
pd->pmode = PARSING_ENTRIES;
char **retv = NULL;
*length = 0;
unsigned int actual_length = 0;
int fd = execute_generator ( command );
if ( fd >= 0 ) {
FILE *inp = fdopen ( fd, "r" );
if ( inp ) {
char *buffer = NULL;
size_t buffer_length = 0;
while ( getline ( &buffer, &buffer_length, inp ) > 0 ) {
retv = g_realloc ( retv, ( ( *length ) + 2 ) * sizeof ( char* ) );
ssize_t read_length = 0;
while ( (read_length = getline ( &buffer, &buffer_length, inp )) > 0 ) {
if ( buffer[read_length-1] == '\n' ){
buffer[read_length-1] = '\0';
read_length--;
}
if ( buffer[0] == START_OF_HEADING ) {
pd->pmode = PARSING_HEADER;
parse_header( sw, pd, buffer+1, read_length);
continue;
}
if ( pd->pmode == PARSING_HEADER ){
parse_header(sw, pd, buffer, read_length);
continue;
}
if ( actual_length < ((*length)+2)) {
actual_length += 128;
retv = g_realloc ( retv, ( actual_length ) * sizeof ( char* ) );
}
retv[( *length )] = g_strdup ( buffer );
retv[( *length ) + 1] = NULL;
// Filter out line-end.
if ( retv[( *length )][strlen ( buffer ) - 1] == '\n' ) {
retv[( *length )][strlen ( buffer ) - 1] = '\0';
}
( *length )++;
}
@ -78,9 +154,10 @@ static char **get_script_output ( const char *command, unsigned int *length )
static char **execute_executor ( Mode *sw, const char *result, unsigned int *length )
{
ScriptModePrivateData *pd = (ScriptModePrivateData *) sw->private_data;
char *arg = g_shell_quote ( result );
char *command = g_strdup_printf ( "%s %s", (const char *) sw->ed, arg );
char **retv = get_script_output ( command, length );
char **retv = get_script_output ( sw, pd, command, length );
g_free ( command );
g_free ( arg );
return retv;
@ -96,19 +173,12 @@ static void script_switcher_free ( Mode *sw )
g_free ( sw );
}
typedef struct
{
unsigned int id;
char **cmd_list;
unsigned int cmd_list_length;
} ScriptModePrivateData;
static int script_mode_init ( Mode *sw )
{
if ( sw->private_data == NULL ) {
ScriptModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
sw->private_data = (void *) pd;
pd->cmd_list = get_script_output ( (const char *) sw->ed, &( pd->cmd_list_length ) );
pd->cmd_list = get_script_output ( sw,pd, (const char *) sw->ed, &( pd->cmd_list_length ) );
}
return TRUE;
}
@ -157,6 +227,8 @@ static void script_mode_destroy ( Mode *sw )
ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data;
if ( rmpd != NULL ) {
g_strfreev ( rmpd->cmd_list );
g_free ( rmpd->message );
g_free ( rmpd->prompt );
g_free ( rmpd );
sw->private_data = NULL;
}
@ -164,6 +236,9 @@ static void script_mode_destroy ( Mode *sw )
static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, G_GNUC_UNUSED GList **list, int get_entry )
{
ScriptModePrivateData *rmpd = sw->private_data;
if ( rmpd->markup_rows ) {
*state |= MARKUP;
}
return get_entry ? g_strdup ( rmpd->cmd_list[selected_line] ) : NULL;
}
@ -172,6 +247,14 @@ static int script_token_match ( const Mode *sw, GRegex **tokens, unsigned int in
ScriptModePrivateData *rmpd = sw->private_data;
return helper_token_match ( tokens, rmpd->cmd_list[index] );
}
static char *script_get_message ( const Mode *sw )
{
ScriptModePrivateData *pd = (ScriptModePrivateData *) mode_get_private_data ( sw );
if ( pd->message ) {
return g_strdup ( pd->message );
}
return NULL;
}
#include "mode-private.h"
Mode *script_switcher_parse_setup ( const char *str )
@ -198,9 +281,10 @@ Mode *script_switcher_parse_setup ( const char *str )
sw->_result = script_mode_result;
sw->_destroy = script_mode_destroy;
sw->_token_match = script_token_match;
sw->_get_completion = NULL,
sw->_preprocess_input = NULL,
sw->_get_completion = NULL;
sw->_preprocess_input = NULL;
sw->_get_display_value = _get_display_value;
sw->_get_message = script_get_message;
return sw;
}

View file

@ -429,6 +429,12 @@ PangoAttrList *helper_token_match_get_pango_attr ( ThemeHighlight th, GRegex **t
pa->end_index = end;
pango_attr_list_insert ( retv, pa );
}
if ( th.style & HL_SMALL_CAPS ) {
PangoAttribute *pa = pango_attr_variant_new ( PANGO_VARIANT_SMALL_CAPS );
pa->start_index = start;
pa->end_index = end;
pango_attr_list_insert ( retv, pa );
}
if ( th.style & HL_ITALIC ) {
PangoAttribute *pa = pango_attr_style_new ( PANGO_STYLE_ITALIC );
pa->start_index = start;