From bac831cd69b8a5c92cbce74bdcaab567e7647bfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Goli=C5=84ski?= Date: Thu, 14 Apr 2016 12:18:10 +0200 Subject: [PATCH] Code refactoring for merging - license header in new files - changed "powerline" into "powerline-right" - added braces around one-liners - small fixes concerning whitespace --- CMakeLists.txt | 2 +- README.rst | 2 +- common/load.cc | 6 +++++- common/main.cc | 10 +++++++--- common/powerline.cc | 30 ++++++++++++++++++++++++++---- common/powerline.h | 18 ++++++++++++++++++ 6 files changed, 58 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 512516c..0fa3854 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,7 +80,7 @@ else() endif() # set common source files -set(COMMON_SOURCES "common/main.cc" "common/memory.cc" "common/graph.cc""common/powerline.cc") +set(COMMON_SOURCES "common/main.cc" "common/memory.cc" "common/graph.cc" "common/powerline.cc") # add binary tree so we find version.h include_directories("${PROJECT_BINARY_DIR}") diff --git a/README.rst b/README.rst index 3a98ae9..188ee6f 100644 --- a/README.rst +++ b/README.rst @@ -118,7 +118,7 @@ The full usage:: Prints this help message --colors Use tmux colors in output - --powerline + --powerline-right Use powerline symbols throughout the output, DO NOT reset background color at the end, enables --colors -i , --interval Set tmux status refresh interval in seconds. Default: 1 second diff --git a/common/load.cc b/common/load.cc index 1ed1ebd..926ada8 100644 --- a/common/load.cc +++ b/common/load.cc @@ -77,10 +77,14 @@ std::string load_string( bool use_colors, bool use_powerline ) if( use_colors ) { - if(use_powerline) + if( use_powerline ) + { ss << ' '; + } else + { ss << "#[fg=default,bg=default]"; + } } } diff --git a/common/main.cc b/common/main.cc index df79865..7d3f265 100644 --- a/common/main.cc +++ b/common/main.cc @@ -67,9 +67,13 @@ std::string cpu_string( unsigned int cpu_usage_delay, unsigned int graph_lines, if( use_colors ) { if( use_powerline ) + { oss << ' '; + } else + { oss << "#[fg=default,bg=default]"; + } } return oss.str(); @@ -88,7 +92,7 @@ void print_help() << "-c, --colors\n" << "--colors\n" << "\tUse tmux colors in output\n" - << "-p, --powerline\n" + << "-p, --powerline-right\n" << "\tUse powerline symbols throughout the output, DO NOT reset background color at the end, enables --colors\n" << "-i , --interval \n" << "\tSet tmux status refresh interval in seconds. Default: 1 second\n" @@ -115,7 +119,7 @@ int main( int argc, char** argv ) // otherwise it's a value to set the variable *flag points to { "help", no_argument, NULL, 'h' }, { "colors", no_argument, NULL, 'c' }, - { "powerline", no_argument, NULL, 'p' }, + { "powerline-right", no_argument, NULL, 'p' }, { "interval", required_argument, NULL, 'i' }, { "graph-lines", required_argument, NULL, 'g' }, { "mem-mode", required_argument, NULL, 'm' }, @@ -135,7 +139,7 @@ int main( int argc, char** argv ) case 'c': // --colors use_colors = true; break; - case 'p': // --powerline + case 'p': // --powerline-right use_colors = true; use_powerline = true; break; diff --git a/common/powerline.cc b/common/powerline.cc index 6825eb2..85bac7b 100644 --- a/common/powerline.cc +++ b/common/powerline.cc @@ -1,3 +1,21 @@ +/* vim: tabstop=2 shiftwidth=2 expandtab textwidth=80 linebreak wrap + * + * Copyright 2012 Matthew McCormick + * Copyright 2016 Michał Goliński + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #include "powerline.h" #include @@ -18,10 +36,14 @@ const char * bg2fg(const char s[]) void powerline(std::ostringstream &oss, const char s[], bool use_powerline) { - if (use_powerline) - oss << bg2fg(s) - << PWL_RIGHT_FILLED - << s << ' '; + if( use_powerline ) + { + oss << bg2fg(s) + << PWL_RIGHT_FILLED + << s << ' '; + } else + { oss << s; + } } diff --git a/common/powerline.h b/common/powerline.h index 60b45e8..caf6d93 100644 --- a/common/powerline.h +++ b/common/powerline.h @@ -1,3 +1,21 @@ +/* vim: tabstop=2 shiftwidth=2 expandtab textwidth=80 linebreak wrap + * + * Copyright 2012 Matthew McCormick + * Copyright 2016 Michał Goliński + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #ifndef POWERLINE_H #define POWERLINE_H