Diffstat (limited to 'src/buffer.rs')
1 file changed, 14 insertions(+), 1 deletion(-)
@@ -6,10 +6,23 @@
impl Buffer {
pub fn from_file(file: Option<String>) -> Self {
let lines = match &file {
Some(file) => std::fs::read_to_string(file).unwrap().lines().map(|s| s.to_string()).collect(),
Some(file) => std::fs::read_to_string(file)
.unwrap()
.lines()
.map(|s| s.to_string())
.collect(),
None => vec![],
};
Self { file, lines }
}
pub fn get(&self, line: usize) -> Option<String> {
if self.lines.len() >= line {
return Some(self.lines[line].clone())
}
None
}
}