PCL
Console.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.6.5
6 // ----------------------------------------------------------------------------
7 // pcl/Console.h - Released 2024-01-13T15:47:58Z
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-2024 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 (https://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 
377  : m_handle( x.m_handle )
378  , m_thread( x.m_thread )
379  {
380  x.m_handle = x.m_thread = nullptr;
381  }
382 
387  Console& operator =( const Console& ) = delete;
388 
392  Console& operator =( Console&& x )
393  {
394  if ( &x != this )
395  {
396  m_handle = x.m_handle;
397  m_thread = x.m_thread;
398  x.m_handle = x.m_thread = nullptr;
399  }
400  return *this;
401  }
402 
406  virtual ~Console();
407 
411  void Write( const String& s );
412 
420  void WriteLn( const String& s );
421 
428  void WriteLn();
429 
437  void Note( const String& s )
438  {
439  Write( "\x1b[32m" + s + "\x1b[39m" );
440  }
441 
448  void NoteLn( const String& s )
449  {
450  WriteLn( "\x1b[32m" + s + "\x1b[39m" );
451  }
452 
460  void Warning( const String& s )
461  {
462  Write( "\x1b[35m" + s + "\x1b[39m" );
463  }
464 
471  void WarningLn( const String& s )
472  {
473  WriteLn( "\x1b[35m" + s + "\x1b[39m" );
474  }
475 
483  void Critical( const String& s )
484  {
485  Write( "\x1b[31m" + s + "\x1b[39m" );
486  }
487 
494  void CriticalLn( const String& s )
495  {
496  WriteLn( "\x1b[31m" + s + "\x1b[39m" );
497  }
498 
509  int ReadChar();
510 
523  String ReadString();
524 
529  bool Suspended() const;
530 
534  bool Waiting() const;
535 
539  bool AbortEnabled() const;
540 
545  bool AbortRequested() const;
546 
562  void ResetStatus();
563 
573  void EnableAbort();
574 
584  void DisableAbort();
585 
595  void Abort();
596 
601  bool IsValid() const;
602 
607  bool IsCurrentThreadConsole() const;
608 
613  void Flush();
614 
631  bool Show( bool show = true );
632 
644  bool Hide( bool hide = true )
645  {
646  return Show( !hide );
647  }
648 
661  void Clear();
662 
666  void ExecuteCommand( const String& command );
667 
714  void ExecuteScript( const String& filePath, const StringKeyValueList& arguments = StringKeyValueList() );
715 
731  void ExecuteScriptGlobal( const String& filePath, const StringKeyValueList& arguments = StringKeyValueList() );
732 
747  void ExecuteScriptOn( const View& view, const String& filePath, const StringKeyValueList& arguments = StringKeyValueList() );
748 
749 protected:
750 
751  void* m_handle = nullptr;
752 
753 private:
754 
755  void* m_thread = nullptr;
756 };
757 
758 // ----------------------------------------------------------------------------
759 
769 template <typename T>
770 inline Console& operator <<( Console& o, T t )
771 {
772  o.Write( String( t ) );
773  return o;
774 }
775 
781 inline Console& operator <<( Console& o, const char* s )
782 {
783  o.Write( s );
784  return o;
785 }
786 
792 inline Console& operator <<( Console& o, const String& s )
793 {
794  o.Write( s );
795  return o;
796 }
797 
803 inline Console& operator >>( Console& o, char& c )
804 {
805  c = o.ReadChar();
806  return o;
807 }
808 
815 {
816  s = o.ReadString();
817  return o;
818 }
819 
820 // ----------------------------------------------------------------------------
821 
822 } // pcl
823 
824 #endif // __PCL_BUILDING_PIXINSIGHT_APPLICATION
825 
826 #endif // __PCL_Console_h
827 
828 // ----------------------------------------------------------------------------
829 // EOF pcl/Console.h - Released 2024-01-13T15:47:58Z
pcl
PCL root namespace.
Definition: AbstractImage.h:76
pcl::Console::CriticalLn
void CriticalLn(const String &s)
Definition: Console.h:494
pcl::Console::Console
Console(Console &&x)
Definition: Console.h:376
pcl::Console::Critical
void Critical(const String &s)
Definition: Console.h:483
pcl::String
Unicode (UTF-16) string.
Definition: String.h:8112
pcl::View
High-level interface to a PixInsight view object.
Definition: View.h:212
pcl::Console::Warning
void Warning(const String &s)
Definition: Console.h:460
pcl::Console::Write
void Write(const String &s)
pcl::Console::Note
void Note(const String &s)
Definition: Console.h:437
pcl::Console::ReadString
String ReadString()
pcl::operator<<
Array< T, A > & operator<<(Array< T, A > &x, const V &v)
Definition: Array.h:2118
pcl::operator>>
Console & operator>>(Console &o, char &c)
Definition: Console.h:803
pcl::Console::ReadChar
int ReadChar()
pcl::Console
A high-level interface to a PixInsight processing console.
Definition: Console.h:358
pcl::Array
Generic dynamic array.
Definition: Array.h:99
StringList.h
pcl::Console::NoteLn
void NoteLn(const String &s)
Definition: Console.h:448
pcl::Console::Hide
bool Hide(bool hide=true)
Definition: Console.h:644
pcl::Console::WarningLn
void WarningLn(const String &s)
Definition: Console.h:471
Defs.h