parent
624a56cc97
commit
dea9d2fa54
1 changed files with 18 additions and 19 deletions
@ -1,35 +1,34 @@ |
|||||||
use std::{fs::{self, File}, path::Path, io::Read}; |
use std::{fs::File, path::Path, io::Read}; |
||||||
|
|
||||||
|
#[allow(dead_code)] |
||||||
type Character = [[bool; 8]; 14]; |
type Character = [[bool; 8]; 14]; |
||||||
|
|
||||||
fn read_file(mut file_name: String) -> Vec<u8> { |
/// Reads the file and turns it into a Vec of u8s
|
||||||
file_name = file_name.replace("/", ""); |
fn read_file(file_name: String) -> Vec<u8> { |
||||||
if file_name.is_empty() { |
|
||||||
file_name = String::from("index.html"); |
|
||||||
} |
|
||||||
|
|
||||||
let path = Path::new(&file_name); |
let path = Path::new(&file_name); |
||||||
|
|
||||||
if !path.exists() { |
if !path.exists() { |
||||||
return String::from("Not Found!").into(); |
return String::from("Not Found!").into(); |
||||||
} |
} |
||||||
|
|
||||||
let mut file_content = Vec::new(); |
let mut file_content = Vec::new(); |
||||||
let mut file = File::open(&file_name).expect("Unable to open file"); |
let mut file = File::open(&file_name).expect("Unable to open file"); |
||||||
file.read_to_end(&mut file_content).expect("Unable to read"); |
file.read_to_end(&mut file_content).expect("Unable to read"); |
||||||
|
|
||||||
file_content |
file_content |
||||||
} |
} |
||||||
|
|
||||||
pub fn get_font() { |
pub fn get_font() { |
||||||
// Retrieve font data from file
|
// Retrieve font data from file
|
||||||
let file_path = "./fonts/Terminus14x8.data"; |
let file_path = String::from("./fonts/Terminus14x8.data"); |
||||||
println!("In file {}", file_path); |
println!("In file {file_path}"); |
||||||
let contents = fs::read_to_string(file_path) |
|
||||||
.expect("File could not be read"); |
let contents = read_file(file_path); |
||||||
let width_left_byte = &contents[0..0]; |
|
||||||
let width_right_byte = &contents[1..1]; |
let width_left_byte = contents[0]; |
||||||
let number_left = width_left_byte.chars().nth(0).unwrap(); |
let width_right_byte = contents[1]; |
||||||
let number_right = width_right_byte.chars().nth(0).unwrap(); |
let number = [width_left_byte, width_right_byte]; |
||||||
let number = [number_left as u8, number_right as u8]; |
let width = i16::from_be_bytes(number); |
||||||
let width = i16::from_ne_bytes(number); |
|
||||||
|
println!("Left Byte: {width_left_byte}, Right Byte: {width_right_byte}, Byte Pair {width}") |
||||||
println!("{width}") |
|
||||||
} |
} |
||||||
|
|||||||
Loading…
Reference in new issue