Skip to content

Commit

Permalink
Code refactoring for merging
Browse files Browse the repository at this point in the history
- license header in new files
- changed "powerline" into "powerline-right"
- added braces around one-liners
- small fixes concerning whitespace
  • Loading branch information
golinski committed Apr 14, 2016
1 parent e9a3726 commit bac831c
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <value>, --interval <value>
Set tmux status refresh interval in seconds. Default: 1 second
Expand Down
6 changes: 5 additions & 1 deletion common/load.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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]";
}
}
}

Expand Down
10 changes: 7 additions & 3 deletions common/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 <value>, --interval <value>\n"
<< "\tSet tmux status refresh interval in seconds. Default: 1 second\n"
Expand All @@ -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' },
Expand All @@ -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;
Expand Down
30 changes: 26 additions & 4 deletions common/powerline.cc
Original file line number Diff line number Diff line change
@@ -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 <cstring>
Expand All @@ -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;
}
}
18 changes: 18 additions & 0 deletions common/powerline.h
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit bac831c

Please sign in to comment.