2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ftermbuffer.cpp - Buffer for virtual terminal strings *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2019-01-30 12:17:48 +01:00
|
|
|
* Copyright 2017-2019 Markus Gans *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
|
|
|
* The Final Cut is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 3 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* The Final Cut is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public *
|
|
|
|
* License along with this program. If not, see *
|
|
|
|
* <http://www.gnu.org/licenses/>. *
|
|
|
|
***********************************************************************/
|
2017-07-12 01:16:57 +02:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/ftermbuffer.h"
|
2017-07-12 01:16:57 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
namespace finalcut
|
|
|
|
{
|
2017-07-12 01:16:57 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FTermBuffer
|
|
|
|
//----------------------------------------------------------------------
|
2017-09-11 03:06:02 +02:00
|
|
|
FTermBuffer::~FTermBuffer() // destructor
|
2017-07-12 01:16:57 +02:00
|
|
|
{ }
|
|
|
|
|
|
|
|
// public methods of FTermBuffer
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-05 05:35:33 +02:00
|
|
|
int FTermBuffer::writef (const FString format, ...)
|
2017-07-12 01:16:57 +02:00
|
|
|
{
|
2018-12-26 23:41:49 +01:00
|
|
|
static constexpr int BUFSIZE = 4096;
|
2018-10-05 05:15:54 +02:00
|
|
|
wchar_t buffer[BUFSIZE];
|
2017-07-12 01:16:57 +02:00
|
|
|
va_list args;
|
|
|
|
|
2018-10-05 05:15:54 +02:00
|
|
|
if ( format.isEmpty() )
|
|
|
|
return 0;
|
2017-07-12 01:16:57 +02:00
|
|
|
|
|
|
|
va_start (args, format);
|
2018-10-05 05:15:54 +02:00
|
|
|
std::vswprintf (buffer, BUFSIZE, format.wc_str(), args);
|
2017-07-12 01:16:57 +02:00
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
FString str(buffer);
|
|
|
|
return write(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int FTermBuffer::write (const FString& s)
|
|
|
|
{
|
|
|
|
assert ( ! s.isNull() );
|
2018-09-12 22:51:15 +02:00
|
|
|
int len = 0;
|
2017-07-12 01:16:57 +02:00
|
|
|
const wchar_t* p = s.wc_str();
|
|
|
|
|
|
|
|
if ( p )
|
|
|
|
{
|
|
|
|
while ( *p )
|
|
|
|
{
|
2018-06-25 00:14:53 +02:00
|
|
|
charData nc; // next character
|
2017-07-12 01:16:57 +02:00
|
|
|
nc = FVTerm::getAttribute();
|
|
|
|
nc.code = *p;
|
2017-08-20 17:30:30 +02:00
|
|
|
nc.attr.bit.no_changes = false;
|
|
|
|
nc.attr.bit.printed = false;
|
2017-07-12 01:16:57 +02:00
|
|
|
|
|
|
|
data.push_back(nc);
|
|
|
|
|
|
|
|
p++;
|
|
|
|
len++;
|
2017-09-11 03:06:02 +02:00
|
|
|
} // end of while
|
2017-07-12 01:16:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2019-01-30 12:17:48 +01:00
|
|
|
int FTermBuffer::write (wchar_t c)
|
2017-07-12 01:16:57 +02:00
|
|
|
{
|
2018-06-25 00:14:53 +02:00
|
|
|
charData nc; // next character
|
2017-07-12 01:16:57 +02:00
|
|
|
nc = FVTerm::getAttribute();
|
|
|
|
nc.code = c;
|
2017-08-20 17:30:30 +02:00
|
|
|
nc.attr.bit.no_changes = false;
|
|
|
|
nc.attr.bit.printed = false;
|
2017-07-12 01:16:57 +02:00
|
|
|
|
|
|
|
data.push_back(nc);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-01-30 12:17:48 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FTermBuffer::write (const FColorPair& pair)
|
|
|
|
{
|
|
|
|
charData nc; // next character
|
|
|
|
nc = FVTerm::getAttribute();
|
|
|
|
nc.fg_color = pair.fg_color;
|
|
|
|
nc.bg_color = pair.bg_color;
|
|
|
|
}
|
|
|
|
|
2017-07-12 01:16:57 +02:00
|
|
|
|
2017-08-06 17:02:19 +02:00
|
|
|
// FTermBuffer non-member operators
|
2017-07-12 01:16:57 +02:00
|
|
|
//----------------------------------------------------------------------
|
2018-06-25 00:14:53 +02:00
|
|
|
std::vector<FTermBuffer::charData>& operator << \
|
|
|
|
( std::vector<FTermBuffer::charData>& termString
|
2017-09-11 03:06:02 +02:00
|
|
|
, const FTermBuffer& buf )
|
2017-08-06 17:02:19 +02:00
|
|
|
{
|
|
|
|
if ( ! buf.data.empty() )
|
|
|
|
termString.assign(buf.data.begin(), buf.data.end());
|
|
|
|
|
|
|
|
return termString;
|
|
|
|
}
|
2018-09-20 23:59:01 +02:00
|
|
|
|
|
|
|
} // namespace finalcut
|