]> OCCT Git - occt.git/commitdiff
0031714: Draw Harness - print command name with intense within help output
authorkgv <kgv@opencascade.com>
Tue, 18 Aug 2020 07:10:50 +0000 (10:10 +0300)
committerbugmaster <bugmaster@opencascade.com>
Sat, 22 Aug 2020 09:13:09 +0000 (12:13 +0300)
Added command "dputs" similar to "puts" but with extra arguments modifying text color/intensity.
Command "help" now prints the name of command with intense style.

src/Draw/Draw_BasicCommands.cxx
src/DrawResources/StandardCommands.tcl

index ca79372b1d7d9b26b89405580e5d8578e1848930..c2ef187bb0b7390e3e039e8e168ee3009fe0cc55 100644 (file)
@@ -23,6 +23,7 @@
 #include <Draw_ProgressIndicator.hxx>
 #include <Message.hxx>
 #include <Message_Messenger.hxx>
+#include <Message_PrinterOStream.hxx>
 #include <OSD.hxx>
 #include <OSD_Chronometer.hxx>
 #include <OSD_Environment.hxx>
@@ -1103,6 +1104,99 @@ static int dtracelevel (Draw_Interpretor& theDI,
   return 0;
 }
 
+//==============================================================================
+//function : dputs
+//purpose  :
+//==============================================================================
+static int dputs (Draw_Interpretor& ,
+                  Standard_Integer theArgNb,
+                  const char** theArgVec)
+{
+  Standard_OStream* aStream = &std::cout;
+  bool isNoNewline = false, toIntense = false;
+  Message_ConsoleColor aColor = Message_ConsoleColor_Default;
+  for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter)
+  {
+    TCollection_AsciiString anArg (theArgVec[anArgIter]);
+    anArg.LowerCase();
+    if (anArg == "-nonewline")
+    {
+      isNoNewline = true;
+    }
+    else if (anArg == "stdcout")
+    {
+      aStream = &std::cout;
+    }
+    else if (anArg == "stdcerr")
+    {
+      aStream = &std::cerr;
+    }
+    else if (anArg == "-intense")
+    {
+      toIntense = true;
+    }
+    else if (anArg == "-black")
+    {
+      aColor = Message_ConsoleColor_Black;
+    }
+    else if (anArg == "-white")
+    {
+      aColor = Message_ConsoleColor_White;
+    }
+    else if (anArg == "-red")
+    {
+      aColor = Message_ConsoleColor_Red;
+    }
+    else if (anArg == "-blue")
+    {
+      aColor = Message_ConsoleColor_Blue;
+    }
+    else if (anArg == "-green")
+    {
+      aColor = Message_ConsoleColor_Green;
+    }
+    else if (anArg == "-yellow")
+    {
+      aColor = Message_ConsoleColor_Yellow;
+    }
+    else if (anArg == "-cyan")
+    {
+      aColor = Message_ConsoleColor_Cyan;
+    }
+    else if (anArg == "-magenta")
+    {
+      aColor = Message_ConsoleColor_Magenta;
+    }
+    else if (anArgIter + 1 == theArgNb)
+    {
+      if (toIntense || aColor != Message_ConsoleColor_Default)
+      {
+        Message_PrinterOStream::SetConsoleTextColor (aStream, aColor, toIntense);
+      }
+
+      *aStream << theArgVec[anArgIter];
+      if (!isNoNewline)
+      {
+        *aStream << std::endl;
+      }
+
+      if (toIntense || aColor != Message_ConsoleColor_Default)
+      {
+        Message_PrinterOStream::SetConsoleTextColor (aStream, Message_ConsoleColor_Default, false);
+      }
+      return 0;
+    }
+    else
+    {
+      Message::SendFail() << "Syntax error at '" << anArg << "'";
+      return 1;
+    }
+  }
+
+  Message::SendFail() << "Syntax error: wrong number of arguments";
+  return 1;
+}
+
 void Draw::BasicCommands(Draw_Interpretor& theCommands)
 {
   static Standard_Boolean Done = Standard_False;
@@ -1164,4 +1258,10 @@ void Draw::BasicCommands(Draw_Interpretor& theCommands)
                  __FILE__,dversion,g);
   theCommands.Add("dlocale", "set and / or query locate of C subsystem (function setlocale())",
                  __FILE__,dlocale,g);
+
+  theCommands.Add("dputs",
+            "dputs [-intense] [-black|-white|-red|-green|-blue|-yellow|-cyan|-magenta]"
+    "\n\t\t:       [-nonewline] [stdcout|stdcerr] text"
+    "\n\t\t: Puts text into console output",
+                  __FILE__,dputs,g);
 }
index 4436b606d6510d44abb1f24cee4e74b800bbc748..bcebbde5456a3be80b2016c0c86867b02b2aeda5 100644 (file)
@@ -27,67 +27,56 @@ set tcl_prompt1 {
 
 set tcl_prompt2 {puts -nonewline "> "}
 
-
 #################################################
 # the help command in TCL
 #################################################
-
-
 proc help {{command ""} {helpstring ""} {group "Procedures"}} {
-
-    global Draw_Helps Draw_Groups
-
-    if {$command == ""} {
-
+  global Draw_Helps Draw_Groups
+  if {$command == ""} {
     # help general
     foreach h [lsort [array names Draw_Groups]] {
-        puts ""
-        puts ""
-        puts $h
-        set i 0
-        foreach f [lsort $Draw_Groups($h)] {
+      dputs -intense "\n\n$h"
+      set i 0
+      foreach f [lsort $Draw_Groups($h)] {
         if {$i == 0} {
-            puts ""
-            puts -nonewline "  "
+          puts ""
+          puts -nonewline "  "
         }
         puts -nonewline $f
         for {set j [string length $f]} {$j < 15} {incr j} {
-            puts -nonewline " "
+          puts -nonewline " "
         }
         incr i
         if {$i == 4} {set i 0}
-        }
-        puts ""
+      }
+      puts ""
     }
-    } elseif {$helpstring == ""} {
-
+  } elseif {$helpstring == ""} {
     # help function
     set isfound 0
     foreach f [lsort [array names Draw_Helps]] {
-        if {[string match $command $f]} {
-        puts -nonewline $f
+      if {[string match $command $f]} {
+        dputs -nonewline -intense $f
         for {set j [string length $f]} {$j < 15} {incr j} {
-            puts -nonewline " "
+          puts -nonewline " "
         }
         puts " : $Draw_Helps($f)"
         set isfound 1
-        }
+      }
     }
     if {!$isfound} {
-        if {[string first * $command] != -1} {
-            puts "No matching commands found!"
-        } else {
-            puts "No help found for '$command'! Please try 'help $command*' to find matching commands."
-        }
+      if {[string first * $command] != -1} {
+        puts "No matching commands found!"
+      } else {
+        puts "No help found for '$command'! Please try 'help $command*' to find matching commands."
+      }
     }
-    } else {
-
+  } else {
     # set help
     lappend Draw_Groups($group) $command
     set Draw_Helps($command) $helpstring
-    }
-    
-    flush stdout
+  }
+  flush stdout
 }
 
 help help {help pattern, or help command string group, to set help} {DRAW General Commands}