From 36242ee4f2c24352c547d266a311305007111ac9 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 26 Dec 2006 19:59:58 +0000 Subject: david - woops, forgot to add --- src/viewercolorpct.cpp | 129 +++++++++++++++++++++++++++++++++++++++++++++++++ src/viewercolorpct.h | 49 +++++++++++++++++++ 2 files changed, 178 insertions(+) create mode 100644 src/viewercolorpct.cpp create mode 100644 src/viewercolorpct.h diff --git a/src/viewercolorpct.cpp b/src/viewercolorpct.cpp new file mode 100644 index 0000000..3745a03 --- /dev/null +++ b/src/viewercolorpct.cpp @@ -0,0 +1,129 @@ +#include "viewercolorpct.h" +#include "perform.h" +#include "plugger.h" +#include "math.h" + +PluginInterface2( colorpct, ViewerColorPct, Viewer, "Mike Buland", 0, 1 ); + +ViewerColorPct::ViewerColorPct() : + bRunClean( true ) +{ +} + +ViewerColorPct::~ViewerColorPct() +{ +} + +void ViewerColorPct::beginCommand( Action::eAction nAct, const std::string &sTarget ) +{ + Cmd cmd; + if( sCmd.empty() ) + cmd.nLevel = 0; + else + cmd.nLevel = sCmd.front().nLevel+1; + + cmd.bCmdClean = true; + cmd.sTarget = sTarget; + + sCmd.push_front( cmd ); +} + +void ViewerColorPct::endCommand() +{ + if( sCmd.front().bCmdClean == false ) + printf("\n"); + sCmd.pop_front(); + if(sCmd.empty()) + iCC++; +} + +void ViewerColorPct::indent() +{ + if( sCmd.empty() ) return; + int jmax = sCmd.front().nLevel; + for( int j = 0; j < jmax; j++ ) + { + printf(" "); + } +} + +void ViewerColorPct::printHead() +{ + if( sCmd.front().bCmdClean == true ) + { + bRunClean = false; + sCmd.front().bCmdClean = false; + indent(); + if(sCmd.size() > 1) + printf("\033[37;22m--- \033[34m%s\033[37m ---\n\033[0m", sCmd.front().sTarget.c_str() ); + else + printf("\033[37;1m--- [\033[32m%d/%d\033[37m] \033[34m%s\033[37m ---\n\033[0m", iCC, iTC, sCmd.front().sTarget.c_str() ); + } +} + +void ViewerColorPct::printPerform(const char *sRule, const char *sTarget) +{ + int iPct = (int)round( + ((double)sCmd.front().iCP/(double)sCmd.front().iTP)*100.0 + ); + if(sCmd.size() > 1) + printf( "\033[37;22m[\033[32m%3d%%\033[37m] \033[35m%8s\033[37m: %s\n\033[0m", iPct, sRule, sTarget ); + else + printf( "\033[37;1m[\033[32m%3d%%\033[37m] \033[35m%8s\033[37m: %s\n\033[0m", iPct, sRule, sTarget ); +} + +void ViewerColorPct::beginRequiresCheck( bool bCached, const std::string &sName ) +{ + printHead(); + indent(); + printPerform("deps", sName.c_str()); +} + +void ViewerColorPct::endRequiresCheck() +{ + sCmd.front().iCP++; +} + +void ViewerColorPct::skipRequiresCheck( bool bCached, const std::string &sName ) +{ + sCmd.front().iCP++; +} + +void ViewerColorPct::beginPerform( Perform *pPerform ) +{ + printHead(); + indent(); + printPerform(pPerform->getRule().c_str(), pPerform->getTarget().c_str()); +} + +void ViewerColorPct::endPerform() +{ + sCmd.front().iCP++; +} + +void ViewerColorPct::skipPerform( Perform *pPerform ) +{ + sCmd.front().iCP++; +} + +void ViewerColorPct::beginPerforms( int nCount ) +{ + sCmd.front().iTP = nCount*2; + sCmd.front().iCP = 1; +} + +void ViewerColorPct::beginAction( const std::string &sName, int nCommands ) +{ + iTC = nCommands; + iCC = 1; +} + +void ViewerColorPct::endAction() +{ + if( bRunClean == true ) + { + printf("Nothing to be done.\n\n"); + } + printf("\033[0m"); +} + diff --git a/src/viewercolorpct.h b/src/viewercolorpct.h new file mode 100644 index 0000000..dc810c1 --- /dev/null +++ b/src/viewercolorpct.h @@ -0,0 +1,49 @@ +#ifndef VIEWER_COLOR_PCT_H +#define VIEWER_COLOR_PCT_H + +#include +#include +#include "viewer.h" + +class ViewerColorPct : public Viewer +{ +public: + ViewerColorPct(); + virtual ~ViewerColorPct(); + + virtual void beginCommand( Action::eAction nAct, const std::string &sTarget ); + virtual void endCommand(); + + virtual void beginRequiresCheck( bool bCached, const std::string &sName ); + virtual void endRequiresCheck(); + virtual void beginPerform( Perform *pPerform ); + virtual void endPerform(); + virtual void beginPerforms( int nCount ); + + virtual void skipRequiresCheck( bool bCached, const std::string &sName ); + virtual void skipPerform( Perform *pPerform ); + + virtual void beginAction( const std::string &sName, int nCommands ); + + virtual void endAction(); + + void printPerform(const char *sRule, const char *sTarget); + void printHead(); + void indent(); + +private: + int iTC, iCC; + + bool bRunClean; + typedef struct + { + int nLevel; + bool bCmdClean; + std::string sTarget; + int iTP, iCP; + } Cmd; + typedef std::list CmdStack; + CmdStack sCmd; +}; + +#endif -- cgit v1.2.3