3 buffer::{Buffer, Cell},
5use helix_core::unicode::width::UnicodeWidthStr;
6use helix_view::graphics::{CursorKind, Rect};
7use std::{fmt::Write, io};
9/// A backend used for the integration tests.
11pub struct TestBackend {
19/// Returns a string representation of the given buffer for debugging purpose.
20fn buffer_view(buffer: &Buffer) -> String {
21 let mut view = String::with_capacity(buffer.content.len() + buffer.area.height as usize * 3);
22 for cells in buffer.content.chunks(buffer.area.width as usize) {
23 let mut overwritten = vec![];
24 let mut skip: usize = 0;
26 for (x, c) in cells.iter().enumerate() {
28 view.push_str(&c.symbol);
30 overwritten.push((x, &c.symbol))
32 skip = std::cmp::max(skip, c.symbol.width()).saturating_sub(1);
35 if !overwritten.is_empty() {
38 " Hidden by multi-width symbols: {:?}",
49 pub fn new(width: u16, height: u16) -> TestBackend {
53 buffer: Buffer::empty(Rect::new(0, 0, width, height)),
59 pub fn buffer(&self) -> &Buffer {
63 pub fn resize(&mut self, width: u16, height: u16) {
64 self.buffer.resize(Rect::new(0, 0, width, height));
69 pub fn assert_buffer(&self, expected: &Buffer) {
70 assert_eq!(expected.area, self.buffer.area);
71 let diff = expected.diff(&self.buffer);
76 let mut debug_info = String::from("Buffers are not equal");
77 debug_info.push('\n');
78 debug_info.push_str("Expected:");
79 debug_info.push('\n');
80 let expected_view = buffer_view(expected);
81 debug_info.push_str(&expected_view);
82 debug_info.push('\n');
83 debug_info.push_str("Got:");
84 debug_info.push('\n');
85 let view = buffer_view(&self.buffer);
86 debug_info.push_str(&view);
87 debug_info.push('\n');
89 debug_info.push_str("Diff:");
90 debug_info.push('\n');
94 .map(|(i, (x, y, cell))| {
95 let expected_cell = expected.get(*x, *y);
97 "{}: at ({}, {}) expected {:?} got {:?}",
98 i, x, y, expected_cell, cell
101 .collect::<Vec<String>>()
103 debug_info.push_str(&nice_diff);
104 panic!("{}", debug_info);
108impl Backend for TestBackend {
109 fn draw<'a, I>(&mut self, content: I) -> Result<(), io::Error>
111 I: Iterator<Item = (u16, u16, &'a Cell)>,
113 for (x, y, c) in content {
114 let cell = self.buffer.get_mut(x, y);
120 fn hide_cursor(&mut self) -> Result<(), io::Error> {
125 fn show_cursor(&mut self, _kind: CursorKind) -> Result<(), io::Error> {
130 fn get_cursor(&mut self) -> Result<(u16, u16), io::Error> {
134 fn set_cursor(&mut self, x: u16, y: u16) -> Result<(), io::Error> {
139 fn clear(&mut self) -> Result<(), io::Error> {
144 fn size(&self) -> Result<Rect, io::Error> {
145 Ok(Rect::new(0, 0, self.width, self.height))
148 fn flush(&mut self) -> Result<(), io::Error> {
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list