vvv_core/text/position.rs
1use serde::{Deserialize, Serialize};
2
3/// Zero-based line and character column. Columns count `char`s, not bytes,
4/// so they are safe to show to humans and editors.
5#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
6#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
7pub struct Position {
8 pub line: u32,
9 pub column: u32,
10}
11
12impl Position {
13 pub fn new(line: u32, column: u32) -> Self {
14 Self { line, column }
15 }
16
17 /// One-based rendering for terminals (`12:4`).
18 pub fn display(&self) -> String {
19 format!("{}:{}", self.line + 1, self.column + 1)
20 }
21}