xref: /haiku/src/apps/terminal/TerminalLine.h (revision 71452e98334eaac603bf542d159e24788a46bebb)
1 /*
2  * Copyright 2013, Haiku, Inc. All rights reserved.
3  * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
4  * Distributed under the terms of the MIT License.
5  *
6  * Authors:
7  *		Ingo Weinhold, ingo_weinhold@gmx.de
8  *		Siarzhuk Zharski, zharik@gmx.li
9  */
10 #ifndef TERMINAL_LINE_H
11 #define TERMINAL_LINE_H
12 
13 #include <SupportDefs.h>
14 
15 #include "TermConst.h"
16 
17 #include "UTF8Char.h"
18 
19 
20 struct TerminalCell {
21 	UTF8Char		character;
22 	uint32			attributes;
23 };
24 
25 
26 struct TerminalLine {
27 	uint16			length;
28 	bool			softBreak;	// soft line break
29 	uint32			attributes;
30 	TerminalCell	cells[1];
31 
32 	inline void Clear(uint32 attr = 0, size_t count = 0)
33 	{
34 		length = 0;
35 		attributes = attr;
36 		softBreak = false;
37 		for (size_t i = 0; i < count; i++)
38 			cells[i].attributes = attr;
39 	}
40 };
41 
42 
43 struct AttributesRun {
44 	uint32	attributes;
45 	uint16	offset;			// character offset
46 	uint16	length;			// length of the run in characters
47 };
48 
49 
50 struct HistoryLine {
51 	AttributesRun*	attributesRuns;
52 	uint16			attributesRunCount;	// number of attribute runs
53 	uint16			byteLength : 15;	// number of bytes in the line
54 	bool			softBreak : 1;		// soft line break;
55 	uint32			attributes;
56 
57 	AttributesRun* AttributesRuns() const
58 	{
59 		return attributesRuns;
60 	}
61 
62 	char* Chars() const
63 	{
64 		return (char*)(attributesRuns + attributesRunCount);
65 	}
66 
67 	int32 BufferSize() const
68 	{
69 		return attributesRunCount * sizeof(AttributesRun) + byteLength;
70 	}
71 };
72 
73 
74 #endif	// TERMINAL_LINE_H
75