text:
/*
@copyright Louis Dionne 2015
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
 */

#include <boost/hana.hpp>

#include <test/numeric.hpp>

#include <boost/hana/assert.hpp>
#include <boost/hana/tuple.hpp>

#include <laws/base.hpp>
#include <laws/comparable.hpp>
#include <laws/euclidean_ring.hpp>
#include <laws/group.hpp>
#include <laws/logical.hpp>
#include <laws/monoid.hpp>
#include <laws/orderable.hpp>
#include <test/cnumeric.hpp>

#include <cstdlib>
#include <vector>
using namespace boost::hana;

struct invalid {
    template <typename T>
    operator T const() { std::abort(); }
};

int main() {
    //////////////////////////////////////////////////////////////////////////
    // Comparable
    //////////////////////////////////////////////////////////////////////////
    {
        test::_injection<0> f{};
        auto x = test::numeric(1);
        auto y = test::numeric(2);

        // equal
        {
            BOOST_HANA_CONSTEXPR_CHECK(equal(x, x));
            BOOST_HANA_CONSTEXPR_CHECK(not_(equal(x, y)));
        }

        // not_equal
        {
            BOOST_HANA_CONSTEXPR_CHECK(not_equal(x, y));
            BOOST_HANA_CONSTEXPR_CHECK(not_(not_equal(x, x)));
        }

        // comparing
        {
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                comparing(f)(x, x),
                equal(f(x), f(x))
            ));

            BOOST_HANA_CONSTEXPR_CHECK(equal(
                comparing(f)(x, y),
                equal(f(x), f(y))
            ));
        }
    }

    //////////////////////////////////////////////////////////////////////////
    // Orderable
    //////////////////////////////////////////////////////////////////////////
    {
        auto ord = test::numeric;

        // test::_injection is also monotonic
        test::_injection<0> f{};

        // less
        {
            BOOST_HANA_CONSTEXPR_CHECK(less(ord(0), ord(1)));
            BOOST_HANA_CONSTEXPR_CHECK(not_(less(ord(0), ord(0))));
            BOOST_HANA_CONSTEXPR_CHECK(not_(less(ord(1), ord(0))));
        }

        // less_equal
        {
            BOOST_HANA_CONSTEXPR_CHECK(less_equal(ord(0), ord(1)));
            BOOST_HANA_CONSTEXPR_CHECK(less_equal(ord(0), ord(0)));
            BOOST_HANA_CONSTEXPR_CHECK(not_(less_equal(ord(1), ord(0))));
        }

        // greater_equal
        {
            BOOST_HANA_CONSTEXPR_CHECK(greater_equal(ord(1), ord(0)));
            BOOST_HANA_CONSTEXPR_CHECK(greater_equal(ord(0), ord(0)));
            BOOST_HANA_CONSTEXPR_CHECK(not_(greater_equal(ord(0), ord(1))));
        }

        // greater
        {
            BOOST_HANA_CONSTEXPR_CHECK(greater(ord(1), ord(0)));
            BOOST_HANA_CONSTEXPR_CHECK(not_(greater(ord(0), ord(0))));
            BOOST_HANA_CONSTEXPR_CHECK(not_(greater(ord(0), ord(1))));
        }

        // max
        {
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                max(ord(0), ord(0)), ord(0)
            ));
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                max(ord(1), ord(0)), ord(1)
            ));
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                max(ord(0), ord(1)), ord(1)
            ));
        }

        // min
        {
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                min(ord(0), ord(0)),
                ord(0)
            ));
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                min(ord(1), ord(0)),
                ord(0)
            ));
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                min(ord(0), ord(1)),
                ord(0)
            ));
        }

        // ordering
        {
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                ordering(f)(ord(1), ord(0)),
                less(f(ord(1)), f(ord(0)))
            ));

            BOOST_HANA_CONSTEXPR_CHECK(equal(
                ordering(f)(ord(0), ord(1)),
                less(f(ord(0)), f(ord(1)))
            ));

            BOOST_HANA_CONSTEXPR_CHECK(equal(
                ordering(f)(ord(0), ord(0)),
                less(f(ord(0)), f(ord(0)))
            ));
        }
    }

    //////////////////////////////////////////////////////////////////////////
    // Monoid
    //////////////////////////////////////////////////////////////////////////
    {
        constexpr int x = 2, y = 3;

        // zero
        {
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                zero<test::Numeric>(), test::numeric(0)
            ));
        }

        // plus
        {
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                plus(test::numeric(x), test::numeric(y)),
                test::numeric(x + y)
            ));
        }
    }

    //////////////////////////////////////////////////////////////////////////
    // Group
    //////////////////////////////////////////////////////////////////////////
    {
        constexpr int x = 2, y = 3;

        // minus
        {
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                minus(test::numeric(x), test::numeric(y)),
                test::numeric(x - y)
            ));
        }

        // negate
        {
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                negate(test::numeric(x)),
                test::numeric(-x)
            ));
        }
    }

    //////////////////////////////////////////////////////////////////////////
    // Ring
    //////////////////////////////////////////////////////////////////////////
    {
        constexpr int x = 2, y = 3;

        // one
        {
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                one<test::Numeric>(),
                test::numeric(1)
            ));
        }

        // mult
        {
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                mult(test::numeric(x), test::numeric(y)),
                test::numeric(x * y)
            ));
        }

        // power
        {
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                power(test::numeric(x), zero<test::CNumeric<int>>()),
                one<test::Numeric>()
            ));

            BOOST_HANA_CONSTEXPR_CHECK(equal(
                power(test::numeric(x), one<test::CNumeric<int>>()),
                test::numeric(x)
            ));

            BOOST_HANA_CONSTEXPR_CHECK(equal(
                power(test::numeric(x), test::cnumeric<int, 2>),
                mult(test::numeric(x), test::numeric(x))
            ));

            BOOST_HANA_CONSTEXPR_CHECK(equal(
                power(test::numeric(x), test::cnumeric<int, 3>),
                mult(mult(test::numeric(x), test::numeric(x)), test::numeric(x))
            ));
        }
    }

    //////////////////////////////////////////////////////////////////////////
    // EuclideanRing
    //////////////////////////////////////////////////////////////////////////
    {
        constexpr int x = 6, y = 3, z = 4;

        // div
        {
            using boost::hana::div; // hide ::div
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                div(test::numeric(x), test::numeric(y)),
                test::numeric(x / y)
            ));

            BOOST_HANA_CONSTEXPR_CHECK(equal(
                div(test::numeric(x), test::numeric(z)),
                 test::numeric(x/ z)
            ));
        }

        // mod
        {
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                mod(test::numeric(x), test::numeric(y)),
                test::numeric(x % y)
            ));

            BOOST_HANA_CONSTEXPR_CHECK(equal(
                mod(test::numeric(x), test::numeric(z)),
                test::numeric(x % z)
            ));
        }
    }

    //////////////////////////////////////////////////////////////////////////
    // Logical
    //////////////////////////////////////////////////////////////////////////
    {
        auto logical = test::numeric;
        auto comparable = test::numeric;

        // not_
        {
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                not_(logical(true)),
                logical(false)
            ));
        }

        // and_
        {
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                and_(logical(true)),
                logical(true)
            ));
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                and_(logical(false)),
                logical(false)
            ));

            BOOST_HANA_CONSTEXPR_CHECK(equal(
                and_(logical(true), logical(true)),
                logical(true)
            ));
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                and_(logical(true), logical(false)),
                logical(false)
            ));
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                and_(logical(false), invalid{}),
                logical(false)
            ));

            BOOST_HANA_CONSTEXPR_CHECK(equal(
                and_(logical(true), logical(true), logical(true)),
                logical(true)
            ));
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                and_(logical(true), logical(true), logical(false)),
                logical(false)
            ));
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                and_(logical(true), logical(false), invalid{}),
                logical(false)
            ));
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                and_(logical(false), invalid{}, invalid{}),
                logical(false)
            ));
        }

        // or_
        {
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                or_(logical(true)),
                logical(true)
            ));
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                or_(logical(false)),
                logical(false)
            ));

            BOOST_HANA_CONSTEXPR_CHECK(equal(
                or_(logical(false), logical(false)),
                logical(false)
            ));
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                or_(logical(false), logical(true)),
                logical(true)
            ));
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                or_(logical(true), invalid{}),
                logical(true)
            ));

            BOOST_HANA_CONSTEXPR_CHECK(equal(
                or_(logical(false), logical(false), logical(false)),
                logical(false)
            ));
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                or_(logical(false), logical(false), logical(true)),
                logical(true)
            ));
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                or_(logical(false), logical(true), invalid{}),
                logical(true)
            ));
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                or_(logical(true), invalid{}, invalid{}),
                logical(true)
            ));
        }

        // if_
        {
            BOOST_HANA_CONSTEXPR_CHECK(equal(
                if_(logical(true), comparable(0), comparable(1)),
                comparable(0)
            ));

            BOOST_HANA_CONSTEXPR_CHECK(equal(
                if_(logical(false), comparable(0), comparable(1)),
                comparable(1)
            ));
        }

        // eval_if
        {
            auto t = [=](auto) { return comparable(0); };
            auto e = [=](auto) { return comparable(1); };

            BOOST_HANA_CONSTEXPR_CHECK(equal(
                eval_if(logical(true), t, e),
                comparable(0)
            ));

            BOOST_HANA_CONSTEXPR_CHECK(equal(
                eval_if(logical(false), t, e),
                comparable(1)
            ));
        }

        // while_
        {
            auto smaller_than = [](auto n) {
                return [n](auto v) { return v.size() < n; };
            };
            auto f = [](auto v) {
                v.push_back(v.size());
                return v;
            };

            BOOST_HANA_RUNTIME_CHECK(equal(
                while_(smaller_than(0u), std::vector<int>{}, f),
                std::vector<int>{}
            ));

            BOOST_HANA_RUNTIME_CHECK(equal(
                while_(smaller_than(1u), std::vector<int>{}, f),
                std::vector<int>{0}
            ));

            BOOST_HANA_RUNTIME_CHECK(equal(
                while_(smaller_than(2u), std::vector<int>{}, f),
                std::vector<int>{0, 1}
            ));

            BOOST_HANA_RUNTIME_CHECK(equal(
                while_(smaller_than(3u), std::vector<int>{}, f),
                std::vector<int>{0, 1, 2}
            ));

            BOOST_HANA_RUNTIME_CHECK(equal(
                while_(smaller_than(4u), std::vector<int>{}, f),
                std::vector<int>{0, 1, 2, 3}
            ));

            // Make sure it can be called with an lvalue state:
            std::vector<int> v{};
            BOOST_HANA_RUNTIME_CHECK(equal(
                while_(smaller_than(4u), v, f),
                std::vector<int>{0, 1, 2, 3}
            ));
        }

        // while_
        {
            auto less_than = [](auto n) {
                return [n](auto v) { return v.size() < n; };
            };
            auto f = [](auto v) {
                v.push_back(v.size());
                return v;
            };

            BOOST_HANA_RUNTIME_CHECK(equal(
                while_(less_than(0u), std::vector<int>{}, f),
                std::vector<int>{}
            ));

            BOOST_HANA_RUNTIME_CHECK(equal(
                while_(less_than(1u), std::vector<int>{}, f),
                std::vector<int>{0}
            ));

            BOOST_HANA_RUNTIME_CHECK(equal(
                while_(less_than(2u), std::vector<int>{}, f),
                std::vector<int>{0, 1}
            ));

            BOOST_HANA_RUNTIME_CHECK(equal(
                while_(less_than(3u), std::vector<int>{}, f),
                std::vector<int>{0, 1, 2}
            ));

            BOOST_HANA_RUNTIME_CHECK(equal(
                while_(less_than(4u), std::vector<int>{}, f),
                std::vector<int>{0, 1, 2, 3}
            ));

            // Make sure it can be called with an lvalue state:
            std::vector<int> v{};
            BOOST_HANA_RUNTIME_CHECK(equal(
                while_(less_than(4u), v, f),
                std::vector<int>{0, 1, 2, 3}
            ));
        }
    }
}

max_stars_repo_name: qicosmos/hana

max_issues_repo_name: qicosmos/hana

max_forks_repo_name: qicosmos/hana


text:
/*=============================================================================
    Copyright (c) 2001-2014 Joel de Guzman

    Distributed under the Boost Software License, Version 1.0. (See accompanying
    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#if !defined(BOOST_SPIRIT_X3_CALC9_ERROR_HANDLER_HPP)
#define BOOST_SPIRIT_X3_CALC9_ERROR_HANDLER_HPP

#include <boost/spirit/home/x3.hpp>
#include <boost/spirit/home/x3/support/utility/error_reporting.hpp>
#include <boost/spirit/home/x3/support/ast/position_tagged.hpp>
#include "expression.hpp"
#include "statement.hpp"

namespace client { namespace parser
{
    namespace x3 = boost::spirit::x3;

    ////////////////////////////////////////////////////////////////////////////
    //  Our error handler
    ////////////////////////////////////////////////////////////////////////////
    template <typename Iterator>
    using error_handler = x3::error_handler<Iterator>;

    // tag used to get our error handler from the context
    struct error_handler_tag;

    struct error_handler_base
    {
        template <typename Iterator, typename Exception, typename Context>
        x3::error_handler_result on_error(
            Iterator& first, Iterator const& last
          , Exception const& x, Context const& context)
        {
            std::string message = "Error! Expecting: " + x.which() + " here:";
            auto& error_handler = x3::get<error_handler_tag>(context).get();
            error_handler(x.where(), message);
            return x3::error_handler_result::fail;
        }
    };
}}

#endif

ext: hpp

max_stars_repo_name: Abce/boost


text:
#define BOOST_TEST_DYN_LINK
#ifdef STAND_ALONE
#   define BOOST_TEST_MODULE Main
#endif

#include <boost/test/unit_test.hpp>
#include "utility/data_buffer.h"

using namespace reinforcement_learning;
using namespace utility;
using namespace std;

BOOST_AUTO_TEST_CASE(new_data_buffer_is_empty) {
  data_buffer buffer;

  BOOST_CHECK_EQUAL(buffer.str(), "");
}

BOOST_AUTO_TEST_CASE(single_output_to_data_buffer) {
  data_buffer buffer;

  buffer << "test";

  BOOST_CHECK_EQUAL(buffer.str(), "test");
}

BOOST_AUTO_TEST_CASE(multiple_outputs_to_data_buffer) {
  data_buffer buffer;

  const string value_string = "test";
  const size_t value_size_t = 2;

  buffer << value_string << value_size_t << value_string.c_str();

  BOOST_CHECK_EQUAL(buffer.str(), "test2test");
}

BOOST_AUTO_TEST_CASE(remove_last_from_nonempty_data_buffer) {
  data_buffer buffer;

  buffer << "test1";
  buffer.remove_last();

  BOOST_CHECK_EQUAL(buffer.str(), "test");
}

BOOST_AUTO_TEST_CASE(empty_data_buffer_reset) {
  data_buffer buffer;

  buffer.reset();

  BOOST_CHECK_EQUAL(buffer.str(), "");
}

BOOST_AUTO_TEST_CASE(nonempty_data_buffer_reset) {
  data_buffer buffer;

  buffer << "test";
  buffer.reset();

  BOOST_CHECK_EQUAL(buffer.str(), "");
}

BOOST_AUTO_TEST_CASE(translation_data_buffer_reset) {
  data_buffer buffer(translate_func('s', 'n'));

  buffer << "test";

  BOOST_CHECK_EQUAL(buffer.str(), "tent");
}

ext: cc


text:
/*
 * Copyright (c) 2015-2016 Spotify AB
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

#include <string>

#include <boost/test/unit_test.hpp>

#include <spotify/json/decode_context.hpp>
#include <spotify/json/detail/macros.hpp>
#include <spotify/json/detail/skip_chars.hpp>

#include <spotify/json/benchmark/benchmark.hpp>

BOOST_AUTO_TEST_SUITE(spotify)
BOOST_AUTO_TEST_SUITE(json)
BOOST_AUTO_TEST_SUITE(detail)

std::string generate_simple_string(size_t size) {
  std::string string;
  for (size_t i = 0; i < size; i++) {
    char c;
    switch (i % 3) {
      case 0: c = '0' + (i % 10); break;
      case 1: c = 'a' + (i % ('z' - 'a')); break;
      case 2: c = 'A' + (i % ('Z' - 'A')); break;
    }
    string.append(&c, 1);
  }
  return string;
}

BOOST_AUTO_TEST_CASE(benchmark_json_detail_skip_any_simple_characters) {
  const auto json = generate_simple_string(8192);
  volatile size_t n = 0;
  JSON_BENCHMARK(1e6, [&]{
    auto context = decode_context(json.data(), json.data() + json.size());
    *const_cast<bool *>(&context.has_sse42) = false;
    detail::skip_any_simple_characters(context);
    n += context.offset();
  });
}

#if defined(json_arch_x86_sse42)

BOOST_AUTO_TEST_CASE(benchmark_json_detail_skip_any_simple_characters_sse42) {
  const auto json = generate_simple_string(8192);
  volatile size_t n = 0;
  JSON_BENCHMARK(1e6, [&]{
    auto context = decode_context(json.data(), json.data() + json.size());
    detail::skip_any_simple_characters(context);
    n += context.offset();
  });
}

#endif  // defined(json_arch_x86_sse42)

std::string generate_whitespace_string(size_t size) {
  std::string string;
  for (size_t i = 0; i < size; i++) {
    char c;
    switch (i % 4) {
      case 0: c = ' '; break;
      case 1: c = '\t'; break;
      case 2: c = '\n'; break;
      case 3: c = '\r'; break;
    }
    string.append(&c, 1);
  }
  return string;
}

BOOST_AUTO_TEST_CASE(benchmark_json_detail_skip_any_whitespace) {
  const auto json = generate_whitespace_string(8192);
  volatile size_t n = 0;
  JSON_BENCHMARK(1e6, [&]{
    auto context = decode_context(json.data(), json.data() + json.size());
    *const_cast<bool *>(&context.has_sse42) = false;
    detail::skip_any_whitespace(context);
    n += context.offset();
  });
}

#if defined(json_arch_x86_sse42)

BOOST_AUTO_TEST_CASE(benchmark_json_detail_skip_any_whitespace_sse42) {
  const auto json = generate_whitespace_string(8192);
  volatile size_t n = 0;
  JSON_BENCHMARK(1e6, [&]{
    auto context = decode_context(json.data(), json.data() + json.size());
    detail::skip_any_whitespace(context);
    n += context.offset();
  });
}

#endif  // defined(json_arch_x86_sse42)

BOOST_AUTO_TEST_SUITE_END()  // detail
BOOST_AUTO_TEST_SUITE_END()  // json
BOOST_AUTO_TEST_SUITE_END()  // spotify

ext: cpp

max_stars_repo_name: ivangalkin/spotify-json

max_issues_repo_name: ivangalkin/spotify-json

max_forks_repo_name: ivangalkin/spotify-json


text:
////////////////////////////////////////////////////////////////
// Orkid Media Engine
// Copyright 1996-2020, Michael T. Mayers.
// Distributed under the Boost Software License - Version 1.0 - August 17, 2003
// see http://www.boost.org/LICENSE_1_0.txt
////////////////////////////////////////////////////////////////

#include <ork/python/context.h>
// python header must come before qt
#include <orktool/qtui/qtui_tool.h>
#include <ork/kernel/prop.h>
#include <ork/kernel/Array.hpp>
#include <ork/kernel/opq.h>
#if 1
///////////////////////////////////////////////////////////////////////////////
#include <orktool/qtui/qtconsole.h>
#include <QtWidgets/QScrollBar>
#include <QtWidgets/QVBoxLayout>
#include <ork/lev2/qtui/qtui.hpp>
#include <fcntl.h>
#include <boost/algorithm/string.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace ork {
namespace tool {
static int fd_tty_out_slave = -1;
static int fd_tty_err_slave = -1;
static int fd_tty_inp_slave = -1;
///////////////////////////////////////////////////////////////////////////////
static void console_handler();
///////////////////////////////////////////////////////////////////////////////
static QtConsoleWindow* gPCON = nullptr;
void QtConsoleWindow::Register()
{
    gPCON = this;

    opq::mainSerialQueue()->enqueue([&]() {
        /*
        //const char* inpname = slave_inp_name;
        const char* outname = python::slave_out_name;
        const char* errname = python::slave_err_name;

        //fd_tty_inp_slave = open( inpname, O_WRONLY|O_NONBLOCK );
        fd_tty_out_slave = open( outname, O_RDONLY|O_NONBLOCK );
        fd_tty_err_slave = open( errname, O_RDONLY|O_NONBLOCK );

        //assert( fd_tty_inp_slave>=0 );
        assert( fd_tty_out_slave>=0 );
        assert( fd_tty_err_slave>=0 );

        usleep(1<<18);

        console_handler();*/
    });
}
///////////////////////////////////////////////////////////////////////////////
void QtConsoleWindow::AppendOutput( const std::string & data )
{
    /////////////////////////////////
    // alloc line from linepool
    /////////////////////////////////

    auto allocLine = [this]() -> ConsoleLine* {
        static const int kmaxlines = 8;
        auto& used = mLinePool.used();
        if( used.size()>=kmaxlines )
        {
            auto oldine = *used.rbegin();
            assert(oldine);
            mLinePool.deallocate(oldine);
        }
        ConsoleLine* cline = mLinePool.allocate();
        return cline;
    };

    /////////////////////////////////

    std::vector<std::string> strs;
    boost::split(strs, data, boost::is_any_of("\n"));

    int inumstrs = strs.size();

    for( int i=0; i<inumstrs; i++ )
    {
        std::string line = strs[i];
        std::string::size_type pos = line.find("\n");
        if(std::string::npos == pos)
        {
            line += ("\n" );
        }
        auto cline = allocLine();

        cline->Set(line.c_str());

    }

    mOutputText.clear();
    const auto& used_lines = mLinePool.used();
    for( const auto& l : used_lines )
        mOutputText += l->mBuffer;

    auto tout = mpConsoleOutputTextEdit;
    auto tdoc = tout->document();
    tdoc->setPlainText(QString(mOutputText.c_str()));
}
///////////////////////////////////////////////////////////////////////////////
void console_handler()
{
    /////////////////////
    char buf[256];
    int nread = read(fd_tty_out_slave, buf, 254);
    switch( nread )
    {
        case -1:
        {
            if (errno == EAGAIN)
            {
                break;
            }
            perror("read");
            break;
        }
        default:
        {   buf[nread] = 0;
            std::string outstr(&buf[0]);
            if( gPCON )
                gPCON->AppendOutput( outstr );
            break;
        }
    }
    ////////////////////////////
    /*nread = read(0, buf, 254);
    switch( nread )
    {
        case -1:
        {
            if (errno == EAGAIN)
            {
                break;
            }
            perror("read");
            break;
        }
        default:
            for( int i = 0; i < nread; i++)
            {
              write(fd_pty_master, buf+i, 1);
              //fputc(buf[i],fslave);
            }
            break;
    }*/

    //PyGILState_STATE gstate = PyGILState_Ensure();
    //int iret = PyRun_InteractiveOne(fp_pty_master,"???");
    //PyGILState_Release(gstate);
    //fprintf( fp_pty_master, ">>>" );
    //fflush( fp_pty_master );

    /////////////////////

    opq::mainSerialQueue()->enqueue([&]() {
        console_handler();
    });
}
///////////////////////////////////////////////////////////////////////////////

QtConsoleWindow::QtConsoleWindow( bool bfloat, QWidget *pparent )
	: QWidget(pparent)
	, mbEcho( true )
{
	static int viewnum = 0;
	std::string viewname = CreateFormattedString( "Console:%d", viewnum+1 );
	viewnum++;

	//mpDockWidget = new QDockWidget(pparent->tr(viewname.c_str()), pparent);
	//mpDockWidget->setFloating( bfloat );
	//mpDockWidget->setAllowedAreas(Qt::AllDockWidgetAreas );
	//mpDockWidget->setAutoFillBackground(false);

	mpGROUPBOX = new QGroupBox;
	QVBoxLayout *playout = new QVBoxLayout( mpGROUPBOX );

	mpConsoleOutputTextEdit = new QTextEdit( mpGROUPBOX );
	mpConsoleInputTextEdit = new QLineEdit( mpGROUPBOX );

	QPalette p=mpConsoleOutputTextEdit->palette();
    p.setColor(QPalette::Active, QPalette::Base , QColor(0,0,128,255) );
    p.setColor(QPalette::Active, QPalette::Text , QColor(0,255,0,255) );
    mpConsoleOutputTextEdit->setPalette(p);
	mpConsoleOutputTextEdit->setBackgroundRole ( QPalette::Dark );
	mpConsoleOutputTextEdit->setForegroundRole ( QPalette::BrightText );
	mpConsoleOutputTextEdit->setAutoFillBackground(true);
	QFont* consolefont = new QFont("Inconsolata",16);

	mpConsoleOutputTextEdit->setCurrentFont( *consolefont );

    p.setColor(QPalette::Active, QPalette::Base , QColor(128,0,0,255) );
    p.setColor(QPalette::Active, QPalette::Text , QColor(255,255,0,255) );
	mpConsoleInputTextEdit->setPalette(p);

	mpConsoleOutputTextEdit->setReadOnly(true);

	QGroupBox *pwH = new QGroupBox;
	playout->addWidget( mpConsoleOutputTextEdit );
	playout->addWidget( mpConsoleInputTextEdit );
	//QHBoxLayout *playoutH = new QHBoxLayout( pwH );

	//QCheckBox *but = new QCheckBox("echo");
	//playoutH->addWidget( but );
	//playoutH->addWidget( mpConsoleInputTextEdit );

	pwH->resize( 156, 16 );
	mpGROUPBOX->resize( 156, 32 );

	//mpDockWidget->setWidget( pw );
	//mpDockWidget->setMinimumSize( 100, 48 );

	connect( mpConsoleInputTextEdit, SIGNAL(editingFinished()), SLOT(InputDone()) );
	//connect( but, SIGNAL(toggled(bool)), SLOT(EchoToggle()) );

	this->resize( 160, 160 );
	//mpDockWidget->show();

    Register();

}
///////////////////////////////////////////////////////////////////////////////
QtConsoleWindow::~QtConsoleWindow()
{
}
///////////////////////////////////////////////////////////////////////////////
void QtConsoleWindow::EchoToggle( void )
{
	mbEcho = mbEcho ? false : true;
	PropTypeString tstr;
	PropType<bool>::ToString(mbEcho,tstr);

	std::string tglline = CreateFormattedString( "echo = %s", tstr.c_str() );
	AppendOutput(tglline);
}
///////////////////////////////////////////////////////////////////////////////
void QtConsoleWindow::InputDone( void )
{
	QString qstr = mpConsoleInputTextEdit->text();
	std::string sstr = qstr.toStdString();
	if( mbEcho )
	{
		AppendOutput(sstr);
	}
	//printf( "INPUT<%s>\n", sstr.c_str() );
	if( sstr.length() )
	{
    opq::mainSerialQueue()->enqueue([&]() {
			  python::context().call(sstr);
		});
	}
	mpConsoleInputTextEdit->clear();
	//Py::Ctx().Call("print dir(sys)");
	//OrkAssertNotImpl();
}
///////////////////////////////////////////////////////////////////////////////
} } // namespace ork::tool

#endif

max_stars_repo_name: tweakoz/orkid

max_issues_repo_name: tweakoz/orkid

max_forks_repo_name: tweakoz/orkid