1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
#[cfg(test)]
mod line_attribute_tests {
use crate::ansi_processor::{AnsiProcessor, LineAttribute, TerminalState};
/// F0314: Test line attribute initialization (all normal)
#[test]
fn test_line_attribute_initialization() {
let terminal_state = TerminalState::new(80, 24);
// Check that all lines start with Normal attribute
for line in 0..24 {
assert_eq!(
terminal_state.get_line_attribute(line),
LineAttribute::Normal
);
}
}
/// F0314: Test setting double-width line with DECDWL (ESC # 6)
#[test]
fn test_decdwl_double_width_line() {
let mut processor = AnsiProcessor::new();
// Move cursor to line 5
processor.terminal_state.get_cursor_mut().y = 5;
// Set double-width line using ESC # 6
processor.process_bytes(b"\x1b#6");
// Line 5 should now be double-width
assert_eq!(
processor.terminal_state.get_line_attribute(5),
LineAttribute::DoubleWidth
);
// Other lines should remain normal
assert_eq!(
processor.terminal_state.get_line_attribute(4),
LineAttribute::Normal
);
assert_eq!(
processor.terminal_state.get_line_attribute(6),
LineAttribute::Normal
);
}
/// F0314: Test setting double-height line top half with DECDHL (ESC # 3)
#[test]
fn test_decdhl_double_height_line_top() {
let mut processor = AnsiProcessor::new();
// Move cursor to line 8
processor.terminal_state.get_cursor_mut().y = 8;
// Set double-height line top half using ESC # 3
processor.process_bytes(b"\x1b#3");
// Line 8 should now be double-height top
assert_eq!(
processor.terminal_state.get_line_attribute(8),
LineAttribute::DoubleHeightTop
);
// Other lines should remain normal
assert_eq!(
processor.terminal_state.get_line_attribute(7),
LineAttribute::Normal
);
assert_eq!(
processor.terminal_state.get_line_attribute(9),
LineAttribute::Normal
);
}
/// F0314: Test setting double-height line bottom half with DECDHL (ESC # 4)
#[test]
fn test_decdhl_double_height_line_bottom() {
let mut processor = AnsiProcessor::new();
// Move cursor to line 12
processor.terminal_state.get_cursor_mut().y = 12;
// Set double-height line bottom half using ESC # 4
processor.process_bytes(b"\x1b#4");
// Line 12 should now be double-height bottom
assert_eq!(
processor.terminal_state.get_line_attribute(12),
LineAttribute::DoubleHeightBottom
);
// Other lines should remain normal
assert_eq!(
processor.terminal_state.get_line_attribute(11),
LineAttribute::Normal
);
assert_eq!(
processor.terminal_state.get_line_attribute(13),
LineAttribute::Normal
);
}
/// F0314: Test resetting line to normal with DECSWL (ESC # 5)
#[test]
fn test_decswl_reset_to_normal() {
let mut processor = AnsiProcessor::new();
// Move cursor to line 10
processor.terminal_state.get_cursor_mut().y = 10;
// Set double-width first
processor.process_bytes(b"\x1b#6");
assert_eq!(
processor.terminal_state.get_line_attribute(10),
LineAttribute::DoubleWidth
);
// Reset to normal using ESC # 5
processor.process_bytes(b"\x1b#5");
// Line 10 should now be normal
assert_eq!(
processor.terminal_state.get_line_attribute(10),
LineAttribute::Normal
);
}
/// F0314: Test line attribute sequence on double-height line pair
#[test]
fn test_double_height_line_pair() {
let mut processor = AnsiProcessor::new();
// Set up a double-height line pair on lines 15 and 16
processor.terminal_state.get_cursor_mut().y = 15;
processor.process_bytes(b"\x1b#3"); // Top half
processor.terminal_state.get_cursor_mut().y = 16;
processor.process_bytes(b"\x1b#4"); // Bottom half
// Check both lines have correct attributes
assert_eq!(
processor.terminal_state.get_line_attribute(15),
LineAttribute::DoubleHeightTop
);
assert_eq!(
processor.terminal_state.get_line_attribute(16),
LineAttribute::DoubleHeightBottom
);
// Surrounding lines should be normal
assert_eq!(
processor.terminal_state.get_line_attribute(14),
LineAttribute::Normal
);
assert_eq!(
processor.terminal_state.get_line_attribute(17),
LineAttribute::Normal
);
}
/// F0314: Test line attributes in alternate screen buffer
#[test]
fn test_line_attributes_alternate_screen() {
let mut processor = AnsiProcessor::new();
// Switch to alternate screen
processor.terminal_state.use_alternate_screen = true;
// Move cursor and set double-width in alternate screen
processor.terminal_state.get_cursor_mut().y = 7;
processor.process_bytes(b"\x1b#6");
// Alternate screen should have the attribute
assert_eq!(
processor.terminal_state.alternate_buffer.line_attributes[7],
LineAttribute::DoubleWidth
);
// Primary screen should still be normal
assert_eq!(
processor.terminal_state.primary_buffer.line_attributes[7],
LineAttribute::Normal
);
}
/// F0314: Test line attributes persistence during scrolling
#[test]
fn test_line_attributes_with_scrolling() {
let mut processor = AnsiProcessor::new();
// Set double-width on line 0
processor.terminal_state.get_cursor_mut().y = 0;
processor.process_bytes(b"\x1b#6");
assert_eq!(
processor.terminal_state.get_line_attribute(0),
LineAttribute::DoubleWidth
);
// Scroll up - this should move line 0 to scrollback
processor.terminal_state.primary_buffer.scroll_up_one_line();
// Line 0 should now be normal (new empty line)
assert_eq!(
processor.terminal_state.get_line_attribute(0),
LineAttribute::Normal
);
// The scrollback should have the double-width attribute
assert_eq!(
processor
.terminal_state
.primary_buffer
.scrollback_line_attributes
.last(),
Some(&LineAttribute::DoubleWidth)
);
}
/// F0314: Test line attribute resize behavior
#[test]
fn test_line_attributes_after_resize() {
let mut processor = AnsiProcessor::new();
// Set some line attributes
processor.terminal_state.get_cursor_mut().y = 5;
processor.process_bytes(b"\x1b#6"); // Double width
processor.terminal_state.get_cursor_mut().y = 10;
processor.process_bytes(b"\x1b#3"); // Double height top
// Resize to larger height
processor.terminal_state.resize(80, 30);
// Existing attributes should be preserved
assert_eq!(
processor.terminal_state.get_line_attribute(5),
LineAttribute::DoubleWidth
);
assert_eq!(
processor.terminal_state.get_line_attribute(10),
LineAttribute::DoubleHeightTop
);
// New lines should be normal
assert_eq!(
processor.terminal_state.get_line_attribute(25),
LineAttribute::Normal
);
assert_eq!(
processor.terminal_state.get_line_attribute(29),
LineAttribute::Normal
);
// Resize to smaller height
processor.terminal_state.resize(80, 15);
// Only preserved attributes should remain
assert_eq!(
processor.terminal_state.get_line_attribute(5),
LineAttribute::DoubleWidth
);
assert_eq!(
processor.terminal_state.get_line_attribute(10),
LineAttribute::DoubleHeightTop
);
// Should have exactly 15 line attributes
assert_eq!(
processor
.terminal_state
.primary_buffer
.line_attributes
.len(),
15
);
}
/// F0314: Test multiple line attribute changes on same line
#[test]
fn test_multiple_attribute_changes() {
let mut processor = AnsiProcessor::new();
// Move cursor to line 3
processor.terminal_state.get_cursor_mut().y = 3;
// Start with double-width
processor.process_bytes(b"\x1b#6");
assert_eq!(
processor.terminal_state.get_line_attribute(3),
LineAttribute::DoubleWidth
);
// Change to double-height top
processor.process_bytes(b"\x1b#3");
assert_eq!(
processor.terminal_state.get_line_attribute(3),
LineAttribute::DoubleHeightTop
);
// Change to double-height bottom
processor.process_bytes(b"\x1b#4");
assert_eq!(
processor.terminal_state.get_line_attribute(3),
LineAttribute::DoubleHeightBottom
);
// Reset to normal
processor.process_bytes(b"\x1b#5");
assert_eq!(
processor.terminal_state.get_line_attribute(3),
LineAttribute::Normal
);
}
/// F0314: Test line attribute edge cases
#[test]
fn test_line_attribute_edge_cases() {
let mut processor = AnsiProcessor::new();
// Test at first line (y=0)
processor.terminal_state.get_cursor_mut().y = 0;
processor.process_bytes(b"\x1b#6");
assert_eq!(
processor.terminal_state.get_line_attribute(0),
LineAttribute::DoubleWidth
);
// Test at last line (y=23)
processor.terminal_state.get_cursor_mut().y = 23;
processor.process_bytes(b"\x1b#3");
assert_eq!(
processor.terminal_state.get_line_attribute(23),
LineAttribute::DoubleHeightTop
);
// Test invalid line requests return Normal
assert_eq!(
processor.terminal_state.get_line_attribute(100),
LineAttribute::Normal
);
}
/// F0314: Test line attributes with terminal modes
#[test]
fn test_line_attributes_with_terminal_modes() {
let mut processor = AnsiProcessor::new();
// Set line attribute in origin mode
processor.terminal_state.mode.origin_mode = true;
processor.terminal_state.get_cursor_mut().y = 5;
processor.process_bytes(b"\x1b#6");
// Should work regardless of terminal mode
assert_eq!(
processor.terminal_state.get_line_attribute(5),
LineAttribute::DoubleWidth
);
// Reset origin mode
processor.terminal_state.mode.origin_mode = false;
// Line attribute should still be there
assert_eq!(
processor.terminal_state.get_line_attribute(5),
LineAttribute::DoubleWidth
);
}
/// F0314: Test comprehensive line attribute integration
#[test]
fn test_comprehensive_line_attribute_integration() {
let mut processor = AnsiProcessor::new();
// Create a pattern of different line attributes
let test_patterns = [
(2, b"\x1b#6", LineAttribute::DoubleWidth),
(4, b"\x1b#3", LineAttribute::DoubleHeightTop),
(5, b"\x1b#4", LineAttribute::DoubleHeightBottom),
(7, b"\x1b#6", LineAttribute::DoubleWidth),
(10, b"\x1b#3", LineAttribute::DoubleHeightTop),
(11, b"\x1b#4", LineAttribute::DoubleHeightBottom),
];
// Set all patterns
for &(line, sequence, expected) in &test_patterns {
processor.terminal_state.get_cursor_mut().y = line;
processor.process_bytes(sequence);
assert_eq!(processor.terminal_state.get_line_attribute(line), expected);
}
// Verify all other lines are normal
for line in 0..24 {
if !test_patterns
.iter()
.any(|(test_line, _, _)| *test_line == line)
{
assert_eq!(
processor.terminal_state.get_line_attribute(line),
LineAttribute::Normal
);
}
}
// Test reset of one line
processor.terminal_state.get_cursor_mut().y = 7;
processor.process_bytes(b"\x1b#5"); // Reset to normal
assert_eq!(
processor.terminal_state.get_line_attribute(7),
LineAttribute::Normal
);
// Other attributes should remain unchanged
assert_eq!(
processor.terminal_state.get_line_attribute(2),
LineAttribute::DoubleWidth
);
assert_eq!(
processor.terminal_state.get_line_attribute(4),
LineAttribute::DoubleHeightTop
);
assert_eq!(
processor.terminal_state.get_line_attribute(5),
LineAttribute::DoubleHeightBottom
);
}
}