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>
|
|
|
|
|
2019-07-21 23:31:21 +02:00
|
|
|
#include "final/fc.h"
|
|
|
|
#include "final/fcolorpair.h"
|
|
|
|
#include "final/fstring.h"
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/ftermbuffer.h"
|
2019-07-21 23:31:21 +02:00
|
|
|
#include "final/fvterm.h"
|
|
|
|
#include "final/ftypes.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;
|
2019-08-25 22:16:00 +02:00
|
|
|
wchar_t buffer[BUFSIZE]{};
|
|
|
|
va_list args{};
|
2017-07-12 01:16:57 +02:00
|
|
|
|
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() );
|
2019-08-25 22:16:00 +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
|
|
|
{
|
2019-08-25 22:16:00 +02:00
|
|
|
charData nc = FVTerm::getAttribute(); // next character
|
2017-07-12 01:16:57 +02:00
|
|
|
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)
|
|
|
|
{
|
2019-02-24 00:25:36 +01:00
|
|
|
FVTerm::setColor(pair.fg_color, pair.bg_color);
|
2019-01-30 12:17:48 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
//----------------------------------------------------------------------
|
2019-02-24 00:25:36 +01:00
|
|
|
FTermBuffer::charDataVector& operator << ( FTermBuffer::charDataVector& termString
|
|
|
|
, 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
|