improve ui for opening files, read stdin if no files (unless on macos :/)

This commit is contained in:
alice pellerin
2026-04-10 21:51:19 -05:00
parent 1a62deb710
commit a59f48736f
2 changed files with 65 additions and 14 deletions
+8 -4
View File
@@ -1,5 +1,5 @@
use core::slice::GetDisjointMutIndex;
use std::{collections::HashSet, fs::File, io::Read, path::PathBuf};
use std::{collections::HashSet, fs::File, io::{self, Read}, path::PathBuf};
use crossterm::event::KeyEvent;
use ratatui::{layout::{Constraint, Rect}, style::{Color, Style, Stylize}, text::Span, widgets::{Block, Borders, Clear, Widget}};
use serde::{Deserialize, Serialize};
@@ -171,11 +171,15 @@ impl Widget for Popup {
}
impl Buffer {
pub fn new(file_path: PathBuf) -> Self {
let file = File::open(&file_path);
pub fn from_file_at(file_path: PathBuf) -> io::Result<Self> {
let mut file = File::open(&file_path)?;
let mut contents = Vec::new();
file.unwrap().read_to_end(&mut contents).unwrap();
file.read_to_end(&mut contents)?;
Ok(Self::new(file_path, contents))
}
pub fn new(file_path: PathBuf, contents: Vec<u8>) -> Self {
Self {
file_name: file_path.file_name().unwrap().to_str().unwrap().to_owned(),
file_path,