diff --git a/README.rst b/README.rst index b4370d1..83517dc 100644 --- a/README.rst +++ b/README.rst @@ -144,10 +144,18 @@ The full usage:: Use tmux colors in output -p, --powerline-left Use powerline left symbols throughout the output, enables --colors - -v, --vertical-graph - Use vertical bar chart for CPU graph -q, --powerline-right Use powerline right symbols throughout the output, enables --colors + -v, --vertical-graph + Use vertical bar chart for CPU graph + -l , --segments-left + Enable blending bg/fg color (depending on -p or -q use) with segment to left + Provide color to be used depending on -p or -q option for seamless segment blending + Color is an integer value which uses the standard tmux color palette values + -r , --segments-right + Enable blending bg/fg color (depending on -p or -q use) with segment to right + Provide color to be used depending on -p or -q option for seamless segment blending + Color is an integer value which uses the standard tmux color palette values -i , --interval Set tmux status refresh interval in seconds. Default: 1 second -g , --graph-lines @@ -159,7 +167,37 @@ The full usage:: -a , --averages-count Set how many load-averages should be drawn. Default: 3 +Blending Dynamic Colors Tmux Powerline Segments +=============================================== +The -l and -r options when used in conjunction with a recent version of Tmux Powerline +that has the ability to selectively disable spacing and separators between segments allow +for seamless blending of tmux-mem-cpu-load output with other adjacent segments. The end +result is dynamic changing of appropriate foreground and background colors as the start +and end of the tmux-mem-cpu-load output string that is aggregated with other Tmux +Powerline output to produce a more polished status line in Tmux. + +Segment Adjaceny before this feature: + +.. image:: seg-adj1.png + +Segment Adjaceny after this feature: + +.. image:: seg-adj2.png + +Note that the values for the -l and -r options will be the standard Tmux integer color +values. They set the appropriate background and foreground colors used for the separator +character when used with the poweline-left or powerline-right options so it is easy to +match coloring to adjacent segments. An example from the segment script that calls +tmux-mem-cpu-load is as follows:: + + tmux-mem-cpu-load -q -v -l 52 -r 33 + +This combines with theme options available to tmux-powerline, such as the following:: + + "disk_usage_cust 52 123 ${TMUX_POWERLINE_SEPARATOR_LEFT_BOLD} 52 123 right_disable" \ + "tmux_mem_cpu_load_cust 52 234 ${TMUX_POWERLINE_SEPARATOR_LEFT_BOLD} 52 234 both_disable separator_disable" \ + "batt_cust 33 154 ${TMUX_POWERLINE_SEPARATOR_LEFT_BOLD} 16 33 N separator_disable" \ Authors ======= diff --git a/common/load.cc b/common/load.cc index 092ba8f..3d3d92c 100644 --- a/common/load.cc +++ b/common/load.cc @@ -26,6 +26,7 @@ #include // getloadavg() #include // floorf() #include +#include #include "cpu.h" #include "load.h" @@ -35,8 +36,8 @@ // Load Averages std::string load_string( bool use_colors, - bool use_powerline_left, bool use_powerline_right, - short num_averages ) + bool use_powerline_left, bool use_powerline_right, short num_averages, + bool segments_to_right, short right_color ) { std::ostringstream ss; ss.setf( std::ios::fixed, std::ios::floatfield ); @@ -97,7 +98,12 @@ std::string load_string( bool use_colors, if( use_colors ) { - if( use_powerline_left ) + if( use_powerline_left && segments_to_right ) + { + powerline( ss, load_lut[load_percent], POWERLINE_LEFT, true ); + powerline_char( ss, load_lut[load_percent], right_color, POWERLINE_LEFT, true ); + } + else if( use_powerline_left && !segments_to_right ) { powerline( ss, load_lut[load_percent], POWERLINE_LEFT, true ); powerline( ss, "#[fg=default,bg=default]", POWERLINE_LEFT ); @@ -106,6 +112,10 @@ std::string load_string( bool use_colors, { ss << "#[fg=default,bg=default]"; } + else if ( segments_to_right && use_powerline_right ) + { + powerline_char( ss, load_lut[load_percent], right_color, POWERLINE_RIGHT, true ); + } } } diff --git a/common/load.h b/common/load.h index 4b57015..5f1f98b 100644 --- a/common/load.h +++ b/common/load.h @@ -24,6 +24,7 @@ std::string load_string( bool use_colors = false, bool use_powerline_left = false, bool use_powerline_right = false, - short num_averages = 3 ); + short num_averages = 3, bool segments_to_right = false, + short right_color = 0 ); #endif diff --git a/common/main.cc b/common/main.cc index e684467..ea27a71 100644 --- a/common/main.cc +++ b/common/main.cc @@ -131,6 +131,14 @@ void print_help() << "\tUse powerline right symbols throughout the output, enables --colors\n" << "-v, --vertical-graph\n" << "\tUse vertical bar chart for CPU graph\n" + << "-l , --segments-left \n" + << "\tEnable blending bg/fg color (depending on -p or -q use) with segment to left\n" + << "\tProvide color to be used depending on -p or -q option for seamless segment blending\n" + << "\tColor is an integer value which uses the standard tmux color palette values\n" + << "-r , --segments-right \n" + << "\tEnable blending bg/fg color (depending on -p or -q use) with segment to right\n" + << "\tProvide color to be used depending on -p or -q option for seamless segment blending\n" + << "\tColor is an integer value which uses the standard tmux color palette values\n" << "-i , --interval \n" << "\tSet tmux status refresh interval in seconds. Default: 1 second\n" << "-g , --graph-lines \n" @@ -149,10 +157,14 @@ int main( int argc, char** argv ) unsigned cpu_usage_delay = 990000; short averages_count = 3; short graph_lines = 10; // max 32767 should be enough + short left_color = 0; + short right_color = 0; bool use_colors = false; bool use_powerline_left = false; bool use_powerline_right = false; bool use_vert_graph = false; + bool segments_to_left = false; + bool segments_to_right= false; MEMORY_MODE mem_mode = MEMORY_MODE_DEFAULT; CPU_MODE cpu_mode = CPU_MODE_DEFAULT; @@ -172,12 +184,14 @@ int main( int argc, char** argv ) { "mem-mode", required_argument, NULL, 'm' }, { "cpu-mode", required_argument, NULL, 't' }, { "averages-count", required_argument, NULL, 'a' }, + { "segments-left", required_argument, NULL, 'l' }, + { "segments-right", required_argument, NULL, 'r' }, { 0, 0, 0, 0 } // used to handle unknown long options }; int c; // while c != -1 - while( (c = getopt_long( argc, argv, "hi:cpqvg:m:a:t:", long_options, NULL) ) != -1 ) + while( (c = getopt_long( argc, argv, "hi:cpqvl:r:g:m:a:t:", long_options, NULL) ) != -1 ) { switch( c ) { @@ -199,6 +213,24 @@ int main( int argc, char** argv ) case 'v': // --vertical-graph use_vert_graph = true; break; + case 'l': // --segments-left + segments_to_left = true; + if( atoi( optarg ) < 0 || atoi( optarg ) > 255 ) + { + std::cerr << "Valid color vaues are from 0 to 255.\n"; + return EXIT_FAILURE; + } + left_color = atoi( optarg ) ; + break; + case 'r': // --segments-right + segments_to_right= true; + if( atoi( optarg ) < 0 || atoi( optarg ) > 255 ) + { + std::cerr << "Valid color vaues are from 0 to 255.\n"; + return EXIT_FAILURE; + } + right_color = atoi( optarg ) ; + break; case 'i': // --interval, -i if( atoi( optarg ) < 1 ) { @@ -259,9 +291,9 @@ int main( int argc, char** argv ) MemoryStatus memory_status; mem_status( memory_status ); - std::cout << mem_string( memory_status, mem_mode, use_colors, use_powerline_left, use_powerline_right ) + std::cout << mem_string( memory_status, mem_mode, use_colors, use_powerline_left, use_powerline_right, segments_to_left, left_color ) << cpu_string( cpu_mode, cpu_usage_delay, graph_lines, use_colors, use_powerline_left, use_powerline_right, use_vert_graph ) - << load_string( use_colors, use_powerline_left, use_powerline_right, averages_count ); + << load_string( use_colors, use_powerline_left, use_powerline_right, averages_count, segments_to_right, right_color ); std::cout << std::endl; diff --git a/common/memory.cc b/common/memory.cc index ed84ba7..1af23e4 100644 --- a/common/memory.cc +++ b/common/memory.cc @@ -28,7 +28,9 @@ std::string mem_string( const MemoryStatus & mem_status, MEMORY_MODE mode, bool use_colors, bool use_powerline_left, - bool use_powerline_right ) + bool use_powerline_right, + bool segments_to_left, + short left_color ) { std::ostringstream oss; // Change the percision for floats, for a pretty output @@ -38,12 +40,22 @@ std::string mem_string( const MemoryStatus & mem_status, unsigned int color = static_cast< unsigned int >((100 * mem_status.used_mem) / mem_status.total_mem); if( use_colors ) { - if( use_powerline_right ) + if( use_powerline_right && segments_to_left ) + { + powerline_char( oss, mem_lut[color], left_color, POWERLINE_RIGHT, false); + oss << ' '; + } + else if( use_powerline_right && !segments_to_left ) { oss << "#[bg=default]"; powerline( oss, mem_lut[color], POWERLINE_RIGHT ); oss << ' '; } + else if( use_powerline_left && segments_to_left ) + { + powerline_char( oss, mem_lut[color], left_color, POWERLINE_LEFT, false); + oss << ' '; + } else if( use_powerline_left ) { //powerline( oss, mem_lut[color], POWERLINE_LEFT ); diff --git a/common/memory.h b/common/memory.h index 5e11025..e702784 100644 --- a/common/memory.h +++ b/common/memory.h @@ -51,6 +51,8 @@ std::string mem_string( const MemoryStatus & mem_status, MEMORY_MODE mode = MEMORY_MODE_DEFAULT, bool use_colors = false, bool use_powerline_left = false, - bool use_powerline_right = false ); + bool use_powerline_right = false, + bool segments_to_left = false, + short left_color = 0 ); #endif diff --git a/common/powerline.cc b/common/powerline.cc index d4e5cf8..b88afe2 100644 --- a/common/powerline.cc +++ b/common/powerline.cc @@ -66,3 +66,35 @@ void powerline( std::ostringstream & oss, const char color[], break; }; } + +void powerline_char( std::ostringstream & oss, const char dynamic_color[], + short static_color, POWERLINE_DIRECTION direction, bool eol ) +{ + char write_color[7]; + sprintf(write_color, "%d", static_color); + switch( direction ) + { + case POWERLINE_LEFT: + if ( eol ) + { + oss << bg2fg( dynamic_color ) << "#[bg=colour" << write_color << "]"; + } + else + { + oss << dynamic_color << "#[fg=colour" << write_color << "]"; + } + oss << PWL_LEFT_FILLED << dynamic_color; + break; + case POWERLINE_RIGHT: + if ( eol ) + { + oss << dynamic_color << "#[fg=colour" << write_color << "] "; + } + else + { + oss << bg2fg(dynamic_color) << " #[bg=colour" << write_color << "]"; + } + oss << PWL_RIGHT_FILLED << dynamic_color; + break; + } +} diff --git a/common/powerline.h b/common/powerline.h index 367d86d..e6ad299 100644 --- a/common/powerline.h +++ b/common/powerline.h @@ -34,5 +34,7 @@ enum POWERLINE_DIRECTION * in the next entr. */ void powerline( std::ostringstream & oss, const char color[], POWERLINE_DIRECTION direction, bool background_only = false ); +void powerline_char( std::ostringstream & oss, const char dynamic_color[], + short static_color, POWERLINE_DIRECTION direction, bool eol = false ); #endif // POWERLINE_H diff --git a/seg-adj1.png b/seg-adj1.png new file mode 100644 index 0000000..c8d57f9 Binary files /dev/null and b/seg-adj1.png differ diff --git a/seg-adj2.png b/seg-adj2.png new file mode 100644 index 0000000..20f8538 Binary files /dev/null and b/seg-adj2.png differ