-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add document mod and welcome message
- Loading branch information
shepherdma
committed
Nov 29, 2023
1 parent
e4e374c
commit 493bf9c
Showing
5 changed files
with
109 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use crate::Row; | ||
|
||
#[derive(Default)] | ||
pub struct Document { | ||
rows: Vec<Row>, | ||
} | ||
|
||
impl Document { | ||
pub fn open() -> Self{ | ||
let mut rows = Vec::new(); | ||
rows.push(Row::from("Hello, World!")); | ||
Self { rows } | ||
} | ||
pub fn row(&self, index: usize) -> Option<&Row> { | ||
self.rows.get(index) | ||
} | ||
pub fn is_empty(&self) -> bool { | ||
self.rows.is_empty() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use std::cmp; | ||
pub struct Row { | ||
string: String, | ||
} | ||
|
||
impl From<&str> for Row { | ||
fn from(slice: &str) -> Self { | ||
Self { | ||
string: String::from(slice), | ||
} | ||
} | ||
} | ||
|
||
impl Row { | ||
pub fn render(&self, start: usize, end: usize) -> String { | ||
let end = cmp::min(end, self.string.len()); | ||
let start = cmp::min(start, end); | ||
self.string.get(start..end).unwrap_or_default().to_string() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters