PCL
Console.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.1.19
6 // ----------------------------------------------------------------------------
7 // pcl/Console.h - Released 2019-11-07T10:59:34Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2019 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (http://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_Console_h
53 #define __PCL_Console_h
54 
56 
57 #ifndef __PCL_BUILDING_PIXINSIGHT_APPLICATION
58 
59 #include <pcl/Defs.h>
60 
61 #include <pcl/StringList.h>
62 
63 namespace pcl
64 {
65 
66 // ----------------------------------------------------------------------------
67 
68 class PCL_CLASS View;
69 
358 class PCL_CLASS Console
359 {
360 public:
361 
365  Console();
366 
371  Console( const Console& ) = delete;
372 
376  Console( Console&& x ) :
377  m_handle( x.m_handle ), m_thread( x.m_thread )
378  {
379  x.m_handle = x.m_thread = nullptr;
380  }
381 
386  Console& operator =( const Console& ) = delete;
387 
391  Console& operator =( Console&& x )
392  {
393  if ( &x != this )
394  {
395  m_handle = x.m_handle;
396  m_thread = x.m_thread;
397  x.m_handle = x.m_thread = nullptr;
398  }
399  return *this;
400  }
401 
405  virtual ~Console();
406 
410  void Write( const String& s );
411 
419  void WriteLn( const String& s );
420 
427  void WriteLn();
428 
436  void Note( const String& s )
437  {
438  Write( "\x1b[32m" + s + "\x1b[39m" );
439  }
440 
447  void NoteLn( const String& s )
448  {
449  WriteLn( "\x1b[32m" + s + "\x1b[39m" );
450  }
451 
459  void Warning( const String& s )
460  {
461  Write( "\x1b[35m" + s + "\x1b[39m" );
462  }
463 
470  void WarningLn( const String& s )
471  {
472  WriteLn( "\x1b[35m" + s + "\x1b[39m" );
473  }
474 
482  void Critical( const String& s )
483  {
484  Write( "\x1b[31m" + s + "\x1b[39m" );
485  }
486 
493  void CriticalLn( const String& s )
494  {
495  WriteLn( "\x1b[31m" + s + "\x1b[39m" );
496  }
497 
508  int ReadChar();
509 
522  String ReadString();
523 
528  bool Suspended() const;
529 
533  bool Waiting() const;
534 
538  bool AbortEnabled() const;
539 
544  bool AbortRequested() const;
545 
561  void ResetStatus();
562 
572  void EnableAbort();
573 
583  void DisableAbort();
584 
594  void Abort();
595 
600  bool IsValid() const;
601 
606  bool IsCurrentThreadConsole() const;
607 
612  void Flush();
613 
630  bool Show( bool show = true );
631 
643  bool Hide( bool hide = true )
644  {
645  return Show( !hide );
646  }
647 
660  void Clear();
661 
665  void ExecuteCommand( const String& command );
666 
713  void ExecuteScript( const String& filePath, const StringKeyValueList& arguments = StringKeyValueList() );
714 
730  void ExecuteScriptGlobal( const String& filePath, const StringKeyValueList& arguments = StringKeyValueList() );
731 
746  void ExecuteScriptOn( const View& view, const String& filePath, const StringKeyValueList& arguments = StringKeyValueList() );
747 
748 protected:
749 
750  void* m_handle = nullptr;
751 
752 private:
753 
754  void* m_thread = nullptr;
755 };
756 
757 // ----------------------------------------------------------------------------
758 
768 template <typename T>
769 inline Console& operator <<( Console& o, T t )
770 {
771  o.Write( String( t ) );
772  return o;
773 }
774 
780 inline Console& operator <<( Console& o, const char* s )
781 {
782  o.Write( s );
783  return o;
784 }
785 
791 inline Console& operator <<( Console& o, const String& s )
792 {
793  o.Write( s );
794  return o;
795 }
796 
802 inline Console& operator >>( Console& o, char& c )
803 {
804  c = o.ReadChar();
805  return o;
806 }
807 
814 {
815  s = o.ReadString();
816  return o;
817 }
818 
819 // ----------------------------------------------------------------------------
820 
821 } // pcl
822 
823 #endif // __PCL_BUILDING_PIXINSIGHT_APPLICATION
824 
825 #endif // __PCL_Console_h
826 
827 // ----------------------------------------------------------------------------
828 // EOF pcl/Console.h - Released 2019-11-07T10:59:34Z
A high-level interface to a PixInsight processing console.
Definition: Console.h:358
bool Hide(bool hide=true)
Definition: Console.h:643
void CriticalLn(const String &s)
Definition: Console.h:493
void Note(const String &s)
Definition: Console.h:436
void WarningLn(const String &s)
Definition: Console.h:470
PCL root namespace.
Definition: AbstractImage.h:76
Console(Console &&x)
Definition: Console.h:376
void Warning(const String &s)
Definition: Console.h:459
Console & operator>>(Console &o, char &c)
Definition: Console.h:802
void Write(const String &s)
Array< T, A > & operator<<(Array< T, A > &x, const V &v)
Definition: Array.h:2103
Unicode (UTF-16) string.
Definition: String.h:7911
Dynamic list of key-value associations implemented as Unicode (UTF-16) strings.
void Critical(const String &s)
Definition: Console.h:482
High-level interface to a PixInsight view object.
Definition: View.h:167
void NoteLn(const String &s)
Definition: Console.h:447
String ReadString()