rm-lisa 0.3.2

A logging library for rem-verse, with support for inputs, tasks, and more.
Documentation
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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
//! Render the actual 'terminal', or 'input' part of the console.

use crate::{
	display::{
		SuperConsole,
		renderers::color::helpers::{
			ClearLine, CursorDirection, EMPTY_HEADER, calculate_message_width,
			calculate_tailer_width, erase_line, header_width, move_cursor, pad_to_width,
		},
	},
	input::{InputProvider, TerminalInputEvent},
};
use owo_colors::OwoColorize;
use std::{
	fmt::Write,
	sync::atomic::{AtomicBool, Ordering},
};
use unicode_width::UnicodeWidthChar;
use valuable::Valuable;

/// A type that simulates a line and a column.
type LineColumnType = (usize, usize);

/// The state of the terminal, or input that a user is typing in.
///
/// This is the 'display' state only. We do our best to not keep a secondary
/// copy of the string data, and instead keep offsets of character in order to
/// determine how we need to display a string.
#[derive(Clone, Debug, PartialEq, Eq, Valuable)]
pub struct TerminalState {
	/// The current autocomplete suggestion.
	autocomplete_suggestion: Option<String>,
	/// The character count our cursor is at.
	character_at: usize,
	/// The cursor position at (row, column in char count -- NOT WIDTH).
	cursor_character_position: LineColumnType,
	/// The width of every line in terms of unicode widths.
	line_widths: Vec<InputLine>,
	/// The maximum character position one can be at.
	max_character_at: usize,
	/// The latest set message width.
	message_width: usize,
	/// The latest set tailer width.
	tailer_width: usize,
	/// The 'PS1' in terms of a posix compatible shell.
	///
	/// Basically the bit of text that appears before the users input, for example
	/// this might just be: '$ ', or it could be something more fancy like:
	/// `<username>@<hostname>$ `. It is dynamic, and changable.
	ps1: String,
}

impl TerminalState {
	/// Create a new terminal state.
	#[must_use]
	pub fn new(ps1: String) -> Self {
		// Terminal widths are always guaranteed to be 40 wide, so start there, and grow.
		let msg_width = calculate_message_width(40);
		let tailer_width = calculate_tailer_width(40);

		Self {
			autocomplete_suggestion: None,
			character_at: 0,
			cursor_character_position: (0, 0),
			line_widths: vec![InputLine {
				char_count: 0,
				total_width: 0,
			}],
			max_character_at: 0,
			message_width: msg_width,
			tailer_width,
			ps1,
		}
	}

	/// Clear the current render so we can render log lines above our console.
	#[must_use]
	pub fn clear_current_render(&self) -> String {
		if self.cursor_character_position.0 == 0 && self.cursor_character_position.1 == 0 {
			return String::with_capacity(0);
		}

		// First move our cursor down if necessary.
		let mut clear_string = if self.cursor_character_position.0 + 1 < self.line_widths.len() {
			move_cursor(
				CursorDirection::Down,
				self.line_widths.len() - (self.cursor_character_position.0 + 1),
			)
		} else {
			String::new()
		};
		// We're now at the last line. Let's make sure we're as far left as possible.
		clear_string += &move_cursor(
			CursorDirection::Left,
			self.cursor_character_position.1 + header_width(),
		);
		// Now we can clear lines and move up.
		for _ in 0..self.line_widths.len() {
			clear_string += &erase_line(ClearLine::EntireLine);
			clear_string += &move_cursor(CursorDirection::Up, 1);
		}
		// Erase '-------' line.
		clear_string += &erase_line(ClearLine::EntireLine);

		clear_string
	}

	/// After we've [`Self::clear_current_render`], we will render some log
	/// lines, and then need to render our standalone again. This is also where
	/// PS1 updates happen.
	#[must_use]
	pub fn render_current_standalone(
		&mut self,
		new_ps1: Option<&str>,
		message_width: usize,
		tailer_width: usize,
		input: &str,
	) -> String {
		if (new_ps1.is_some() && Some(self.ps1.as_str()) != new_ps1)
			|| self.message_width != message_width
			|| self.tailer_width != tailer_width
			|| self.cursor_character_position == (0, 0)
		{
			self.message_width = message_width;
			self.tailer_width = tailer_width;
			if let Some(new_ps) = new_ps1 {
				new_ps.clone_into(&mut self.ps1);
			}

			let (linecol, lines) = Self::calculate_lines(
				self.message_width,
				&self.ps1,
				input,
				self.autocomplete_suggestion.as_deref(),
				self.character_at,
			);
			self.cursor_character_position = linecol;
			self.line_widths = lines;

			Self::do_full_render(
				self.message_width,
				self.tailer_width,
				&self.ps1,
				input,
				self.cursor_character_position,
				&self.line_widths,
				self.autocomplete_suggestion.as_deref(),
			)
		} else {
			Self::do_full_render(
				self.message_width,
				self.tailer_width,
				&self.ps1,
				input,
				self.cursor_character_position,
				&self.line_widths,
				self.autocomplete_suggestion.as_deref(),
			)
		}
	}

	/// Update the terminal state given a new input event, returning the string
	/// that should be rendered
	#[must_use]
	pub fn on_input_event(
		&mut self,
		input_provider: &dyn InputProvider,
		input_event: TerminalInputEvent,
		force_pause: &AtomicBool,
	) -> String {
		match input_event {
			TerminalInputEvent::InputStarted => String::with_capacity(0),
			TerminalInputEvent::ClearScreen => self.do_clear_screen(),
			TerminalInputEvent::InputCancelled | TerminalInputEvent::InputFinished => {
				self.on_input_reset()
			}
			TerminalInputEvent::InputChanged(cursor_char_position) => {
				self.reflow_entire_input(cursor_char_position, input_provider)
			}
			TerminalInputEvent::InputAppend(new_character) => {
				self.reflow_new_char(new_character, input_provider)
			}
			TerminalInputEvent::InputMassAppend(new_data) => {
				self.reflow_string(&new_data, input_provider)
			}
			TerminalInputEvent::CursorMoveLeft(mut char_amount) => {
				let mut move_left_amount = 0_usize;
				let mut move_up_amount = 0_usize;

				while char_amount > 0 {
					char_amount -= 1;

					if self.character_at == 0 {
						break;
					}
					self.character_at -= 1;
					if self.cursor_character_position.1 == 0 {
						self.cursor_character_position.0 -= 1;
						self.cursor_character_position.1 =
							self.line_widths[self.cursor_character_position.0].char_count;
						move_up_amount += 1;
					} else {
						self.cursor_character_position.1 -= 1;
						move_left_amount += 1;
					}
				}

				if move_up_amount > 0 {
					let mut data =
						move_cursor(CursorDirection::Left, self.message_width + header_width());
					data += &move_cursor(CursorDirection::Up, move_up_amount);
					data += &move_cursor(
						CursorDirection::Right,
						header_width() + self.cursor_character_position.1,
					);
					data
				} else {
					move_cursor(CursorDirection::Left, move_left_amount)
				}
			}
			TerminalInputEvent::CursorMoveRight(mut char_amount) => {
				let mut move_down_amount = 0_usize;
				let mut move_right_amount = 0_usize;

				while char_amount > 0 {
					char_amount -= 1;

					if self.character_at > self.max_character_at {
						break;
					}
					self.character_at += 1;
					let line = &self.line_widths[self.cursor_character_position.0];
					if self.cursor_character_position.1 + 1 > line.char_count {
						move_down_amount += 1;
						move_right_amount = 0;
						self.cursor_character_position.0 += 1;
						self.cursor_character_position.1 = 1;
					} else {
						self.cursor_character_position.1 += 1;
						move_right_amount += 1;
					}
				}

				if move_down_amount > 0 {
					let mut data =
						move_cursor(CursorDirection::Left, self.message_width + header_width());
					data += &move_cursor(CursorDirection::Down, move_down_amount);
					data += &move_cursor(
						CursorDirection::Right,
						header_width() + self.cursor_character_position.1,
					);
					data
				} else {
					move_cursor(CursorDirection::Right, move_right_amount)
				}
			}
			TerminalInputEvent::ToggleOutputPause => {
				force_pause.fetch_not(Ordering::AcqRel);
				String::with_capacity(0)
			}
		}
	}

	fn calculate_lines(
		msg_width: usize,
		ps1: &str,
		input: &str,
		autocomplete: Option<&str>,
		input_char: usize,
	) -> (LineColumnType, Vec<InputLine>) {
		let mut line_col = (0_usize, 0_usize);
		let mut input_lines = vec![InputLine {
			char_count: 0,
			total_width: 0,
		}];

		for character in ps1.chars() {
			let my_input_line = input_lines
				.last_mut()
				.unwrap_or_else(|| unreachable!("input lines always > 0"));
			let character_width = character.width().unwrap_or_default();

			if character == '\n' {
				line_col.0 += 1;
				line_col.1 = 1;
				input_lines.push(InputLine {
					char_count: 1,
					total_width: 1,
				});
			} else if my_input_line.total_width + character_width > msg_width {
				line_col.0 += 1;
				line_col.1 = 1;
				input_lines.push(InputLine {
					char_count: 1,
					total_width: character_width,
				});
			} else {
				line_col.1 += 1;
				my_input_line.char_count += 1;
				my_input_line.total_width += character_width;
			}
		}

		for (idx, character) in input.chars().enumerate() {
			let my_input_line = input_lines
				.last_mut()
				.unwrap_or_else(|| unreachable!("input lines always > 0"));
			let character_width = character.width().unwrap_or_default();

			if character == '\n' {
				input_lines.push(InputLine {
					char_count: 1,
					total_width: 1,
				});
				if idx < input_char {
					line_col.0 += 1;
					line_col.1 = 1;
				}
			} else if my_input_line.total_width + character_width > msg_width {
				input_lines.push(InputLine {
					char_count: 1,
					total_width: character_width,
				});
				if idx < input_char {
					line_col.0 += 1;
					line_col.1 = 1;
				}
			} else {
				my_input_line.char_count += 1;
				my_input_line.total_width += character_width;
				if idx < input_char {
					line_col.1 += 1;
				}
			}
		}

		for character in autocomplete.unwrap_or_default().chars() {
			let my_input_line = input_lines
				.last_mut()
				.unwrap_or_else(|| unreachable!("input lines always > 0"));
			let character_width = character.width().unwrap_or_default();

			if character == '\n' {
				input_lines.push(InputLine {
					char_count: 1,
					total_width: 1,
				});
			} else if my_input_line.total_width + character_width > msg_width {
				input_lines.push(InputLine {
					char_count: 1,
					total_width: character_width,
				});
			} else {
				my_input_line.char_count += 1;
				my_input_line.total_width += character_width;
			}
		}

		(line_col, input_lines)
	}

	/// Clear the entire screen.
	fn do_clear_screen(&self) -> String {
		// First let's go all the way to the left, and all the way down.
		//
		// This ensures we can just loop and clear up.
		let mut buff = move_cursor(
			CursorDirection::Left,
			header_width() + self.message_width + self.tailer_width,
		);
		let observed_terminal_height =
			SuperConsole::<std::io::Stdout, std::io::Stderr>::terminal_height().unwrap_or(144);
		buff += &move_cursor(CursorDirection::Down, usize::from(observed_terminal_height));

		for _ in 0..=observed_terminal_height {
			buff += &erase_line(ClearLine::EntireLine);
			buff += &move_cursor(CursorDirection::Up, 1);
		}

		buff
	}

	/// Perform a full render of the console.
	fn do_full_render(
		message_width: usize,
		tailer_width: usize,
		ps1: &str,
		input: &str,
		cursor_at: LineColumnType,
		lines: &[InputLine],
		autocomplete_suggestion: Option<&str>,
	) -> String {
		let mut final_render = String::new();
		let mut autocomplete_iterator = autocomplete_suggestion.unwrap_or_default().chars();
		let mut full_input_iterator = ps1.chars().chain(input.chars()).peekable();

		final_render.push_str(EMPTY_HEADER);
		let mut msg = String::new();
		while msg.len() < message_width {
			msg.push('-');
		}
		final_render.push_str(&msg);
		final_render.push_str(&pad_to_width("|".to_owned(), tailer_width));
		let mut italic_buff: Option<String> = None;
		for line in lines {
			final_render.push('\n');
			final_render.push_str(EMPTY_HEADER);

			let mut inner_line = String::new();
			for _ in 0..line.char_count {
				if let Some(regular_char) = full_input_iterator.next() {
					if regular_char == '\u{1b}' && full_input_iterator.peek().is_none() {
						// Ignore!
					} else {
						inner_line.push(if regular_char == '\n' {
							' '
						} else {
							regular_char
						});
					}
				} else if let Some(other_char) = autocomplete_iterator.next() {
					if let Some(italic_buff_add) = italic_buff.as_mut() {
						italic_buff_add.push(if other_char == '\n' { ' ' } else { other_char });
					} else {
						italic_buff = Some(String::from(if other_char == '\n' {
							' '
						} else {
							other_char
						}));
					}
				}
			}
			if let Some(buff) = italic_buff.take() {
				_ = write!(&mut inner_line, "{}", buff.italic().bright_black());
			}
			final_render.push_str(&pad_to_width(inner_line, message_width));
			final_render.push_str(&pad_to_width("|".to_owned(), tailer_width));
		}
		final_render.push_str(&move_cursor(
			CursorDirection::Left,
			tailer_width + (message_width - cursor_at.1) - 1,
		));
		final_render.push_str(&move_cursor(
			CursorDirection::Up,
			(lines.len() - 1) - cursor_at.0,
		));

		final_render
	}

	/// Called on input cancel/finish events.
	///
	/// Fully resets the input to a starting state.
	fn on_input_reset(&mut self) -> String {
		let mut data = self.clear_current_render();
		self.character_at = 0_usize;
		self.max_character_at = 0_usize;
		self.cursor_character_position = (0_usize, 0_usize);
		self.autocomplete_suggestion = None;
		self.line_widths = vec![InputLine {
			char_count: 0,
			total_width: 0,
		}];
		data += &self.render_current_standalone(None, self.message_width, self.tailer_width, "");
		data
	}

	/// Reflow and re-render the entire input block on a full change.
	fn reflow_entire_input(
		&mut self,
		cursor_char_position: usize,
		input_provider: &dyn InputProvider,
	) -> String {
		let mut final_input = self.clear_current_render();

		let input = input_provider.current_input();
		// We don't render auto-completes for commands are too short in order to
		// prevent flashing of various completions when you first start typing.
		if input.len() >= 3 && !input_provider.autocomplete_suggestion_pending() {
			self.autocomplete_suggestion = input_provider.current_autocomplete_suggestion();
		}
		if input.len() < 3 || input_provider.autocomplete_suggestion_pending() {
			self.autocomplete_suggestion = None;
		}
		let (linecol, lines) = Self::calculate_lines(
			self.message_width,
			&self.ps1,
			&input,
			self.autocomplete_suggestion.as_deref(),
			cursor_char_position,
		);
		self.character_at = cursor_char_position;
		self.cursor_character_position = linecol;
		self.line_widths = lines;
		self.max_character_at = input.len();

		final_input +=
			&self.render_current_standalone(None, self.message_width, self.tailer_width, &input);
		final_input
	}

	/// Perform a partial character reflow where we just add a new
	/// character.
	fn reflow_new_char(
		&mut self,
		new_character: char,
		input_provider: &dyn InputProvider,
	) -> String {
		self.character_at += 1;
		self.max_character_at += 1;

		let last_line = &mut self.line_widths[self.cursor_character_position.0];
		let new_char_width = new_character.width().unwrap_or_default();

		if input_provider.autocomplete_suggestion_pending() {
			self.autocomplete_suggestion = None;
			return self.reflow_entire_input(self.character_at, input_provider);
		}
		if input_provider.is_doing_history_search() {
			return self.reflow_entire_input(self.character_at, input_provider);
		}

		if self.autocomplete_suggestion.is_some() {
			let sugg = self.autocomplete_suggestion.as_deref().unwrap_or_default();
			if sugg.starts_with(new_character) && sugg.len() != 1 {
				self.autocomplete_suggestion = self
					.autocomplete_suggestion
					.take()
					.map(|str| str.chars().skip(1).collect::<String>());
			} else {
				self.autocomplete_suggestion = None;
			}
			return self.reflow_entire_input(self.character_at, input_provider);
		} else if self.character_at + 1 >= 3
			&& let Some(sugg) = input_provider.current_autocomplete_suggestion()
		{
			self.autocomplete_suggestion = Some(sugg);
			return self.reflow_entire_input(self.character_at + 1, input_provider);
		}

		if new_character == '\n' {
			return self.reflow_entire_input(self.character_at + 1, input_provider);
		}

		if last_line.total_width + new_char_width > self.message_width {
			self.cursor_character_position.0 += 1;
			self.cursor_character_position.1 = 1;
			self.line_widths.push(InputLine {
				char_count: 1,
				total_width: new_char_width,
			});

			let mut data = move_cursor(
				CursorDirection::Right,
				self.message_width + self.tailer_width,
			);
			data.push('\n');
			data.push_str(EMPTY_HEADER);
			data.push_str(&pad_to_width(
				if new_character == '\u{1b}' {
					String::new()
				} else {
					String::from(new_character)
				},
				self.message_width,
			));
			data.push_str(&pad_to_width("|".to_owned(), self.tailer_width));
			data.push_str(&move_cursor(
				CursorDirection::Left,
				self.tailer_width + (self.message_width - self.cursor_character_position.1) - 1,
			));

			data
		} else {
			self.cursor_character_position.1 += 1;
			let mut data = erase_line(ClearLine::CursorToEnd);
			data += &pad_to_width(
				if new_character == '\u{1b}' {
					String::new()
				} else {
					String::from(new_character)
				},
				self.message_width - last_line.total_width,
			);
			last_line.char_count += 1;
			last_line.total_width += new_char_width;
			data += &pad_to_width("|".to_owned(), self.tailer_width);
			data += &move_cursor(
				CursorDirection::Left,
				self.tailer_width + (self.message_width - self.cursor_character_position.1) - 1,
			);

			data
		}
	}

	/// Reflow many new bytes at once.
	fn reflow_string(&mut self, new_data: &str, input_provider: &dyn InputProvider) -> String {
		let mut result = String::new();

		if input_provider.autocomplete_suggestion_pending() {
			self.autocomplete_suggestion = None;
			return self.reflow_entire_input(self.character_at, input_provider);
		}
		if input_provider.is_doing_history_search() {
			return self.reflow_entire_input(self.character_at, input_provider);
		}

		if self.autocomplete_suggestion.is_some() {
			let sugg = self.autocomplete_suggestion.as_deref().unwrap_or_default();
			if sugg.starts_with(new_data) && sugg.len() < new_data.len() {
				self.autocomplete_suggestion = self.autocomplete_suggestion.take().map(|str| {
					str.chars()
						.skip(new_data.chars().count())
						.collect::<String>()
				});
			} else {
				self.autocomplete_suggestion = None;
			}
			return self.reflow_entire_input(self.character_at, input_provider);
		} else if self.character_at + new_data.chars().count() >= 3
			&& let Some(sugg) = input_provider.current_autocomplete_suggestion()
		{
			self.autocomplete_suggestion = Some(sugg);
			return self
				.reflow_entire_input(self.character_at + new_data.chars().count(), input_provider);
		}

		if new_data.contains('\n') {
			return self
				.reflow_entire_input(self.character_at + new_data.chars().count(), input_provider);
		}

		let mut has_erased = false;
		for new_character in new_data.chars() {
			self.character_at += 1;
			self.max_character_at += 1;

			let last_line = &mut self.line_widths[self.cursor_character_position.0];
			let new_char_width = new_character.width().unwrap_or_default();
			if last_line.total_width + new_char_width > self.message_width {
				if has_erased {
					let mut current_width = last_line.total_width;
					while current_width < self.message_width {
						result.push(' ');
						current_width += 1;
					}
					result.push_str(&pad_to_width("|".to_owned(), self.tailer_width));
				} else {
					// we don't need to erase, so pretend we have erased so no one else does.
					has_erased = true;
					result.push_str(&move_cursor(
						CursorDirection::Right,
						self.message_width + self.tailer_width,
					));
				}
				result.push('\n');
				result.push_str(EMPTY_HEADER);
				result.push(new_character);

				self.cursor_character_position.0 += 1;
				self.cursor_character_position.1 = 1;
				self.line_widths.push(InputLine {
					char_count: 1,
					total_width: new_char_width,
				});
			} else {
				if !has_erased {
					result += &erase_line(ClearLine::CursorToEnd);
					has_erased = true;
				}
				last_line.char_count += 1;
				last_line.total_width += new_char_width;
				result.push(new_character);

				self.cursor_character_position.1 += 1;
			}
		}

		// We need to re-render a tailer.
		if has_erased {
			let last_line = self
				.line_widths
				.last_mut()
				.unwrap_or_else(|| unreachable!());

			let mut current_width = last_line.total_width;
			while current_width < self.message_width {
				result.push(' ');
				current_width += 1;
			}
			result.push_str(&pad_to_width("|".to_owned(), self.tailer_width));
			result.push_str(&move_cursor(
				CursorDirection::Left,
				self.tailer_width + (self.message_width - self.cursor_character_position.1) - 1,
			));
		}

		result
	}
}

/// An line of input and it's current char count, and width.
///
/// Used to calculate when we should wrap around, and how we should move our
/// cursor. We need to use widths to know _when_ to wrap, and char count to
/// actually mess with bash cursor control.
#[derive(Clone, Debug, PartialEq, Eq, Valuable)]
struct InputLine {
	/// The amount of characters that have been pasted into a line.
	char_count: usize,
	/// The amount of unicode width those characters take up.
	total_width: usize,
}