Compare commits
55 Commits
gui
...
3450d6db9b
| Author | SHA1 | Date | |
|---|---|---|---|
| 3450d6db9b | |||
| 8ce92b435b | |||
| bc29502ad4 | |||
| 4622102d81 | |||
| dc680554dd | |||
| 177a4bc432 | |||
| 5f4391cb82 | |||
| 2273c0156e | |||
| 417f01b527 | |||
| d776602fe8 | |||
| e2ddadd952 | |||
| 61c7f59237 | |||
| 1e63eabd46 | |||
| ac83b3e30f | |||
| a42ad73a57 | |||
| 1ec13aa43a | |||
| 0a3f095080 | |||
| 6474c5b6bd | |||
| 717ea70895 | |||
| 8eada4bbee | |||
| 0ebd45ae15 | |||
| 14e7514cc1 | |||
| b3bb13fa33 | |||
| ad95056376 | |||
| 384fa51b6e | |||
| fc2a44740f | |||
| f609aa02db | |||
| fdb4f0db0b | |||
| 2d5e721a79 | |||
| 2e55ba1a4b | |||
| 6b9e3b1b40 | |||
| bdb126cab5 | |||
| a4f6f199ec | |||
| 911a29937e | |||
| 579826d398 | |||
| 3b1f33f055 | |||
| 607dae32fe | |||
| bb032e9daf | |||
| 886a32a9e2 | |||
| 0c58b6c436 | |||
| df3547267b | |||
| a605c4929e | |||
| a40125416d | |||
| 6777a44b3b | |||
| 288298ac18 | |||
| d461a29ff9 | |||
| bc906cd7f3 | |||
| 8ddff3fe9e | |||
| 289f94300c | |||
| d95aa680ff | |||
| 1119b3db9b | |||
| 7ad25af13d | |||
| 7d4f23d82a | |||
| b4e14f7f27 | |||
| f6fdd19f73 |
@@ -1,6 +1,2 @@
|
|||||||
[build]
|
[build]
|
||||||
rustflags = [ "-C", "link-arg=-fuse-ld=lld", ]
|
rustflags = [ "-C", "link-arg=-fuse-ld=lld", ]
|
||||||
|
|
||||||
[env]
|
|
||||||
QMAKE="/opt/Qt/6.7.3/gcc_64/bin/qmake6"
|
|
||||||
LD_LIBRARY_PATH="/opt/Qt/6.7.3/gcc_64/lib"
|
|
||||||
|
|||||||
20
.github/actions/setup-qt/action.yml
vendored
Normal file
20
.github/actions/setup-qt/action.yml
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
name: "Setup Qt"
|
||||||
|
description: "Install clide dependencies"
|
||||||
|
inputs:
|
||||||
|
qt-version:
|
||||||
|
description: "Qt version to install"
|
||||||
|
required: true
|
||||||
|
|
||||||
|
runs:
|
||||||
|
using: "composite"
|
||||||
|
steps:
|
||||||
|
- name: Install apt packages
|
||||||
|
run: |
|
||||||
|
sudo apt update -y
|
||||||
|
sudo apt install -y build-essential cmake curl libgl1-mesa-dev python3 python3-pip
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Install Qt
|
||||||
|
uses: jurplel/install-qt-action@v4
|
||||||
|
with:
|
||||||
|
version: ${{ inputs.qt-version }}
|
||||||
85
.github/workflows/check.yaml
vendored
Normal file
85
.github/workflows/check.yaml
vendored
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
name: Check
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- '**'
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
env:
|
||||||
|
QT_VERSION: 6.7.3
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
Build:
|
||||||
|
name: Build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
|
- name: Setup Qt
|
||||||
|
uses: ./.github/actions/setup-qt
|
||||||
|
with:
|
||||||
|
qt-version: ${{ env.QT_VERSION }}
|
||||||
|
|
||||||
|
- name: Build libclide
|
||||||
|
run: |
|
||||||
|
cargo b -p libclide --release
|
||||||
|
- name: Build clide
|
||||||
|
run: |
|
||||||
|
cargo b --release
|
||||||
|
|
||||||
|
Test:
|
||||||
|
name: Test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
|
- name: Setup Qt
|
||||||
|
uses: ./.github/actions/setup-qt
|
||||||
|
with:
|
||||||
|
qt-version: ${{ env.QT_VERSION }}
|
||||||
|
|
||||||
|
- name: Test libclide
|
||||||
|
run: |
|
||||||
|
cargo test -p libclide
|
||||||
|
- name: Test clide
|
||||||
|
run: |
|
||||||
|
cargo test
|
||||||
|
|
||||||
|
Lint:
|
||||||
|
name: Lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
|
- name: Setup Qt
|
||||||
|
uses: ./.github/actions/setup-qt
|
||||||
|
with:
|
||||||
|
qt-version: ${{ env.QT_VERSION }}
|
||||||
|
|
||||||
|
- name: Lint libclide
|
||||||
|
run: |
|
||||||
|
cargo clippy -p libclide -- -D warnings
|
||||||
|
- name: Lint clide
|
||||||
|
run: |
|
||||||
|
cargo clippy -- -D warnings
|
||||||
|
|
||||||
|
Format:
|
||||||
|
name: Format
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
|
- name: Setup Qt
|
||||||
|
uses: ./.github/actions/setup-qt
|
||||||
|
with:
|
||||||
|
qt-version: ${{ env.QT_VERSION }}
|
||||||
|
|
||||||
|
- name: Format libclide
|
||||||
|
run: |
|
||||||
|
cargo fmt -p libclide --verbose -- --check
|
||||||
|
- name: Format clide
|
||||||
|
run: |
|
||||||
|
cargo fmt --verbose -- --check
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
|||||||
**/.qtcreator/**
|
**/.qtcreator/**
|
||||||
**/.idea/**
|
**/.idea/**
|
||||||
**/*.autosave/**
|
**/*.autosave/**
|
||||||
|
**/.qmlls.ini
|
||||||
|
|||||||
487
Cargo.lock
generated
487
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
17
Cargo.toml
17
Cargo.toml
@@ -3,6 +3,17 @@ name = "clide"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
resolver = "3"
|
||||||
|
members = [
|
||||||
|
".",
|
||||||
|
"libclide",
|
||||||
|
]
|
||||||
|
|
||||||
|
[workspace.dependencies]
|
||||||
|
anyhow = "1.0.100"
|
||||||
|
strum = "0.27.2"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cxx = "1.0.95"
|
cxx = "1.0.95"
|
||||||
cxx-qt = "0.8.0"
|
cxx-qt = "0.8.0"
|
||||||
@@ -12,13 +23,13 @@ dirs = "6.0.0"
|
|||||||
syntect = "5.2.0"
|
syntect = "5.2.0"
|
||||||
clap = { version = "4.5.54", features = ["derive"] }
|
clap = { version = "4.5.54", features = ["derive"] }
|
||||||
ratatui = "0.30.0"
|
ratatui = "0.30.0"
|
||||||
anyhow = "1.0.100"
|
|
||||||
tui-tree-widget = "0.24.0"
|
tui-tree-widget = "0.24.0"
|
||||||
tui-logger = "0.18.1"
|
tui-logger = "0.18.1"
|
||||||
edtui = "0.11.1"
|
edtui = "0.11.1"
|
||||||
strum = "0.27.2"
|
|
||||||
uuid = { version = "1.19.0", features = ["v4"] }
|
|
||||||
devicons = "0.6.12"
|
devicons = "0.6.12"
|
||||||
|
libclide = { path = "./libclide" }
|
||||||
|
anyhow = { workspace = true }
|
||||||
|
strum = { workspace = true }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
# The link_qt_object_files feature is required for statically linking Qt 6.
|
# The link_qt_object_files feature is required for statically linking Qt 6.
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
# CLIDE
|
# CLIDE
|
||||||
|
|
||||||
|
[](https://github.com/shaunrd0/clide/actions/workflows/check.yaml)
|
||||||
|
|
||||||
CLIDE is an extendable command-line driven development environment written in Rust using the Qt UI framework that supports both full and headless Linux environments.
|
CLIDE is an extendable command-line driven development environment written in Rust using the Qt UI framework that supports both full and headless Linux environments.
|
||||||
The GUI is written in QML compiled through Rust using the cxx-qt crate, while the TUI was implemented using the ratatui crate.
|
The GUI is written in QML compiled through Rust using the cxx-qt crate, while the TUI was implemented using the ratatui crate.
|
||||||
|
|
||||||
|
|||||||
2
build.rs
2
build.rs
@@ -1,7 +1,7 @@
|
|||||||
use cxx_qt_build::{CxxQtBuilder, QmlModule};
|
use cxx_qt_build::{CxxQtBuilder, QmlModule};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
CxxQtBuilder::new_qml_module(QmlModule::new("clide.module").qml_files(&[
|
CxxQtBuilder::new_qml_module(QmlModule::new("clide.module").qml_files([
|
||||||
"qml/ClideApplicationView.qml",
|
"qml/ClideApplicationView.qml",
|
||||||
"qml/ClideEditorView.qml",
|
"qml/ClideEditorView.qml",
|
||||||
"qml/ClideExplorerView.qml",
|
"qml/ClideExplorerView.qml",
|
||||||
|
|||||||
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",
|
||||||
|
]
|
||||||
8
libclide/Cargo.toml
Normal file
8
libclide/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "libclide"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
anyhow = { workspace = true }
|
||||||
|
strum = { workspace = true }
|
||||||
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 anyhow::{Context, Result};
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
#[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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
6
libclide/src/lib.rs
Normal file
6
libclide/src/lib.rs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||||
|
|
||||||
|
pub mod fs;
|
||||||
|
pub mod theme;
|
||||||
5
libclide/src/theme.rs
Normal file
5
libclide/src/theme.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 colors;
|
||||||
52
libclide/src/theme/colors.rs
Normal file
52
libclide/src/theme/colors.rs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||||
|
|
||||||
|
pub struct Colors {}
|
||||||
|
|
||||||
|
impl Colors {
|
||||||
|
pub const HOVERED: &str = "#303234";
|
||||||
|
pub const UNHOVERED: &str = "#3c3f41";
|
||||||
|
pub const PRESSED: &str = "#4b4f51";
|
||||||
|
pub const MENUBAR: &str = "#262626";
|
||||||
|
pub const MENUBAR_BORDER: &str = "#575757";
|
||||||
|
pub const SCROLLBAR: &str = "#4b4f51";
|
||||||
|
pub const SCROLLBAR_ACTIVE: &str = "#4b4f51";
|
||||||
|
pub const SCROLLBAR_GUTTER: &str = "#3b3b3b";
|
||||||
|
pub const LINENUMBER: &str = "#94989b";
|
||||||
|
pub const ACTIVE: &str = "#a9acb0";
|
||||||
|
pub const INACTIVE: &str = "#FFF";
|
||||||
|
pub const EDITOR_BACKGROUND: &str = "#1E1F22";
|
||||||
|
pub const EDITOR_TEXT: &str = "#acaea3";
|
||||||
|
pub const EDITOR_HIGHLIGHTED_TEXT: &str = "#ccced3";
|
||||||
|
pub const EDITOR_HIGHLIGHT: &str = "#ccced3";
|
||||||
|
pub const GUTTER: &str = "#1e1f22";
|
||||||
|
pub const EXPLORER_HOVERED: &str = "#4c5053";
|
||||||
|
pub const EXPLORER_TEXT: &str = "#FFF";
|
||||||
|
pub const EXPLORER_TEXT_SELECTED: &str = "#262626";
|
||||||
|
pub const EXPLORER_BACKGROUND: &str = "#1E1F22";
|
||||||
|
pub const EXPLORER_FOLDER: &str = "#54585b";
|
||||||
|
pub const EXPLORER_FOLDER_OPEN: &str = "#393B40";
|
||||||
|
pub const TERMINAL_BACKGROUND: &str = "#111111";
|
||||||
|
pub const INFO_LOG: &str = "#C4FFFF";
|
||||||
|
pub const DEBUG_LOG: &str = "#9148AF";
|
||||||
|
pub const WARN_LOG: &str = "#C4A958";
|
||||||
|
pub const ERROR_LOG: &str = "#ff5555";
|
||||||
|
pub const TRACE_LOG: &str = "#ffaa00";
|
||||||
|
|
||||||
|
pub fn css_to_u32(css: &str) -> Result<u32, String> {
|
||||||
|
let hex = css.trim_start_matches('#');
|
||||||
|
// Expand shorthand #RGB to #RRGGBB
|
||||||
|
let hex_full = match hex.len() {
|
||||||
|
3 => hex.chars()
|
||||||
|
.map(|c| std::iter::repeat(c).take(2).collect::<String>())
|
||||||
|
.collect::<String>(),
|
||||||
|
6 => hex.to_string(),
|
||||||
|
_ => return Err(format!("Invalid hex color length: {}", hex)),
|
||||||
|
};
|
||||||
|
// Parse the hex string as u32, masking to ensure the top byte is 0x00.
|
||||||
|
u32::from_str_radix(&hex_full, 16)
|
||||||
|
.map(|rgb| rgb & 0x00FF_FFFF)
|
||||||
|
.map_err(|e| format!("Failed to parse hex: {}", e))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
|
// 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 2.15
|
||||||
import QtQuick.Controls 2.15
|
import QtQuick.Controls 2.15
|
||||||
import QtQuick.Layouts 1.15
|
import QtQuick.Layouts 1.15
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||||
|
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Controls.Basic
|
import QtQuick.Controls.Basic
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||||
|
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Controls.Basic
|
import QtQuick.Controls.Basic
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,10 @@
|
|||||||
//
|
//
|
||||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||||
|
|
||||||
#[cxx_qt::bridge]
|
use cxx_qt_lib::QColor;
|
||||||
|
use libclide::theme::colors::Colors;
|
||||||
|
|
||||||
|
#[cxx_qt::bridge]
|
||||||
pub mod qobject {
|
pub mod qobject {
|
||||||
unsafe extern "C++" {
|
unsafe extern "C++" {
|
||||||
include!("cxx-qt-lib/qcolor.h");
|
include!("cxx-qt-lib/qcolor.h");
|
||||||
@@ -46,8 +48,6 @@ pub mod qobject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use cxx_qt_lib::QColor;
|
|
||||||
|
|
||||||
pub struct RustColorsImpl {
|
pub struct RustColorsImpl {
|
||||||
hovered: QColor,
|
hovered: QColor,
|
||||||
unhovered: QColor,
|
unhovered: QColor,
|
||||||
@@ -82,34 +82,34 @@ pub struct RustColorsImpl {
|
|||||||
impl Default for RustColorsImpl {
|
impl Default for RustColorsImpl {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
hovered: QColor::try_from("#303234").unwrap(),
|
hovered: QColor::try_from(Colors::HOVERED).unwrap(),
|
||||||
unhovered: QColor::try_from("#3c3f41").unwrap(),
|
unhovered: QColor::try_from(Colors::UNHOVERED).unwrap(),
|
||||||
pressed: QColor::try_from("#4b4f51").unwrap(),
|
pressed: QColor::try_from(Colors::PRESSED).unwrap(),
|
||||||
menubar: QColor::try_from("#262626").unwrap(),
|
menubar: QColor::try_from(Colors::MENUBAR).unwrap(),
|
||||||
menubar_border: QColor::try_from("#575757").unwrap(),
|
menubar_border: QColor::try_from(Colors::MENUBAR_BORDER).unwrap(),
|
||||||
scrollbar: QColor::try_from("#4b4f51").unwrap(),
|
scrollbar: QColor::try_from(Colors::SCROLLBAR).unwrap(),
|
||||||
scrollbar_active: QColor::try_from("#4b4f51").unwrap(),
|
scrollbar_active: QColor::try_from(Colors::SCROLLBAR_ACTIVE).unwrap(),
|
||||||
scrollbar_gutter: QColor::try_from("#3b3b3b").unwrap(),
|
scrollbar_gutter: QColor::try_from(Colors::SCROLLBAR_GUTTER).unwrap(),
|
||||||
linenumber: QColor::try_from("#94989b").unwrap(),
|
linenumber: QColor::try_from(Colors::LINENUMBER).unwrap(),
|
||||||
active: QColor::try_from("#a9acb0").unwrap(),
|
active: QColor::try_from(Colors::ACTIVE).unwrap(),
|
||||||
inactive: QColor::try_from("#FFF").unwrap(),
|
inactive: QColor::try_from(Colors::INACTIVE).unwrap(),
|
||||||
editor_background: QColor::try_from("#1E1F22").unwrap(),
|
editor_background: QColor::try_from(Colors::EDITOR_BACKGROUND).unwrap(),
|
||||||
editor_text: QColor::try_from("#acaea3").unwrap(),
|
editor_text: QColor::try_from(Colors::EDITOR_TEXT).unwrap(),
|
||||||
editor_highlighted_text: QColor::try_from("#ccced3").unwrap(),
|
editor_highlighted_text: QColor::try_from(Colors::EDITOR_HIGHLIGHTED_TEXT).unwrap(),
|
||||||
editor_highlight: QColor::try_from("#ccced3").unwrap(),
|
editor_highlight: QColor::try_from(Colors::EDITOR_HIGHLIGHT).unwrap(),
|
||||||
gutter: QColor::try_from("#1e1f22").unwrap(),
|
gutter: QColor::try_from(Colors::GUTTER).unwrap(),
|
||||||
explorer_hovered: QColor::try_from("#4c5053").unwrap(),
|
explorer_hovered: QColor::try_from(Colors::EXPLORER_HOVERED).unwrap(),
|
||||||
explorer_text: QColor::try_from("#FFF").unwrap(),
|
explorer_text: QColor::try_from(Colors::EXPLORER_TEXT).unwrap(),
|
||||||
explorer_text_selected: QColor::try_from("#262626").unwrap(),
|
explorer_text_selected: QColor::try_from(Colors::EXPLORER_TEXT_SELECTED).unwrap(),
|
||||||
explorer_background: QColor::try_from("#1E1F22").unwrap(),
|
explorer_background: QColor::try_from(Colors::EXPLORER_BACKGROUND).unwrap(),
|
||||||
explorer_folder: QColor::try_from("#54585b").unwrap(),
|
explorer_folder: QColor::try_from(Colors::EXPLORER_FOLDER).unwrap(),
|
||||||
explorer_folder_open: QColor::try_from("#393B40").unwrap(),
|
explorer_folder_open: QColor::try_from(Colors::EXPLORER_FOLDER_OPEN).unwrap(),
|
||||||
terminal_background: QColor::try_from("#111111").unwrap(),
|
terminal_background: QColor::try_from(Colors::TERMINAL_BACKGROUND).unwrap(),
|
||||||
info_log: QColor::try_from("#C4FFFF").unwrap(),
|
info_log: QColor::try_from(Colors::INFO_LOG).unwrap(),
|
||||||
debug_log: QColor::try_from("#9148AF").unwrap(),
|
debug_log: QColor::try_from(Colors::DEBUG_LOG).unwrap(),
|
||||||
warn_log: QColor::try_from("#C4A958").unwrap(),
|
warn_log: QColor::try_from(Colors::WARN_LOG).unwrap(),
|
||||||
error_log: QColor::try_from("#ff5555").unwrap(),
|
error_log: QColor::try_from(Colors::ERROR_LOG).unwrap(),
|
||||||
trace_log: QColor::try_from("#ffaa00").unwrap(),
|
trace_log: QColor::try_from(Colors::TRACE_LOG).unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ impl qobject::FileSystem {
|
|||||||
return QString::default();
|
return QString::default();
|
||||||
}
|
}
|
||||||
let meta = fs::metadata(path.to_string())
|
let meta = fs::metadata(path.to_string())
|
||||||
.expect(format!("Failed to get file metadata {path:?}").as_str());
|
.unwrap_or_else(|_| panic!("Failed to get file metadata {path:?}"));
|
||||||
if !meta.is_file() {
|
if !meta.is_file() {
|
||||||
warn!(target:"FileSystem", "Attempted to open file {path:?} that is not a valid file");
|
warn!(target:"FileSystem", "Attempted to open file {path:?} that is not a valid file");
|
||||||
return QString::default();
|
return QString::default();
|
||||||
@@ -114,7 +114,7 @@ impl qobject::FileSystem {
|
|||||||
output.push_str("</pre>\n");
|
output.push_str("</pre>\n");
|
||||||
QString::from(output)
|
QString::from(output)
|
||||||
} else {
|
} else {
|
||||||
return QString::default();
|
QString::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,7 +126,7 @@ impl qobject::FileSystem {
|
|||||||
fn set_directory(self: std::pin::Pin<&mut Self>, path: &QString) -> QModelIndex {
|
fn set_directory(self: std::pin::Pin<&mut Self>, path: &QString) -> QModelIndex {
|
||||||
if !path.is_empty()
|
if !path.is_empty()
|
||||||
&& fs::metadata(path.to_string())
|
&& fs::metadata(path.to_string())
|
||||||
.expect(format!("Failed to get metadata for path {path:?}").as_str())
|
.unwrap_or_else(|_| panic!("Failed to get metadata for path {path:?}"))
|
||||||
.is_dir()
|
.is_dir()
|
||||||
{
|
{
|
||||||
self.set_root_path(path)
|
self.set_root_path(path)
|
||||||
@@ -147,7 +147,7 @@ impl qobject::FileSystem {
|
|||||||
if Path::new(&str).is_dir() {
|
if Path::new(&str).is_dir() {
|
||||||
// Ensures directories are given a folder icon and not mistakenly resolved to a language.
|
// Ensures directories are given a folder icon and not mistakenly resolved to a language.
|
||||||
// For example, a directory named `cpp` would otherwise return a C++ icon.
|
// For example, a directory named `cpp` would otherwise return a C++ icon.
|
||||||
return QString::from(FileIcon::from("dir/").to_string())
|
return QString::from(FileIcon::from("dir/").to_string());
|
||||||
}
|
}
|
||||||
let icon = FileIcon::from(str);
|
let icon = FileIcon::from(str);
|
||||||
QString::from(icon.to_string())
|
QString::from(icon.to_string())
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ fn main() -> Result<()> {
|
|||||||
RunMode::Gui => {
|
RunMode::Gui => {
|
||||||
trace!(target:"main()", "Starting GUI in a new process");
|
trace!(target:"main()", "Starting GUI in a new process");
|
||||||
Command::new(std::env::current_exe()?)
|
Command::new(std::env::current_exe()?)
|
||||||
.args(&["--gui", app_context.path.to_str().unwrap()])
|
.args(["--gui", app_context.path.to_str().unwrap()])
|
||||||
.stdout(Stdio::null())
|
.stdout(Stdio::null())
|
||||||
.stderr(Stdio::null())
|
.stderr(Stdio::null())
|
||||||
.stdin(Stdio::null())
|
.stdin(Stdio::null())
|
||||||
|
|||||||
@@ -68,8 +68,8 @@ impl Widget for About {
|
|||||||
.map(|l| Line::from(Span::raw(*l)))
|
.map(|l| Line::from(Span::raw(*l)))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
Clear::default().render(kilroy_rect, buf);
|
Clear.render(kilroy_rect, buf);
|
||||||
Clear::default().render(chunks[1], buf);
|
Clear.render(chunks[1], buf);
|
||||||
Paragraph::new(about_lines)
|
Paragraph::new(about_lines)
|
||||||
.block(
|
.block(
|
||||||
Block::default()
|
Block::default()
|
||||||
|
|||||||
@@ -3,13 +3,11 @@
|
|||||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||||
|
|
||||||
use crate::tui::about::About;
|
use crate::tui::about::About;
|
||||||
use crate::tui::app::AppComponent::{AppEditor, AppExplorer, AppLogger};
|
|
||||||
use crate::tui::component::{Action, Component, Focus, FocusState, Visibility, VisibleState};
|
use crate::tui::component::{Action, Component, Focus, FocusState, Visibility, VisibleState};
|
||||||
use crate::tui::editor_tab::EditorTab;
|
use crate::tui::editor_tab::EditorTab;
|
||||||
use crate::tui::explorer::Explorer;
|
use crate::tui::explorer::Explorer;
|
||||||
use crate::tui::logger::Logger;
|
use crate::tui::logger::Logger;
|
||||||
use crate::tui::menu_bar::MenuBar;
|
use crate::tui::menu_bar::MenuBar;
|
||||||
use AppComponent::AppMenuBar;
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use log::{error, info, trace};
|
use log::{error, info, trace};
|
||||||
use ratatui::DefaultTerminal;
|
use ratatui::DefaultTerminal;
|
||||||
@@ -26,10 +24,10 @@ use std::time::Duration;
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum AppComponent {
|
pub enum AppComponent {
|
||||||
AppEditor,
|
Editor,
|
||||||
AppExplorer,
|
Explorer,
|
||||||
AppLogger,
|
Logger,
|
||||||
AppMenuBar,
|
MenuBar,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct App<'a> {
|
pub struct App<'a> {
|
||||||
@@ -51,7 +49,7 @@ impl<'a> App<'a> {
|
|||||||
explorer: Explorer::new(&root_path)?,
|
explorer: Explorer::new(&root_path)?,
|
||||||
logger: Logger::new(),
|
logger: Logger::new(),
|
||||||
menu_bar: MenuBar::new(),
|
menu_bar: MenuBar::new(),
|
||||||
last_active: AppEditor,
|
last_active: AppComponent::Editor,
|
||||||
about: false,
|
about: false,
|
||||||
};
|
};
|
||||||
Ok(app)
|
Ok(app)
|
||||||
@@ -87,7 +85,7 @@ impl<'a> App<'a> {
|
|||||||
fn draw_bottom_status(&self, area: Rect, buf: &mut Buffer) {
|
fn draw_bottom_status(&self, area: Rect, buf: &mut Buffer) {
|
||||||
// Determine help text from the most recently focused component.
|
// Determine help text from the most recently focused component.
|
||||||
let help = match self.last_active {
|
let help = match self.last_active {
|
||||||
AppEditor => match self.editor_tab.current_editor() {
|
AppComponent::Editor => match self.editor_tab.current_editor() {
|
||||||
Some(editor) => editor.component_state.help_text.clone(),
|
Some(editor) => editor.component_state.help_text.clone(),
|
||||||
None => {
|
None => {
|
||||||
if !self.editor_tab.is_empty() {
|
if !self.editor_tab.is_empty() {
|
||||||
@@ -96,9 +94,9 @@ impl<'a> App<'a> {
|
|||||||
"Failed to get current Editor while getting widget help text".to_string()
|
"Failed to get current Editor while getting widget help text".to_string()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
AppExplorer => self.explorer.component_state.help_text.clone(),
|
AppComponent::Explorer => self.explorer.component_state.help_text.clone(),
|
||||||
AppLogger => self.logger.component_state.help_text.clone(),
|
AppComponent::Logger => self.logger.component_state.help_text.clone(),
|
||||||
AppMenuBar => self.menu_bar.component_state.help_text.clone(),
|
AppComponent::MenuBar => self.menu_bar.component_state.help_text.clone(),
|
||||||
};
|
};
|
||||||
Paragraph::new(
|
Paragraph::new(
|
||||||
concat!(
|
concat!(
|
||||||
@@ -132,15 +130,15 @@ impl<'a> App<'a> {
|
|||||||
info!(target:Self::ID, "Changing widget focus to {:?}", focus);
|
info!(target:Self::ID, "Changing widget focus to {:?}", focus);
|
||||||
self.clear_focus();
|
self.clear_focus();
|
||||||
match focus {
|
match focus {
|
||||||
AppEditor => match self.editor_tab.current_editor_mut() {
|
AppComponent::Editor => match self.editor_tab.current_editor_mut() {
|
||||||
None => {
|
None => {
|
||||||
error!(target:Self::ID, "Failed to get current Editor while changing focus")
|
error!(target:Self::ID, "Failed to get current Editor while changing focus")
|
||||||
}
|
}
|
||||||
Some(editor) => editor.component_state.set_focus(Focus::Active),
|
Some(editor) => editor.component_state.set_focus(Focus::Active),
|
||||||
},
|
},
|
||||||
AppExplorer => self.explorer.component_state.set_focus(Focus::Active),
|
AppComponent::Explorer => self.explorer.component_state.set_focus(Focus::Active),
|
||||||
AppLogger => self.logger.component_state.set_focus(Focus::Active),
|
AppComponent::Logger => self.logger.component_state.set_focus(Focus::Active),
|
||||||
AppMenuBar => self.menu_bar.component_state.set_focus(Focus::Active),
|
AppComponent::MenuBar => self.menu_bar.component_state.set_focus(Focus::Active),
|
||||||
}
|
}
|
||||||
self.last_active = focus;
|
self.last_active = focus;
|
||||||
}
|
}
|
||||||
@@ -255,21 +253,21 @@ impl<'a> Component for App<'a> {
|
|||||||
}
|
}
|
||||||
// Handle events for all components.
|
// Handle events for all components.
|
||||||
let action = match self.last_active {
|
let action = match self.last_active {
|
||||||
AppEditor => self.editor_tab.handle_event(event.clone())?,
|
AppComponent::Editor => self.editor_tab.handle_event(event.clone())?,
|
||||||
AppExplorer => self.explorer.handle_event(event.clone())?,
|
AppComponent::Explorer => self.explorer.handle_event(event.clone())?,
|
||||||
AppLogger => self.logger.handle_event(event.clone())?,
|
AppComponent::Logger => self.logger.handle_event(event.clone())?,
|
||||||
AppMenuBar => self.menu_bar.handle_event(event.clone())?,
|
AppComponent::MenuBar => self.menu_bar.handle_event(event.clone())?,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Components should always handle mouse events for click interaction.
|
// Components should always handle mouse events for click interaction.
|
||||||
if let Some(mouse) = event.as_mouse_event() {
|
if let Some(mouse) = event.as_mouse_event()
|
||||||
if mouse.kind == MouseEventKind::Down(MouseButton::Left) {
|
&& mouse.kind == MouseEventKind::Down(MouseButton::Left)
|
||||||
if let Some(editor) = self.editor_tab.current_editor_mut() {
|
{
|
||||||
editor.handle_mouse_events(mouse)?;
|
if let Some(editor) = self.editor_tab.current_editor_mut() {
|
||||||
}
|
editor.handle_mouse_events(mouse)?;
|
||||||
self.explorer.handle_mouse_events(mouse)?;
|
|
||||||
self.logger.handle_mouse_events(mouse)?;
|
|
||||||
}
|
}
|
||||||
|
self.explorer.handle_mouse_events(mouse)?;
|
||||||
|
self.logger.handle_mouse_events(mouse)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle actions returned from widgets that may need context on other widgets or app state.
|
// Handle actions returned from widgets that may need context on other widgets or app state.
|
||||||
@@ -349,7 +347,7 @@ impl<'a> Component for App<'a> {
|
|||||||
kind: KeyEventKind::Press,
|
kind: KeyEventKind::Press,
|
||||||
state: _state,
|
state: _state,
|
||||||
} => {
|
} => {
|
||||||
self.change_focus(AppExplorer);
|
self.change_focus(AppComponent::Explorer);
|
||||||
Ok(Action::Handled)
|
Ok(Action::Handled)
|
||||||
}
|
}
|
||||||
KeyEvent {
|
KeyEvent {
|
||||||
@@ -358,7 +356,7 @@ impl<'a> Component for App<'a> {
|
|||||||
kind: KeyEventKind::Press,
|
kind: KeyEventKind::Press,
|
||||||
state: _state,
|
state: _state,
|
||||||
} => {
|
} => {
|
||||||
self.change_focus(AppEditor);
|
self.change_focus(AppComponent::Editor);
|
||||||
Ok(Action::Handled)
|
Ok(Action::Handled)
|
||||||
}
|
}
|
||||||
KeyEvent {
|
KeyEvent {
|
||||||
@@ -367,7 +365,7 @@ impl<'a> Component for App<'a> {
|
|||||||
kind: KeyEventKind::Press,
|
kind: KeyEventKind::Press,
|
||||||
state: _state,
|
state: _state,
|
||||||
} => {
|
} => {
|
||||||
self.change_focus(AppLogger);
|
self.change_focus(AppComponent::Logger);
|
||||||
Ok(Action::Handled)
|
Ok(Action::Handled)
|
||||||
}
|
}
|
||||||
KeyEvent {
|
KeyEvent {
|
||||||
@@ -376,7 +374,7 @@ impl<'a> Component for App<'a> {
|
|||||||
kind: KeyEventKind::Press,
|
kind: KeyEventKind::Press,
|
||||||
state: _state,
|
state: _state,
|
||||||
} => {
|
} => {
|
||||||
self.change_focus(AppMenuBar);
|
self.change_focus(AppComponent::MenuBar);
|
||||||
Ok(Action::Handled)
|
Ok(Action::Handled)
|
||||||
}
|
}
|
||||||
KeyEvent {
|
KeyEvent {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
use crate::tui::component::Focus::Inactive;
|
use crate::tui::component::Focus::Inactive;
|
||||||
use Focus::Active;
|
use Focus::Active;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use libclide::theme::colors::Colors;
|
||||||
use log::trace;
|
use log::trace;
|
||||||
use ratatui::crossterm::event::{Event, KeyEvent, MouseEvent};
|
use ratatui::crossterm::event::{Event, KeyEvent, MouseEvent};
|
||||||
use ratatui::style::Color;
|
use ratatui::style::Color;
|
||||||
@@ -98,8 +99,8 @@ pub enum Focus {
|
|||||||
impl Focus {
|
impl Focus {
|
||||||
pub(crate) fn get_active_color(&self) -> Color {
|
pub(crate) fn get_active_color(&self) -> Color {
|
||||||
match self {
|
match self {
|
||||||
Active => Color::LightYellow,
|
Active => Color::from_u32(Colors::css_to_u32(Colors::ACTIVE)?),
|
||||||
Inactive => Color::White,
|
Inactive => Color::from_u32(Colors::css_to_u32(Colors::INACTIVE)?),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,9 +115,8 @@ impl Component for Editor {
|
|||||||
fn handle_event(&mut self, event: Event) -> Result<Action> {
|
fn handle_event(&mut self, event: Event) -> Result<Action> {
|
||||||
if let Some(key_event) = event.as_key_event() {
|
if let Some(key_event) = event.as_key_event() {
|
||||||
// Handle events here that should not be passed on to the vim emulation handler.
|
// Handle events here that should not be passed on to the vim emulation handler.
|
||||||
match self.handle_key_events(key_event)? {
|
if let Action::Handled = self.handle_key_events(key_event)? {
|
||||||
Action::Handled => return Ok(Action::Handled),
|
return Ok(Action::Handled);
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.event_handler.on_event(event, &mut self.state);
|
self.event_handler.on_event(event, &mut self.state);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
use crate::tui::component::{Action, Component, ComponentState, Focus, FocusState};
|
use crate::tui::component::{Action, Component, ComponentState, Focus, FocusState};
|
||||||
use anyhow::{Context, Result, bail};
|
use anyhow::{Context, Result, bail};
|
||||||
|
use libclide::fs::entry_meta::EntryMeta;
|
||||||
use log::trace;
|
use log::trace;
|
||||||
use ratatui::buffer::Buffer;
|
use ratatui::buffer::Buffer;
|
||||||
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, MouseEvent, MouseEventKind};
|
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, MouseEvent, MouseEventKind};
|
||||||
@@ -11,14 +12,13 @@ use ratatui::layout::{Alignment, Position, Rect};
|
|||||||
use ratatui::prelude::Style;
|
use ratatui::prelude::Style;
|
||||||
use ratatui::style::{Color, Modifier};
|
use ratatui::style::{Color, Modifier};
|
||||||
use ratatui::widgets::{Block, Borders, StatefulWidget, Widget};
|
use ratatui::widgets::{Block, Borders, StatefulWidget, Widget};
|
||||||
use std::ffi::OsStr;
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use tui_tree_widget::{Tree, TreeItem, TreeState};
|
use tui_tree_widget::{Tree, TreeItem, TreeState};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Explorer<'a> {
|
pub struct Explorer<'a> {
|
||||||
pub(crate) root_path: PathBuf,
|
root_path: EntryMeta,
|
||||||
tree_items: TreeItem<'a, String>,
|
tree_items: TreeItem<'a, String>,
|
||||||
tree_state: TreeState<String>,
|
tree_state: TreeState<String>,
|
||||||
pub(crate) component_state: ComponentState,
|
pub(crate) component_state: ComponentState,
|
||||||
@@ -30,8 +30,8 @@ impl<'a> Explorer<'a> {
|
|||||||
pub fn new(path: &PathBuf) -> Result<Self> {
|
pub fn new(path: &PathBuf) -> Result<Self> {
|
||||||
trace!(target:Self::ID, "Building {}", Self::ID);
|
trace!(target:Self::ID, "Building {}", Self::ID);
|
||||||
let explorer = Explorer {
|
let explorer = Explorer {
|
||||||
root_path: path.to_owned(),
|
root_path: EntryMeta::new(path)?,
|
||||||
tree_items: Self::build_tree_from_path(path.to_owned())?,
|
tree_items: Self::build_tree_from_path(path)?,
|
||||||
tree_state: TreeState::default(),
|
tree_state: TreeState::default(),
|
||||||
component_state: ComponentState::default().with_help_text(concat!(
|
component_state: ComponentState::default().with_help_text(concat!(
|
||||||
"(↑/k)/(↓/j): Select item | ←/h: Close folder | →/l: Open folder |",
|
"(↑/k)/(↓/j): Select item | ←/h: Close folder | →/l: Open folder |",
|
||||||
@@ -41,46 +41,46 @@ impl<'a> Explorer<'a> {
|
|||||||
Ok(explorer)
|
Ok(explorer)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_tree_from_path(path: PathBuf) -> Result<TreeItem<'static, String>> {
|
/// 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();
|
||||||
let mut children = vec![];
|
let mut children = vec![];
|
||||||
let clean_path = fs::canonicalize(path)?;
|
let path_meta = EntryMeta::new(path)?;
|
||||||
if let Ok(entries) = fs::read_dir(&clean_path) {
|
if let Ok(entries) = fs::read_dir(&path_meta.abs_path) {
|
||||||
let mut paths = entries
|
let mut paths = entries
|
||||||
.map(|res| res.map(|e| e.path()))
|
.map(|res| res.map(|e| e.path()))
|
||||||
.collect::<Result<Vec<_>, std::io::Error>>()
|
.collect::<Result<Vec<_>, std::io::Error>>()
|
||||||
.context(format!(
|
.context(format!(
|
||||||
"Failed to build vector of paths under directory: {:?}",
|
"Failed to build vector of paths under directory: {:?}",
|
||||||
clean_path
|
&path_meta.abs_path
|
||||||
))?;
|
))?;
|
||||||
paths.sort();
|
paths.sort();
|
||||||
for path in paths {
|
for entry_path in paths {
|
||||||
if path.is_dir() {
|
let entry_meta = EntryMeta::new(&entry_path)?;
|
||||||
children.push(Self::build_tree_from_path(path)?);
|
if entry_meta.is_dir {
|
||||||
|
children.push(Self::build_tree_from_path(&entry_meta.abs_path)?);
|
||||||
} else {
|
} else {
|
||||||
if let Ok(path) = fs::canonicalize(&path) {
|
children.push(TreeItem::new_leaf(
|
||||||
let path_str = path.to_string_lossy().to_string();
|
entry_meta.abs_path.clone(),
|
||||||
children.push(TreeItem::new_leaf(
|
entry_meta.file_name.clone(),
|
||||||
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(
|
TreeItem::new(
|
||||||
clean_path.to_string_lossy().to_string() + uuid::Uuid::new_v4().to_string().as_str(),
|
path_meta.abs_path.clone(),
|
||||||
clean_path
|
path_meta.file_name.clone(),
|
||||||
.file_name()
|
|
||||||
.context(format!("Failed to get file name from path: {clean_path:?}"))?
|
|
||||||
.to_string_lossy()
|
|
||||||
.to_string(),
|
|
||||||
children,
|
children,
|
||||||
)
|
)
|
||||||
.context(format!("Failed to build tree from path: {clean_path:?}"))
|
.context(format!(
|
||||||
|
"Failed to build tree from path: {:?}",
|
||||||
|
path_meta.abs_path
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn selected(&self) -> Result<String> {
|
pub fn selected(&self) -> Result<String> {
|
||||||
@@ -96,16 +96,12 @@ impl<'a> Explorer<'a> {
|
|||||||
|
|
||||||
impl<'a> Widget for &mut Explorer<'a> {
|
impl<'a> Widget for &mut Explorer<'a> {
|
||||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||||
if let Ok(tree) = Tree::new(&self.tree_items.children()) {
|
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(
|
StatefulWidget::render(
|
||||||
tree.block(
|
tree.block(
|
||||||
Block::default()
|
Block::default()
|
||||||
.borders(Borders::ALL)
|
.borders(Borders::ALL)
|
||||||
.title(file_name.to_string_lossy())
|
.title(self.root_path.file_name.clone())
|
||||||
.border_style(Style::default().fg(self.component_state.get_active_color()))
|
.border_style(Style::default().fg(self.component_state.get_active_color()))
|
||||||
.title_style(Style::default().fg(Color::Green))
|
.title_style(Style::default().fg(Color::Green))
|
||||||
.title_alignment(Alignment::Center),
|
.title_alignment(Alignment::Center),
|
||||||
@@ -134,23 +130,21 @@ impl<'a> Component for Explorer<'a> {
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(mouse_event) = event.as_mouse_event() {
|
if let Some(mouse_event) = event.as_mouse_event()
|
||||||
match self.handle_mouse_events(mouse_event)? {
|
&& let Action::Handled = self.handle_mouse_events(mouse_event)?
|
||||||
Action::Handled => return Ok(Action::Handled),
|
{
|
||||||
_ => {}
|
return Ok(Action::Handled);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(Action::Pass)
|
Ok(Action::Pass)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_key_events(&mut self, key: KeyEvent) -> Result<Action> {
|
fn handle_key_events(&mut self, key: KeyEvent) -> Result<Action> {
|
||||||
if key.code == KeyCode::Enter {
|
if key.code == KeyCode::Enter
|
||||||
if let Ok(selected) = self.selected() {
|
&& let Ok(selected) = self.selected()
|
||||||
if Path::new(&selected).is_file() {
|
&& Path::new(&selected).is_file()
|
||||||
return Ok(Action::OpenTab);
|
{
|
||||||
}
|
// Open a tab if the selected item is a file.
|
||||||
}
|
return Ok(Action::OpenTab);
|
||||||
// Otherwise fall through and handle Enter in the next match case.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let changed = match key.code {
|
let changed = match key.code {
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ impl MenuBar {
|
|||||||
opened: MenuBarItem,
|
opened: MenuBarItem,
|
||||||
) {
|
) {
|
||||||
let popup_area = Self::rect_under_option(title_bar_anchor, area, 27, 10);
|
let popup_area = Self::rect_under_option(title_bar_anchor, area, 27, 10);
|
||||||
Clear::default().render(popup_area, buf);
|
Clear.render(popup_area, buf);
|
||||||
let options = opened.options().iter().map(|i| ListItem::new(i.id()));
|
let options = opened.options().iter().map(|i| ListItem::new(i.id()));
|
||||||
StatefulWidget::render(
|
StatefulWidget::render(
|
||||||
List::new(options)
|
List::new(options)
|
||||||
@@ -150,15 +150,14 @@ impl MenuBar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn rect_under_option(anchor: Rect, area: Rect, width: u16, height: u16) -> Rect {
|
fn rect_under_option(anchor: Rect, area: Rect, width: u16, height: u16) -> Rect {
|
||||||
let rect = Rect {
|
Rect {
|
||||||
x: anchor.x,
|
x: anchor.x,
|
||||||
y: anchor.y + anchor.height,
|
y: anchor.y + anchor.height,
|
||||||
width: width.min(area.width),
|
width: width.min(area.width),
|
||||||
height,
|
height,
|
||||||
};
|
}
|
||||||
// TODO: X offset for item option? It's fine as-is, but it might look nicer.
|
// TODO: X offset for item option? It's fine as-is, but it might look nicer.
|
||||||
// trace!(target:Self::ID, "Building Rect under MenuBar popup {}", rect);
|
// trace!(target:Self::ID, "Building Rect under MenuBar popup {}", rect);
|
||||||
rect
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user