From e05e9ece8ede53b77b331e123f0dd0451cad8497 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Thu, 30 Apr 2009 21:05:59 +0200 Subject: [PATCH] Added the combine variable --- ChangeLog | 5 ++ README | 4 ++ doc/conky.1 | 4 ++ doc/variables.xml | 10 ++++ extras/nano/conky.nanorc | 2 +- extras/vim/syntax/conkyrc.vim | 1 + src/conky.c | 112 +++++++++++++++++++++++++++++++++++++++++ src/text_object.h | 7 +++ 8 files changed, 144 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 0456010..0923a0c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-04-30 + * Added $combine, a var that places 2 other vars next to each other, even if they + have a output of multiple lines. This also makes the moving of RSS-itemes with + $goto (see change from 2009-04-19) no longer necessary. + 2009-04-28 * Various XMMS2 updates (thanks Lassi) * Make ALSA mixers available on Linux, and added $if_mixer_mute (thanks diff --git a/README b/README index bb022fc..9e66990 100644 --- a/README +++ b/README @@ -676,6 +676,10 @@ conky(1) conky(1) Conky version + combine var1 var2 + Places the lines of var2 to the right of the lines of var1 seperated by the chars that are put between var1 and var2. For example: ${combine ${head /proc/cpuinfo 2} - ${head /proc/meminfo 1}} gives as output "cpuinfo_line1 - meminfo_line1" on line 1 and "cpuinfo_line2 -" on line 2. $combine vars can also be nested to place more vars next to each other. + + conky_build_date Date Conky was built diff --git a/doc/conky.1 b/doc/conky.1 index 958619e..41f5fc4 100644 --- a/doc/conky.1 +++ b/doc/conky.1 @@ -603,6 +603,10 @@ Change drawing color to color Change drawing color to colorN configuration option, where N is a digit between 0 and 9, inclusively. .TP +\fB\*(T<\fBcombine\fR\*(T>\fR \*(T<\fBvar1 var2\fR\*(T> +Places the lines of var2 to the right of the lines of var1 seperated by the chars that are put between var1 and var2. For example: ${combine ${head /proc/cpuinfo 2} - ${head /proc/meminfo 1}} gives as output "cpuinfo_line1 - meminfo_line1" on line 1 and "cpuinfo_line2 -" on line 2. $combine vars can also be nested to place more vars next to each other. + +.TP \fB\*(T<\fBconky_version\fR\*(T>\fR Conky version diff --git a/doc/variables.xml b/doc/variables.xml index c7dea16..c32fccb 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -383,6 +383,16 @@ + + + + + Places the lines of var2 to the right of the lines of var1 seperated by the chars that are put between var1 and var2. For example: ${combine ${head /proc/cpuinfo 2} - ${head /proc/meminfo 1}} gives as output "cpuinfo_line1 - meminfo_line1" on line 1 and "cpuinfo_line2 -" on line 2. $combine vars can also be nested to place more vars next to each other. + + + + + diff --git a/extras/nano/conky.nanorc b/extras/nano/conky.nanorc index 761c499..3ee15a6 100644 --- a/extras/nano/conky.nanorc +++ b/extras/nano/conky.nanorc @@ -11,7 +11,7 @@ color green "\<(alias|alignment|background|show_graph_range|show_graph_scale|bor color yellow "\<(above|below|bottom_left|bottom_right|bottom_middle|desktop|dock|no|none|normal|override|skip_pager|skip_taskbar|sticky|top_left|top_right|top_middle|middle_left|middle_right|undecorated|yes)\>" ## Variables -color brightblue "\<(acpitemp|acpitempf|freq|freq_g|voltage_mv|voltage_v|wireless_essid|wireless_mode|wireless_bitrate|wireless_ap|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_link_bar|freq_dyn|freq_dyn_g|adt746xcpu|adt746xfan|acpifan|acpiacadapter|battery|battery_time|battery_percent|battery_bar|buffers|cached|cpu|cpubar|cpugraph|loadgraph|lines|color|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|conky_version|conky_build_date|conky_build_arch|disk_protect|i8k_version|i8k_bios|i8k_serial|i8k_cpu_temp|i8k_cpu_tempf|i8k_left_fan_status|i8k_right_fan_status|i8k_left_fan_rpm|i8k_right_fan_rpm|i8k_ac_status|i8k_buttons_status|ibm_fan|ibm_temps|ibm_volume|ibm_brightness|if_up|if_updatenr|if_gw|gw_iface|gw_ip|laptop_mode|pb_battery|obsd_sensors_temp|obsd_sensors_fan|obsd_sensors_volt|obsd_vendor|obsd_product|font|diskio|diskio_write|diskio_read|diskiograph|diskiograph_read|diskiograph_write|downspeed|downspeedf|downspeedgraph|else|endif|addr|addrs|image|exec|execp|execbar|execgraph|execibar|execigraph|execi|execpi|texeci|imap_unseen|imap_messages|pop3_unseen|pop3_used|fs_bar|fs_free|fs_free_perc|fs_size|fs_type|fs_used|fs_bar_free|fs_used_perc|loadavg|goto|tab|hr|nameserver|rss|hddtemp|offset|voffset|i2c|platform|hwmon|alignr|alignc|if_empty|if_existing|if_mounted|if_running|ioscheduler|kernel|machine|mem|memeasyfree|memfree|memmax|memperc|membar|memgraph|mixer|mixerl|mixerr|mixerbar|mixerlbar|mixerrbar|mails|mboxscan|new_mails|nodename|outlinecolor|processes|running_processes|scroll|shadecolor|stippled_hr|swap|swapmax|swapperc|swapbar|sysname|time|utime|tztime|totaldown|totalup|updates|upspeed|upspeedf|upspeedgraph|uptime_short|uptime|user_names|user_terms|user_times|user_number|apm_adapter|apm_battery_life|apm_battery_time|monitor|monitor_number|mpd_title|mpd_artist|mpd_album|mpd_random|mpd_repeat|mpd_track|mpd_name|mpd_file|mpd_vol|mpd_bitrate|mpd_status|mpd_elapsed|mpd_length|mpd_percent|mpd_bar|mpd_smart|words|xmms2_artist|xmms2_album|xmms2_title|xmms2_genre|xmms2_comment|xmms2_url|xmms2_status|xmms2_date|xmms2_tracknr|xmms2_bitrate|xmms2_id|xmms2_size|xmms2_elapsed|xmms2_duration|xmms2_percent|xmms2_bar|xmms2_playlist|xmms2_timesplayed|xmms2_smart|audacious_status|audacious_title|audacious_length|audacious_length_seconds|audacious_position|audacious_position_seconds|audacious_bitrate|audacious_frequency|audacious_channels|audacious_filename|audacious_playlist_length|audacious_playlist_position|audacious_bar|bmpx_title|bmpx_artist|bmpx_album|bmpx_uri|bmpx_track|bmpx_bitrate|top|top_mem|tail|head|tcp_portmon|iconv_start|iconv_stop|entropy_avail|entropy_poolsize|entropy_bar|smapi|if_smapi_bat_installed|smapi_bat_perc|smapi_bat_bar)\>" +color brightblue "\<(acpitemp|acpitempf|freq|freq_g|voltage_mv|voltage_v|wireless_essid|wireless_mode|wireless_bitrate|wireless_ap|wireless_link_qual|wireless_link_qual_max|wireless_link_qual_perc|wireless_link_bar|freq_dyn|freq_dyn_g|adt746xcpu|adt746xfan|acpifan|acpiacadapter|battery|battery_time|battery_percent|battery_bar|buffers|cached|cpu|cpubar|cpugraph|loadgraph|lines|color|color0|color1|color2|color3|color4|color5|color6|color7|color8|color9|combine|conky_version|conky_build_date|conky_build_arch|disk_protect|i8k_version|i8k_bios|i8k_serial|i8k_cpu_temp|i8k_cpu_tempf|i8k_left_fan_status|i8k_right_fan_status|i8k_left_fan_rpm|i8k_right_fan_rpm|i8k_ac_status|i8k_buttons_status|ibm_fan|ibm_temps|ibm_volume|ibm_brightness|if_up|if_updatenr|if_gw|gw_iface|gw_ip|laptop_mode|pb_battery|obsd_sensors_temp|obsd_sensors_fan|obsd_sensors_volt|obsd_vendor|obsd_product|font|diskio|diskio_write|diskio_read|diskiograph|diskiograph_read|diskiograph_write|downspeed|downspeedf|downspeedgraph|else|endif|addr|addrs|image|exec|execp|execbar|execgraph|execibar|execigraph|execi|execpi|texeci|imap_unseen|imap_messages|pop3_unseen|pop3_used|fs_bar|fs_free|fs_free_perc|fs_size|fs_type|fs_used|fs_bar_free|fs_used_perc|loadavg|goto|tab|hr|nameserver|rss|hddtemp|offset|voffset|i2c|platform|hwmon|alignr|alignc|if_empty|if_existing|if_mounted|if_running|ioscheduler|kernel|machine|mem|memeasyfree|memfree|memmax|memperc|membar|memgraph|mixer|mixerl|mixerr|mixerbar|mixerlbar|mixerrbar|mails|mboxscan|new_mails|nodename|outlinecolor|processes|running_processes|scroll|shadecolor|stippled_hr|swap|swapmax|swapperc|swapbar|sysname|time|utime|tztime|totaldown|totalup|updates|upspeed|upspeedf|upspeedgraph|uptime_short|uptime|user_names|user_terms|user_times|user_number|apm_adapter|apm_battery_life|apm_battery_time|monitor|monitor_number|mpd_title|mpd_artist|mpd_album|mpd_random|mpd_repeat|mpd_track|mpd_name|mpd_file|mpd_vol|mpd_bitrate|mpd_status|mpd_elapsed|mpd_length|mpd_percent|mpd_bar|mpd_smart|words|xmms2_artist|xmms2_album|xmms2_title|xmms2_genre|xmms2_comment|xmms2_url|xmms2_status|xmms2_date|xmms2_tracknr|xmms2_bitrate|xmms2_id|xmms2_size|xmms2_elapsed|xmms2_duration|xmms2_percent|xmms2_bar|xmms2_playlist|xmms2_timesplayed|xmms2_smart|audacious_status|audacious_title|audacious_length|audacious_length_seconds|audacious_position|audacious_position_seconds|audacious_bitrate|audacious_frequency|audacious_channels|audacious_filename|audacious_playlist_length|audacious_playlist_position|audacious_bar|bmpx_title|bmpx_artist|bmpx_album|bmpx_uri|bmpx_track|bmpx_bitrate|top|top_mem|tail|head|tcp_portmon|iconv_start|iconv_stop|entropy_avail|entropy_poolsize|entropy_bar|smapi|if_smapi_bat_installed|smapi_bat_perc|smapi_bat_bar)\>" color brightblue "\$\{?[0-9A-Z_!@#$*?-]+\}?" diff --git a/extras/vim/syntax/conkyrc.vim b/extras/vim/syntax/conkyrc.vim index 78eba75..8702ea7 100644 --- a/extras/vim/syntax/conkyrc.vim +++ b/extras/vim/syntax/conkyrc.vim @@ -179,6 +179,7 @@ syn keyword ConkyrcVarName contained nextgroup=ConkyrcNumber,ConkyrcColour skipw \ color7 \ color8 \ color9 + \ combine \ conky_version \ conky_build_date \ conky_build_arch diff --git a/src/conky.c b/src/conky.c index 4f46364..29b94c2 100644 --- a/src/conky.c +++ b/src/conky.c @@ -967,6 +967,13 @@ static void free_text_objects(struct text_object *root) free_text_objects(obj->sub); free(obj->sub); break; + case OBJ_combine: + free(data.combine.left); + free(data.combine.seperation); + free(data.combine.right); + free_text_objects(obj->sub); + free(obj->sub); + break; } free(obj); } @@ -2532,6 +2539,48 @@ static struct text_object *construct_text_object(const char *s, } else { CRIT_ERR("scroll needs arguments: [] "); } + END OBJ(combine, 0) + if(arg) { + unsigned int i,j; + unsigned int indenting = 0; //vars can be used as args for other vars + int startvar[2]; + int endvar[2]; + startvar[0] = endvar[0] = startvar[1] = endvar[1] = -1; + j=0; + for(i=0; arg[i] != 0 && j < 2; i++) { + if(startvar[j] == -1) { + if(arg[i] == '$') { + startvar[j] = i; + } + }else if(endvar[j] == -1) { + if(arg[i] == '{') { + indenting++; + }else if(arg[i] == '}') { + indenting--; + } + if(indenting == 0 && (arg[i+1] == ' ' || arg[i+1] == '$' || arg[i+1] == 0)) { + endvar[j]=i+1; + j++; + } + } + } + if(startvar[0] >= 0 && endvar[0] >= 0 && startvar[1] >= 0 && endvar[1] >= 0) { + obj->data.combine.left=malloc(endvar[0]-startvar[0]+1); + obj->data.combine.seperation=malloc(startvar[1]-endvar[0]+1); + obj->data.combine.right=malloc(endvar[1]-startvar[1]+1); + strncpy(obj->data.combine.left, arg+startvar[0], endvar[0]-startvar[0]); obj->data.combine.left[endvar[0]-startvar[0]]=0; + strncpy(obj->data.combine.seperation, arg+endvar[0], startvar[1]-endvar[0]); obj->data.combine.seperation[startvar[1]-endvar[0]]=0; + strncpy(obj->data.combine.right, arg+startvar[1], endvar[1]-startvar[1]); obj->data.combine.right[endvar[1]-startvar[1]]=0; + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, obj->data.combine.left, 0); + obj->sub->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub->sub, obj->data.combine.right, 0); + } else { + CRIT_ERR("combine needs arguments: "); + } + } else { + CRIT_ERR("combine needs arguments: "); + } #ifdef NVIDIA END OBJ(nvidia, 0) if (!arg) { @@ -4869,6 +4918,69 @@ static void generate_text_internal(char *p, int p_max_size, } snprintf(p, p_max_size, "%s", buf); } + OBJ(combine) { + char buf[2][max_user_text]; + unsigned int i, j; + unsigned int longest=0; + unsigned int nextstart; + unsigned int nr_rows[2]; + struct llrows { + char* row; + struct llrows* next; + }; + struct llrows *ll_rows[2], *current[2]; + struct text_object * objsub = obj->sub; + + p[0]=0; + for(i=0; i<2; i++) { + nr_rows[i] = 1; + nextstart = 0; + ll_rows[i] = malloc(sizeof(struct llrows)); + current[i] = ll_rows[i]; + for(j=0; jsub; + generate_text_internal(buf[i], max_user_text, *objsub, cur); + for(j=0; buf[i][j] != 0; j++) { + if(buf[i][j] == '\t') buf[i][j] = ' '; + if(buf[i][j] == '\n') { + buf[i][j] = 0; + current[i]->row = strdup(buf[i]+nextstart); + if(i==0 && strlen(current[i]->row) > longest) longest = strlen(current[i]->row); + current[i]->next = malloc(sizeof(struct llrows)); + current[i] = current[i]->next; + nextstart = j + 1; + nr_rows[i]++; + } + } + current[i]->row = strdup(buf[i]+nextstart); + if(i==0 && strlen(current[i]->row) > longest) longest = strlen(current[i]->row); + current[i]->next = NULL; + current[i] = ll_rows[i]; + } + for(j=0; j < (nr_rows[0] > nr_rows[1] ? nr_rows[0] : nr_rows[1] ); j++) { + if(current[0]) { + strcat(p, current[0]->row); + i=strlen(current[0]->row); + }else i = 0; + while(i < longest) { + strcat(p, " "); + i++; + } + if(current[1]) { + strcat(p, obj->data.combine.seperation); + strcat(p, current[1]->row); + } + strcat(p, "\n"); + for(i=0; i<2; i++) if(current[i]) current[i]=current[i]->next; + } + for(i=0; i<2; i++) { + while(ll_rows[i] != NULL) { + current[i]=ll_rows[i]; + free(current[i]->row); + ll_rows[i]=current[i]->next; + free(current[i]); + } + } + } #ifdef NVIDIA OBJ(nvidia) { int value = get_nvidia_value(obj->data.nvidia.type, display); diff --git a/src/text_object.h b/src/text_object.h index 43dadf4..789e63b 100644 --- a/src/text_object.h +++ b/src/text_object.h @@ -368,6 +368,7 @@ enum text_object_type { OBJ_hddtemp, #endif OBJ_scroll, + OBJ_combine, OBJ_entropy_avail, OBJ_entropy_poolsize, OBJ_entropy_bar @@ -493,6 +494,12 @@ struct text_object { unsigned int start; } scroll; + struct { + char *left; + char *seperation; + char *right; + } combine; + struct local_mail_s local_mail; #ifdef NVIDIA struct nvidia_s nvidia; -- 1.7.9.5