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:
parent
9307a1668e
commit
4d7b5a02d6
3 changed files with 40 additions and 27 deletions
|
@ -514,10 +514,11 @@ The following options are further explained in the theming section:
|
|||
|
||||
`-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.
|
||||
* 'i' index.
|
||||
* 'i' index (0 - (N-1)).
|
||||
* 'd' index (1 - N).
|
||||
* 'e' selected string escaped.
|
||||
|
||||
Default: 's'
|
||||
|
|
24
doc/rofi.1
24
doc/rofi.1
|
@ -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.
|
||||
.PP
|
||||
The official website for \fB\fCdmenu\fR can be found here
|
||||
.UR http://tools.suckless.org/dmenu/
|
||||
.UE \&.
|
||||
\[la]http://tools.suckless.org/dmenu/\[ra]\&.
|
||||
.SH OPTIONS
|
||||
.PP
|
||||
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
|
||||
Xresources: A method of storing key values in the Xserver. See
|
||||
here
|
||||
.UR https://en.wikipedia.org/wiki/X_resources
|
||||
.UE
|
||||
for more information.
|
||||
\[la]https://en.wikipedia.org/wiki/X_resources\[ra] for more information.
|
||||
.IP \(bu 2
|
||||
Command\-line options: Arguments passed to \fBrofi\fP\&.
|
||||
.RE
|
||||
|
@ -677,9 +674,10 @@ This mode always returns an entry, or returns directly when no entries given.
|
|||
.PP
|
||||
.RS
|
||||
.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.
|
||||
* 'i' index.
|
||||
* 'i' index (0 \- (N\-1)).
|
||||
* 'd' index (1 \- N).
|
||||
* 'e' selected string escaped.
|
||||
Default: 's'
|
||||
.fi
|
||||
|
@ -922,22 +920,18 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
.SH WEBSITE
|
||||
.PP
|
||||
\fBrofi\fP website can be found at here
|
||||
.UR https://davedavenport.github.io/rofi/
|
||||
.UE
|
||||
\[la]https://davedavenport.github.io/rofi/\[ra]
|
||||
.PP
|
||||
\fBrofi\fP bugtracker can be found here
|
||||
.UR https://github.com/DaveDavenport/rofi/issues
|
||||
.UE
|
||||
\[la]https://github.com/DaveDavenport/rofi/issues\[ra]
|
||||
.SH AUTHOR
|
||||
.PP
|
||||
Qball Cow
|
||||
.MT qball@gmpclient.org
|
||||
.ME
|
||||
\[la]qball@gmpclient.org\[ra]
|
||||
.PP
|
||||
Rasmus Steinke
|
||||
.PP
|
||||
Original code based on work by: Sean Pringle
|
||||
.MT sean.pringle@gmail.com
|
||||
.ME
|
||||
\[la]sean.pringle@gmail.com\[ra]
|
||||
.PP
|
||||
For a full list of authors, check the AUTHORS file.
|
||||
|
|
|
@ -127,12 +127,30 @@ static const char *get_display_data ( unsigned int index, void *data, G_GNUC_UNU
|
|||
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++ ) {
|
||||
if ( format[i] == 'i' ) {
|
||||
fprintf ( stdout, "%d", selected_line );
|
||||
}
|
||||
else if ( format[i] == 'd' ) {
|
||||
fprintf ( stdout, "%d", (selected_line+1) );
|
||||
}
|
||||
else if ( format[i] == 's' ) {
|
||||
fputs ( string, stdout );
|
||||
}
|
||||
|
@ -158,14 +176,14 @@ int dmenu_switcher_dialog ( char **input )
|
|||
char **list = get_dmenu ( &length );
|
||||
int restart = FALSE;
|
||||
|
||||
int number_mode = FALSE;
|
||||
// By default we print the unescaped line back.
|
||||
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 ) {
|
||||
number_mode = TRUE;
|
||||
format = "i";
|
||||
}
|
||||
|
||||
// Allow user to override the output format.
|
||||
find_arg_str ( "-format", &format );
|
||||
// Check prompt
|
||||
find_arg_str ( "-p", &dmenu_prompt );
|
||||
|
@ -202,7 +220,7 @@ int dmenu_switcher_dialog ( char **input )
|
|||
*/
|
||||
restart = TRUE;
|
||||
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;
|
||||
if ( ( mretv & MENU_QUICK_SWITCH ) ) {
|
||||
retv = 10 + ( mretv & MENU_LOWER_MASK );
|
||||
|
@ -216,10 +234,10 @@ int dmenu_switcher_dialog ( char **input )
|
|||
restart = FALSE;
|
||||
if ( ( mretv & ( MENU_OK | MENU_CUSTOM_INPUT ) ) && list[selected_line] != NULL ) {
|
||||
if ( ( mretv & MENU_CUSTOM_INPUT ) ) {
|
||||
dmenu_format_line ( format, *input, -1 );
|
||||
dmenu_output_formatted_line ( format, *input, -1 );
|
||||
}
|
||||
else{
|
||||
dmenu_format_line ( format, list[selected_line], selected_line );
|
||||
dmenu_output_formatted_line ( format, list[selected_line], selected_line );
|
||||
}
|
||||
if ( ( mretv & MENU_SHIFT ) ) {
|
||||
restart = TRUE;
|
||||
|
@ -233,10 +251,10 @@ int dmenu_switcher_dialog ( char **input )
|
|||
}
|
||||
else if ( ( mretv & MENU_QUICK_SWITCH ) ) {
|
||||
if ( ( mretv & MENU_CUSTOM_INPUT ) ) {
|
||||
dmenu_format_line ( format, *input, -1 );
|
||||
dmenu_output_formatted_line ( format, *input, -1 );
|
||||
}
|
||||
else{
|
||||
dmenu_format_line ( format, list[selected_line], selected_line );
|
||||
dmenu_output_formatted_line ( format, list[selected_line], selected_line );
|
||||
}
|
||||
|
||||
restart = FALSE;
|
||||
|
|
Loading…
Reference in a new issue