Compare commits
41 Commits
030b8a5cc8
...
gui
| Author | SHA1 | Date | |
|---|---|---|---|
| e3bf484a5d | |||
| bedd510b0a | |||
| a30ea2b457 | |||
| 52ceda5b06 | |||
| a37fd74d32 | |||
| 6ed4ca11f4 | |||
| 41fab2847d | |||
| c76529b3cb | |||
| 5f5b1a4d39 | |||
| 4bb4ce1882 | |||
| 344efc0042 | |||
| a63acb18fc | |||
| f918d65888 | |||
| aa42ec6072 | |||
| 6f2a655497 | |||
| c0f38b531d | |||
| 4aad91416e | |||
| ff1b5ab2e6 | |||
| 491087a6c1 | |||
| c170b3b20d | |||
| 125041f469 | |||
| 67bf82d0cb | |||
| 39377b32f0 | |||
| 176efb97b7 | |||
| 755066d847 | |||
| 773d7818b5 | |||
| 7e58e3ee03 | |||
| 0f50577d78 | |||
| 29024e3999 | |||
| 5af09485a3 | |||
| e5b91eaed8 | |||
| be383869b2 | |||
| b9eee50e52 | |||
| 4cc43916cb | |||
| a5bed9ed2c | |||
| 0fac2b71ab | |||
| db2f878018 | |||
| 048d40eb83 | |||
| c70bba16e4 | |||
| 325cf285fc | |||
| aa8590cd5c |
@@ -1,28 +0,0 @@
|
||||
name: Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- 'v*'
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
Build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Install Rust
|
||||
run: |
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
||||
|
||||
- name: Install Python
|
||||
run: |
|
||||
apt update - y
|
||||
apt install python3 -y
|
||||
|
||||
- name: Install Qt
|
||||
uses: jurplel/install-qt-action@v4
|
||||
with:
|
||||
version: '6.7.3'
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,5 +1,4 @@
|
||||
**/target/**
|
||||
**/.qtcreator/**
|
||||
**/.idea/**
|
||||
**/*.autosave/**
|
||||
**/.qmlls.ini
|
||||
**/*.autosave/**
|
||||
482
Cargo.lock
generated
482
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -17,8 +17,8 @@ tui-tree-widget = "0.24.0"
|
||||
tui-logger = "0.18.1"
|
||||
edtui = "0.11.1"
|
||||
strum = "0.27.2"
|
||||
uuid = { version = "1.19.0", features = ["v4"] }
|
||||
devicons = "0.6.12"
|
||||
libclide = { path = "./libclide" }
|
||||
|
||||
[build-dependencies]
|
||||
# The link_qt_object_files feature is required for statically linking Qt 6.
|
||||
|
||||
16
libclide/Cargo.lock
generated
16
libclide/Cargo.lock
generated
@@ -1,16 +0,0 @@
|
||||
# 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",
|
||||
]
|
||||
@@ -1,7 +0,0 @@
|
||||
[package]
|
||||
name = "libclide"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.102"
|
||||
@@ -1,5 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
|
||||
//
|
||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||
|
||||
pub mod entry_meta;
|
||||
@@ -1,50 +0,0 @@
|
||||
// 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,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
|
||||
//
|
||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||
|
||||
pub mod fs;
|
||||
@@ -1,7 +1,3 @@
|
||||
// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
|
||||
//
|
||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15
|
||||
import QtQuick.Layouts 1.15
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
|
||||
//
|
||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Controls.Basic
|
||||
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
|
||||
//
|
||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Controls.Basic
|
||||
|
||||
|
||||
@@ -4,21 +4,21 @@
|
||||
|
||||
use crate::tui::component::{Action, Component, ComponentState, Focus, FocusState};
|
||||
use anyhow::{Context, Result, bail};
|
||||
use log::{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};
|
||||
use libclide::fs::entry_meta::EntryMeta;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Explorer<'a> {
|
||||
root_path: EntryMeta,
|
||||
pub(crate) root_path: PathBuf,
|
||||
tree_items: TreeItem<'a, String>,
|
||||
tree_state: TreeState<String>,
|
||||
pub(crate) component_state: ComponentState,
|
||||
@@ -30,7 +30,7 @@ impl<'a> Explorer<'a> {
|
||||
pub fn new(path: &PathBuf) -> Result<Self> {
|
||||
trace!(target:Self::ID, "Building {}", Self::ID);
|
||||
let explorer = Explorer {
|
||||
root_path: EntryMeta::new(&path)?,
|
||||
root_path: path.to_owned(),
|
||||
tree_items: Self::build_tree_from_path(path.to_owned())?,
|
||||
tree_state: TreeState::default(),
|
||||
component_state: ComponentState::default().with_help_text(concat!(
|
||||
@@ -41,46 +41,46 @@ impl<'a> Explorer<'a> {
|
||||
Ok(explorer)
|
||||
}
|
||||
|
||||
/// Builds the file tree from a path using recursion.
|
||||
/// The identifiers used for the TreeItems are normalized. Symlinks are not resolved.
|
||||
/// Resolving symlinks would cause collisions on the TreeItem unique identifiers within the set.
|
||||
fn build_tree_from_path<P: AsRef<Path>>(p: P) -> Result<TreeItem<'static, String>> {
|
||||
let path = p.as_ref();
|
||||
fn build_tree_from_path(path: PathBuf) -> Result<TreeItem<'static, String>> {
|
||||
let mut children = vec![];
|
||||
let path_meta = EntryMeta::new(path)?;
|
||||
if let Ok(entries) = fs::read_dir(&path_meta.abs_path) {
|
||||
let clean_path = fs::canonicalize(path)?;
|
||||
if let Ok(entries) = fs::read_dir(&clean_path) {
|
||||
let mut paths = entries
|
||||
.map(|res| res.map(|e| e.path()))
|
||||
.collect::<Result<Vec<_>, std::io::Error>>()
|
||||
.context(format!(
|
||||
"Failed to build vector of paths under directory: {:?}",
|
||||
&path_meta.abs_path
|
||||
clean_path
|
||||
))?;
|
||||
paths.sort();
|
||||
for entry_path in paths {
|
||||
let entry_meta = EntryMeta::new(&entry_path)?;
|
||||
if entry_meta.is_dir {
|
||||
children.push(Self::build_tree_from_path(&entry_meta.abs_path)?);
|
||||
for path in paths {
|
||||
if path.is_dir() {
|
||||
children.push(Self::build_tree_from_path(path)?);
|
||||
} else {
|
||||
children.push(TreeItem::new_leaf(
|
||||
entry_meta.abs_path.clone(),
|
||||
entry_meta.file_name.clone(),
|
||||
));
|
||||
if let Ok(path) = fs::canonicalize(&path) {
|
||||
let path_str = path.to_string_lossy().to_string();
|
||||
children.push(TreeItem::new_leaf(
|
||||
path_str + uuid::Uuid::new_v4().to_string().as_str(),
|
||||
path.file_name()
|
||||
.context("Failed to get file name from path.")?
|
||||
.to_string_lossy()
|
||||
.to_string(),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Note: The first argument is a unique identifier, where no 2 TreeItems may share the same.
|
||||
// For a file tree this is fine because we shouldn't list the same object twice.
|
||||
TreeItem::new(
|
||||
path_meta.abs_path.clone(),
|
||||
path_meta.file_name.clone(),
|
||||
clean_path.to_string_lossy().to_string() + uuid::Uuid::new_v4().to_string().as_str(),
|
||||
clean_path
|
||||
.file_name()
|
||||
.context(format!("Failed to get file name from path: {clean_path:?}"))?
|
||||
.to_string_lossy()
|
||||
.to_string(),
|
||||
children,
|
||||
)
|
||||
.context(format!(
|
||||
"Failed to build tree from path: {:?}",
|
||||
path_meta.abs_path
|
||||
))
|
||||
.context(format!("Failed to build tree from path: {clean_path:?}"))
|
||||
}
|
||||
|
||||
pub fn selected(&self) -> Result<String> {
|
||||
@@ -97,11 +97,15 @@ impl<'a> Explorer<'a> {
|
||||
impl<'a> Widget for &mut Explorer<'a> {
|
||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||
if let Ok(tree) = Tree::new(&self.tree_items.children()) {
|
||||
let file_name = self
|
||||
.root_path
|
||||
.file_name()
|
||||
.unwrap_or_else(|| OsStr::new("Unknown"));
|
||||
StatefulWidget::render(
|
||||
tree.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.title(self.root_path.file_name.clone())
|
||||
.title(file_name.to_string_lossy())
|
||||
.border_style(Style::default().fg(self.component_state.get_active_color()))
|
||||
.title_style(Style::default().fg(Color::Green))
|
||||
.title_alignment(Alignment::Center),
|
||||
|
||||
Reference in New Issue
Block a user