summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/rofi-theme-manpage.markdown10
-rw-r--r--doc/rofi-theme.519
-rw-r--r--include/theme.h2
-rw-r--r--lexer/theme-lexer.l2
-rw-r--r--lexer/theme-parser.y2
-rw-r--r--source/dialogs/script.c122
-rw-r--r--source/helper.c6
7 files changed, 141 insertions, 22 deletions
diff --git a/doc/rofi-theme-manpage.markdown b/doc/rofi-theme-manpage.markdown
index 7faf9cb6..f6eb2ef9 100644
--- a/doc/rofi-theme-manpage.markdown
+++ b/doc/rofi-theme-manpage.markdown
@@ -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)`
diff --git a/doc/rofi-theme.5 b/doc/rofi-theme.5
index d698656a..21f8877c 100644
--- a/doc/rofi-theme.5
+++ b/doc/rofi-theme.5
@@ -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"
.
diff --git a/include/theme.h b/include/theme.h
index e6ca825f..8bdeddc1 100644
--- a/include/theme.h
+++ b/include/theme.h
@@ -44,6 +44,8 @@ typedef enum
HL_UNDERLINE = 2,
/** strikethrough */
HL_STRIKETHROUGH = 16,
+ /** small caps */
+ HL_SMALL_CAPS = 32,
/** italic */
HL_ITALIC = 4,
/** color */
diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l
index cf85a0fb..80ee6584 100644
--- a/lexer/theme-lexer.l
+++ b/lexer/theme-lexer.l
@@ -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; }
diff --git a/lexer/theme-parser.y b/lexer/theme-parser.y
index e721b346..d66b7cc4 100644
--- a/lexer/theme-parser.y
+++ b/lexer/theme-parser.y
@@ -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. */
diff --git a/source/dialogs/script.c b/source/dialogs/script.c
index a4daf289..df006ba4 100644
--- a/source/dialogs/script.c
+++ b/source/dialogs/script.c
@@ -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;
}
diff --git a/source/helper.c b/source/helper.c
index e14a5e68..7fa07478 100644
--- a/source/helper.c
+++ b/source/helper.c
@@ -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;