1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-25 13:55:34 -05:00

Cleanup and add d format

This commit is contained in:
Dave Davenport 2015-05-11 23:20:34 +02:00
parent 9307a1668e
commit 4d7b5a02d6
3 changed files with 40 additions and 27 deletions

View file

@ -514,10 +514,11 @@ The following options are further explained in the theming section:
`-format` *format* `-format` *format*
Allows the output of dmenu to be customized: Allows the output of dmenu to be customized (N is total number of input entries):
* 's' selected string. * 's' selected string.
* 'i' index. * 'i' index (0 - (N-1)).
* 'd' index (1 - N).
* 'e' selected string escaped. * 'e' selected string escaped.
Default: 's' Default: 's'

View file

@ -87,8 +87,7 @@ Keybindings can also be specified in the \fB\fCXresources\fR file.
\fBrofi\fP can emulate \fB\fCdmenu\fR (a dynamic menu for X) when launched with the \fB\fC\-dmenu\fR flag. \fBrofi\fP can emulate \fB\fCdmenu\fR (a dynamic menu for X) when launched with the \fB\fC\-dmenu\fR flag.
.PP .PP
The official website for \fB\fCdmenu\fR can be found here The official website for \fB\fCdmenu\fR can be found here
.UR http://tools.suckless.org/dmenu/ \[la]http://tools.suckless.org/dmenu/\[ra]\&.
.UE \&.
.SH OPTIONS .SH OPTIONS
.PP .PP
There are currently three methods of setting configuration options: There are currently three methods of setting configuration options:
@ -98,9 +97,7 @@ Compile time: edit config.c. This method is strongly discouraged.
.IP \(bu 2 .IP \(bu 2
Xresources: A method of storing key values in the Xserver. See Xresources: A method of storing key values in the Xserver. See
here here
.UR https://en.wikipedia.org/wiki/X_resources \[la]https://en.wikipedia.org/wiki/X_resources\[ra] for more information.
.UE
for more information.
.IP \(bu 2 .IP \(bu 2
Command\-line options: Arguments passed to \fBrofi\fP\&. Command\-line options: Arguments passed to \fBrofi\fP\&.
.RE .RE
@ -677,9 +674,10 @@ This mode always returns an entry, or returns directly when no entries given.
.PP .PP
.RS .RS
.nf .nf
Allows the output of dmenu to be customized: Allows the output of dmenu to be customized (N is total number of input entries):
* 's' selected string. * 's' selected string.
* 'i' index. * 'i' index (0 \- (N\-1)).
* 'd' index (1 \- N).
* 'e' selected string escaped. * 'e' selected string escaped.
Default: 's' Default: 's'
.fi .fi
@ -922,22 +920,18 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
.SH WEBSITE .SH WEBSITE
.PP .PP
\fBrofi\fP website can be found at here \fBrofi\fP website can be found at here
.UR https://davedavenport.github.io/rofi/ \[la]https://davedavenport.github.io/rofi/\[ra]
.UE
.PP .PP
\fBrofi\fP bugtracker can be found here \fBrofi\fP bugtracker can be found here
.UR https://github.com/DaveDavenport/rofi/issues \[la]https://github.com/DaveDavenport/rofi/issues\[ra]
.UE
.SH AUTHOR .SH AUTHOR
.PP .PP
Qball Cow Qball Cow
.MT qball@gmpclient.org \[la]qball@gmpclient.org\[ra]
.ME
.PP .PP
Rasmus Steinke Rasmus Steinke
.PP .PP
Original code based on work by: Sean Pringle Original code based on work by: Sean Pringle
.MT sean.pringle@gmail.com \[la]sean.pringle@gmail.com\[ra]
.ME
.PP .PP
For a full list of authors, check the AUTHORS file. For a full list of authors, check the AUTHORS file.

View file

@ -127,12 +127,30 @@ static const char *get_display_data ( unsigned int index, void *data, G_GNUC_UNU
return retv[index]; return retv[index];
} }
static void dmenu_format_line ( const char *format, const char *string, int selected_line ) /**
* @param format The format string used. See below for possible syntax.
* @param string The selected entry.
* @param selected_line The selected line index.
*
* Function that outputs the selected line in the user-specified format.
* Currently the following formats are supported:
* * i: Print the index (0-(N-1))
* * d: Print the index (1-N)
* * s: Print input string.
* * e: Print input string shell quoted.
*
* This functions outputs the formatted string to stdout, appends a newline (\n) character and
* calls flush on the file descriptor.
*/
static void dmenu_output_formatted_line ( const char *format, const char *string, int selected_line )
{ {
for ( int i = 0; format && format[i]; i++ ) { for ( int i = 0; format && format[i]; i++ ) {
if ( format[i] == 'i' ) { if ( format[i] == 'i' ) {
fprintf ( stdout, "%d", selected_line ); fprintf ( stdout, "%d", selected_line );
} }
else if ( format[i] == 'd' ) {
fprintf ( stdout, "%d", (selected_line+1) );
}
else if ( format[i] == 's' ) { else if ( format[i] == 's' ) {
fputs ( string, stdout ); fputs ( string, stdout );
} }
@ -158,14 +176,14 @@ int dmenu_switcher_dialog ( char **input )
char **list = get_dmenu ( &length ); char **list = get_dmenu ( &length );
int restart = FALSE; int restart = FALSE;
int number_mode = FALSE; // By default we print the unescaped line back.
char *format = "s"; char *format = "s";
// Check if the user requested number mode. // This is here for compatibility reason.
// Use -format 'i' instead.
if ( find_arg ( "-i" ) >= 0 ) { if ( find_arg ( "-i" ) >= 0 ) {
number_mode = TRUE;
format = "i"; format = "i";
} }
// Allow user to override the output format.
find_arg_str ( "-format", &format ); find_arg_str ( "-format", &format );
// Check prompt // Check prompt
find_arg_str ( "-p", &dmenu_prompt ); find_arg_str ( "-p", &dmenu_prompt );
@ -202,7 +220,7 @@ int dmenu_switcher_dialog ( char **input )
*/ */
restart = TRUE; restart = TRUE;
if ( ( mretv & ( MENU_OK | MENU_QUICK_SWITCH ) ) && list[selected_line] != NULL ) { if ( ( mretv & ( MENU_OK | MENU_QUICK_SWITCH ) ) && list[selected_line] != NULL ) {
dmenu_format_line ( format, list[selected_line], selected_line ); dmenu_output_formatted_line ( format, list[selected_line], selected_line );
retv = TRUE; retv = TRUE;
if ( ( mretv & MENU_QUICK_SWITCH ) ) { if ( ( mretv & MENU_QUICK_SWITCH ) ) {
retv = 10 + ( mretv & MENU_LOWER_MASK ); retv = 10 + ( mretv & MENU_LOWER_MASK );
@ -216,10 +234,10 @@ int dmenu_switcher_dialog ( char **input )
restart = FALSE; restart = FALSE;
if ( ( mretv & ( MENU_OK | MENU_CUSTOM_INPUT ) ) && list[selected_line] != NULL ) { if ( ( mretv & ( MENU_OK | MENU_CUSTOM_INPUT ) ) && list[selected_line] != NULL ) {
if ( ( mretv & MENU_CUSTOM_INPUT ) ) { if ( ( mretv & MENU_CUSTOM_INPUT ) ) {
dmenu_format_line ( format, *input, -1 ); dmenu_output_formatted_line ( format, *input, -1 );
} }
else{ else{
dmenu_format_line ( format, list[selected_line], selected_line ); dmenu_output_formatted_line ( format, list[selected_line], selected_line );
} }
if ( ( mretv & MENU_SHIFT ) ) { if ( ( mretv & MENU_SHIFT ) ) {
restart = TRUE; restart = TRUE;
@ -233,10 +251,10 @@ int dmenu_switcher_dialog ( char **input )
} }
else if ( ( mretv & MENU_QUICK_SWITCH ) ) { else if ( ( mretv & MENU_QUICK_SWITCH ) ) {
if ( ( mretv & MENU_CUSTOM_INPUT ) ) { if ( ( mretv & MENU_CUSTOM_INPUT ) ) {
dmenu_format_line ( format, *input, -1 ); dmenu_output_formatted_line ( format, *input, -1 );
} }
else{ else{
dmenu_format_line ( format, list[selected_line], selected_line ); dmenu_output_formatted_line ( format, list[selected_line], selected_line );
} }
restart = FALSE; restart = FALSE;