//..............................................................................
//
// Serial Monitor log representer
//

import "log_Representer.jnc"
import "SerialMonLogRecordCode.jnc"

//..............................................................................

bool representSerialMonLog  (
	log.RepresenterTarget* target,
	uint64_t recordCode,
	void const* p,
	size_t size,
	uint_t foldFlags
	)
{
	switch (recordCode)
	{
	case SerialMonLogRecordCode.DeviceOpened_old:
		target.m_lineAttr.m_iconIdx = log.StdLogIcon.Connect;
		target.m_lineAttr.m_backColor = log.StdLogColor.Connect;
		target.addHyperText("Port opened");
		break;

	case SerialMonLogRecordCode.DeviceOpened:
		uint32_t pid = *(uint32_t const*) p;
		target.m_lineAttr.m_iconIdx = log.StdLogIcon.Connect;
		target.m_lineAttr.m_backColor = log.StdLogColor.Connect;
		target.addHyperText($"PID \e[34m#$pid\e[m: Port opened");
		break;

	case SerialMonLogRecordCode.DeviceClosed:
		target.m_lineAttr.m_iconIdx = log.StdLogIcon.Disconnect;
		target.m_lineAttr.m_backColor = log.StdLogColor.Disconnect;
		target.addHyperText("Port closed");
		break;

	default:
		return false;
	}

	return true;
}

//..............................................................................
