aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/buffer.rs
blob: 9dd227737d362ba5fb65e30f60d89e21074bf05f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use anyhow::Error;
use ropey::Rope;
use std::{env, fs::File, io::BufReader, path::PathBuf};

pub struct Buffer {
    pub contents: Rope,
}

impl Buffer {
    pub fn load(path: PathBuf) -> Result<Self, Error> {
        let current_dir = env::current_dir()?;

        let contents = Rope::from_reader(BufReader::new(File::open(path)?))?;

        // TODO: create if not found
        Ok(Buffer { contents })
    }
}