Add libclide. #23
480
Cargo.lock
generated
480
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
16
libclide/Cargo.lock
generated
Normal file
16
libclide/Cargo.lock
generated
Normal file
@@ -0,0 +1,16 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.102"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c"
|
||||
|
||||
[[package]]
|
||||
name = "libclide"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
]
|
||||
@@ -4,3 +4,4 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.102"
|
||||
|
||||
5
libclide/src/fs.rs
Normal file
5
libclide/src/fs.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
|
||||
//
|
||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||
|
||||
pub mod entry_meta;
|
||||
50
libclide/src/fs/entry_meta.rs
Normal file
50
libclide/src/fs/entry_meta.rs
Normal file
@@ -0,0 +1,50 @@
|
||||
// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
|
||||
//
|
||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
use anyhow::{Context, Result};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct EntryMeta {
|
||||
pub abs_path: String,
|
||||
pub file_name: String,
|
||||
pub is_dir: bool,
|
||||
}
|
||||
|
||||
impl EntryMeta {
|
||||
/// Normalizes a path, returning an absolute from the root of the filesystem.
|
||||
/// Does not resolve symlinks and extracts `./` or `../` segments.
|
||||
fn normalize<P: AsRef<Path>>(p: P) -> PathBuf {
|
||||
let path = p.as_ref();
|
||||
let mut buf = PathBuf::new();
|
||||
|
||||
for comp in path.components() {
|
||||
match comp {
|
||||
std::path::Component::ParentDir => {
|
||||
buf.pop();
|
||||
}
|
||||
std::path::Component::CurDir => {}
|
||||
_ => buf.push(comp),
|
||||
}
|
||||
}
|
||||
|
||||
buf
|
||||
}
|
||||
|
||||
pub fn new<P: AsRef<Path>>(p: P) -> Result<Self> {
|
||||
let path = p.as_ref();
|
||||
let is_dir = path.is_dir();
|
||||
let abs_path = Self::normalize(&path).to_string_lossy().to_string();
|
||||
let file_name = Path::new(&abs_path)
|
||||
.file_name()
|
||||
.context(format!("Failed to get file name for path: {abs_path:?}"))?
|
||||
.to_string_lossy()
|
||||
.to_string();
|
||||
Ok(EntryMeta {
|
||||
abs_path,
|
||||
file_name,
|
||||
is_dir,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -4,61 +4,17 @@
|
||||
|
||||
use crate::tui::component::{Action, Component, ComponentState, Focus, FocusState};
|
||||
use anyhow::{Context, Result, bail};
|
||||
use log::{info, trace};
|
||||
use log::{trace};
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, MouseEvent, MouseEventKind};
|
||||
use ratatui::layout::{Alignment, Position, Rect};
|
||||
use ratatui::prelude::Style;
|
||||
use ratatui::style::{Color, Modifier};
|
||||
use ratatui::widgets::{Block, Borders, StatefulWidget, Widget};
|
||||
use std::ffi::OsStr;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use tui_tree_widget::{Tree, TreeItem, TreeState};
|
||||
|
||||
#[derive(Debug)]
|
||||
struct EntryMeta {
|
||||
abs_path: String,
|
||||
file_name: String,
|
||||
is_dir: bool,
|
||||
}
|
||||
|
||||
impl EntryMeta {
|
||||
/// Normalizes a path, returning an absolute from the root of the filesystem.
|
||||
/// Does not resolve symlinks and extracts `./` or `../` segments.
|
||||
fn normalize<P: AsRef<Path>>(p: P) -> PathBuf {
|
||||
let path = p.as_ref();
|
||||
let mut buf = PathBuf::new();
|
||||
|
||||
for comp in path.components() {
|
||||
match comp {
|
||||
std::path::Component::ParentDir => {
|
||||
buf.pop();
|
||||
}
|
||||
std::path::Component::CurDir => {}
|
||||
_ => buf.push(comp),
|
||||
}
|
||||
}
|
||||
|
||||
buf
|
||||
}
|
||||
|
||||
fn new<P: AsRef<Path>>(p: P) -> Result<Self> {
|
||||
let path = p.as_ref();
|
||||
let is_dir = path.is_dir();
|
||||
let abs_path = Self::normalize(&path).to_string_lossy().to_string();
|
||||
let file_name = Path::new(&abs_path)
|
||||
.file_name()
|
||||
.context(format!("Failed to get file name for path: {abs_path:?}"))?
|
||||
.to_string_lossy()
|
||||
.to_string();
|
||||
Ok(EntryMeta {
|
||||
abs_path,
|
||||
file_name,
|
||||
is_dir,
|
||||
})
|
||||
}
|
||||
}
|
||||
use libclide::fs::entry_meta::EntryMeta;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Explorer<'a> {
|
||||
|
||||
Reference in New Issue
Block a user