From 5d541cb5c87ffb80262c753394f06f4449609b9b Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 31 Mar 2021 16:53:27 +0530 Subject: integrate pico args to main --- src/utils.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/utils.rs') diff --git a/src/utils.rs b/src/utils.rs index dcf652d..9859f39 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -4,15 +4,20 @@ use crate::{ lisp::{ error::{EvalError, LispError, ParseError}, eval::Evaluator, - expr::LispExpr, lex::Lexer, parse::Parser, }, message::Message, }; -use std::{fs::OpenOptions, io::Read, path::Path}; +use std::{ + fs::OpenOptions, + io::{self, Cursor, Read}, + path::Path, +}; +use log::info; +use obi::Image; use sdl2::{ keyboard::{Keycode, Mod}, pixels::Color, @@ -91,3 +96,15 @@ pub fn load_script>(path: P, app: &mut AppState) -> Result<(), Li } return Ok(()); } + +pub fn load_file>(path: P) -> Result { + info!("loading existing file `{:?}`", path.as_ref()); + let mut image = OpenOptions::new() + .read(true) + .write(false) + .create(false) + .open(&path)?; + let mut buf = Vec::new(); + image.read_to_end(&mut buf)?; + Ok(Image::decode(&mut (Cursor::new(buf))).unwrap()) // TODO: obi erro +} -- cgit v1.2.3