Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8837 for code/branches


Ignore:
Timestamp:
Aug 13, 2011, 9:41:38 PM (13 years ago)
Author:
landauf
Message:

added console command "orxout" (and also "orxout_context")
re-added the shortcut commands log, error, warning, status, info, and debug
adjusted init.tcl

Location:
code/branches/output
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/output/data/tcl/init.tcl

    r7914 r8837  
    169169    foreach {channel s} $input break
    170170
    171     if {$channel == "stdout" || $channel == "stderr"} {
    172         execute puts $newline $s
     171    if {$channel == "stdout"} {
     172        execute log $s
     173    } elseif {$channel == "stderr"} {
     174        execute error $s
    173175    } else {
    174176        eval [concat ::tcl::puts $args]
  • code/branches/output/src/libraries/core/command/ConsoleCommandCompilation.cc

    r8806 r8837  
    4646namespace orxonox
    4747{
     48    SetConsoleCommand("echo", echo);
     49
     50    SetConsoleCommand("orxout", orxout_level);
     51    SetConsoleCommand("orxout_context", orxout_level_context);
     52
     53    SetConsoleCommand("log"    , log    );
     54    SetConsoleCommand("error"  , error  ).hide();
     55    SetConsoleCommand("warning", warning).hide();
     56    SetConsoleCommand("status" , status ).hide();
     57    SetConsoleCommand("info"   , info   ).hide();
     58    SetConsoleCommand("debug"  , debug  ).hide();
     59
    4860//    SetConsoleCommand("source", source).argumentCompleter(0, autocompletion::files());  // disabled because we use the implementation in Tcl
    49     SetConsoleCommand("echo", echo);
    50 
    5161//    SetConsoleCommand("read", read).argumentCompleter(0, autocompletion::files());      // disabled because we use the implementation in Tcl
    5262//    SetConsoleCommand("append", append).argumentCompleter(0, autocompletion::files());  // disabled because we use the implementation in Tcl
     
    5666
    5767    /**
     68        @brief Simply returns the arguments.
     69    */
     70    std::string echo(const std::string& text)
     71    {
     72        return text;
     73    }
     74
     75    /**
     76        @brief Builds a map that maps the levels of all output levels to their ID.
     77    */
     78    std::map<std::string, OutputLevel> getOutputLevelsMap()
     79    {
     80        std::map<std::string, OutputLevel> levels;
     81
     82        levels["message"]          = level::message;
     83        levels["debug_output"]     = level::debug_output;
     84        levels["user_error"]       = level::user_error;
     85        levels["user_warning"]     = level::user_warning;
     86        levels["user_status"]      = level::user_status;
     87        levels["user_info"]        = level::user_info;
     88        levels["internal_error"]   = level::internal_error;
     89        levels["internal_warning"] = level::internal_warning;
     90        levels["internal_status"]  = level::internal_status;
     91        levels["internal_info"]    = level::internal_info;
     92        levels["verbose"]          = level::verbose;
     93        levels["verbose_more"]     = level::verbose_more;
     94        levels["verbose_ultra"]    = level::verbose_ultra;
     95
     96        return levels;
     97    }
     98
     99    /**
     100        @brief Prints text to the console.
     101        @param level_name The name of the output level
     102    */
     103    void orxout_level(const std::string& level_name, const std::string& text)
     104    {
     105        static std::map<std::string, OutputLevel> levels = getOutputLevelsMap();
     106
     107        OutputLevel level = level::debug_output;
     108        std::map<std::string, OutputLevel>::iterator it = levels.find(level_name);
     109        if (it != levels.end())
     110            level = it->second;
     111        else
     112            orxout(internal_warning) << "'" << level_name << "' is not a valid output level" << endl;
     113
     114        orxout(level) << text << endl;
     115    }
     116
     117    /**
     118        @brief Prints text to the console.
     119        @param level_name The name of the output level
     120        @param context_name The name of the output context
     121    */
     122    void orxout_level_context(const std::string& level_name, const std::string& context_name, const std::string& text)
     123    {
     124        static std::map<std::string, OutputLevel> levels = getOutputLevelsMap();
     125
     126        OutputLevel level = level::debug_output;
     127        std::map<std::string, OutputLevel>::iterator it = levels.find(level_name);
     128        if (it != levels.end())
     129            level = it->second;
     130        else
     131            orxout(internal_warning) << "'" << level_name << "' is not a valid output level" << endl;
     132
     133        OutputContextContainer context = registerContext(context_name);
     134
     135        orxout(level, context) << text << endl;
     136    }
     137
     138    /// @brief Prints text to the console and the logfile.
     139    void log(const std::string& text)
     140    { orxout() << text << endl; }
     141
     142    /// @brief Prints output with error level.
     143    void error(const std::string& text)
     144    { orxout(user_error) << text << endl; }
     145
     146    /// @brief Prints output with warning level.
     147    void warning(const std::string& text)
     148    { orxout(user_warning) << text << endl; }
     149
     150    /// @brief Prints output with status level.
     151    void status(const std::string& text)
     152    { orxout(user_status) << text << endl; }
     153
     154    /// @brief Prints output with info level.
     155    void info(const std::string& text)
     156    { orxout(user_info) << text << endl; }
     157
     158    /// @brief Prints debug output with verbose level.
     159    void debug(const std::string& text)
     160    { orxout(verbose, context::tcl) << text << endl; }
     161
     162    /**
    58163        @brief Reads the content of a file and executes the commands in it line by line.
    59164    */
     
    91196        executingFiles.erase(filename);
    92197        file.close();
    93     }
    94 
    95     /**
    96         @brief Simply returns the arguments.
    97     */
    98     std::string echo(const std::string& text)
    99     {
    100         return text;
    101198    }
    102199
  • code/branches/output/src/libraries/core/command/ConsoleCommandCompilation.h

    r8806 r8837  
    4343    _CoreExport std::string echo(const std::string& text);
    4444
     45    _CoreExport void orxout_level(const std::string& level_name, const std::string& text);
     46    _CoreExport void orxout_level_context(const std::string& level_name, const std::string& context_name, const std::string& text);
     47
     48    _CoreExport void log(const std::string& text);
     49    _CoreExport void error(const std::string& text);
     50    _CoreExport void warning(const std::string& text);
     51    _CoreExport void status(const std::string& text);
     52    _CoreExport void info(const std::string& text);
     53    _CoreExport void debug(const std::string& text);
     54
    4555    _CoreExport void write(const std::string& filename, const std::string& text);
    4656    _CoreExport void append(const std::string& filename, const std::string& text);
  • code/branches/output/src/libraries/core/command/Shell.cc

    r8836 r8837  
    4747#include "core/input/InputBuffer.h"
    4848#include "CommandExecutor.h"
    49 #include "ConsoleCommand.h"
    5049
    5150namespace orxonox
    5251{
    53 #pragma message(__FILE__ "("BOOST_PP_STRINGIZE(__LINE__)") : Warning: TODO: add commands again, inspect tcl support (and remove boost include)")
    54 //    SetConsoleCommand("log",     OutputHandler::log    );
    55 //    SetConsoleCommand("error",   OutputHandler::error  ).hide();
    56 //    SetConsoleCommand("warning", OutputHandler::warning).hide();
    57 //    SetConsoleCommand("info",    OutputHandler::info   ).hide();
    58 //    SetConsoleCommand("debug",   OutputHandler::debug  ).hide();
    59 
    6052    unsigned int Shell::cacheSize_s;
    6153
Note: See TracChangeset for help on using the changeset viewer.