1//! The module contains a [Records] abstraction of a [`Grid`] trait and its implementators.
2//!
3//! [`Grid`]: crate::Grid
45use crate::{width::WidthFunc, Position};
67pub mod cell_info;
8pub mod empty;
9pub mod vec_records;
1011#[cfg(feature = "color")]
12pub mod tcell;
1314/// The representaion of data, rows and columns of a [`Grid`].
15///
16/// [`Grid`]: crate::Grid
17pub trait Records {
18/// Returns amount of rows on a grid.
19fn count_rows(&self) -> usize;
2021/// Returns amount of columns on a grid.
22fn count_columns(&self) -> usize;
2324/// Returns a text of a cell by an index.
25fn get_text(&self, pos: Position) -> &str;
2627/// Returns a line of a text of a cell by an index.
28fn get_line(&self, pos: Position, i: usize) -> &str;
2930/// Returns an amount of lines of a text of a cell by an index.
31fn count_lines(&self, pos: Position) -> usize;
3233/// Returns a width of a text of a cell by an index.
34fn get_width<W>(&self, pos: Position, width_ctrl: W) -> usize
35where
36W: WidthFunc;
3738/// Returns a width of line of a text of a cell by an index.
39fn get_line_width<W>(&self, pos: Position, i: usize, width_ctrl: W) -> usize
40where
41W: WidthFunc;
4243/// Prints a prefix of a text of a cell by an index.
44 ///
45 /// Maybe be usefull in order to emit ANSI sequences.
46fn fmt_text_prefix(&self, f: &mut std::fmt::Formatter<'_>, pos: Position) -> std::fmt::Result;
4748/// Prints a suffix of a text of a cell by an index.
49 ///
50 /// Maybe be usefull in order to emit ANSI sequences.
51fn fmt_text_suffix(&self, f: &mut std::fmt::Formatter<'_>, pos: Position) -> std::fmt::Result;
52}
5354impl<R> Records for &R
55where
56R: Records,
57{
58fn count_rows(&self) -> usize {
59 R::count_rows(self)
60 }
6162fn count_columns(&self) -> usize {
63 R::count_columns(self)
64 }
6566fn get_text(&self, pos: Position) -> &str {
67 R::get_text(self, pos)
68 }
6970fn get_line(&self, pos: Position, i: usize) -> &str {
71 R::get_line(self, pos, i)
72 }
7374fn count_lines(&self, pos: Position) -> usize {
75 R::count_lines(self, pos)
76 }
7778fn get_width<W>(&self, pos: Position, width_ctrl: W) -> usize
79where
80W: WidthFunc,
81 {
82 R::get_width(self, pos, width_ctrl)
83 }
8485fn get_line_width<W>(&self, pos: Position, i: usize, width_ctrl: W) -> usize
86where
87W: WidthFunc,
88 {
89 R::get_line_width(self, pos, i, width_ctrl)
90 }
9192fn fmt_text_prefix(&self, f: &mut std::fmt::Formatter<'_>, pos: Position) -> std::fmt::Result {
93 R::fmt_text_prefix(self, f, pos)
94 }
9596fn fmt_text_suffix(&self, f: &mut std::fmt::Formatter<'_>, pos: Position) -> std::fmt::Result {
97 R::fmt_text_suffix(self, f, pos)
98 }
99}
100101/// A [`Grid`] representation of a data set which can be modified.
102///
103/// [`Grid`]: crate::Grid
104pub trait RecordsMut<T> {
105/// Sets a text to a given cell by index.
106fn set<W>(&mut self, pos: Position, text: T, width_ctrl: W)
107where
108W: WidthFunc;
109110/// Updates a given cell by index.
111 ///
112 /// Maybe used if width function was changed.
113fn update<W>(&mut self, pos: Position, width_ctrl: W)
114where
115W: WidthFunc;
116}
117118/// A [`Grid`] representation of a data set which can be modified by moving rows/columns around.
119///
120/// [`Grid`]: crate::Grid
121pub trait Resizable {
122/// Swap cells with one another.
123fn swap(&mut self, lhs: Position, rhs: Position);
124/// Swap rows with one another.
125fn swap_row(&mut self, lhs: usize, rhs: usize);
126/// Swap columns with one another.
127fn swap_column(&mut self, lhs: usize, rhs: usize);
128/// Adds a new row to a data set.
129fn push_row(&mut self);
130/// Adds a new column to a data set.
131fn push_column(&mut self);
132/// Removes a row from a data set by index.
133fn remove_row(&mut self, row: usize);
134/// Removes a column from a data set by index.
135fn remove_column(&mut self, column: usize);
136/// Inserts a row to specific by row index.
137fn insert_row(&mut self, row: usize);
138}