Compare commits
41 Commits
shared-mod
...
2273c0156e
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 |
@@ -1,4 +1,4 @@
|
|||||||
name: Check
|
name: Build
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -26,9 +26,6 @@ jobs:
|
|||||||
- name: Build libclide
|
- name: Build libclide
|
||||||
run: |
|
run: |
|
||||||
cargo b -p libclide --release
|
cargo b -p libclide --release
|
||||||
- name: Build libclide-macros
|
|
||||||
run: |
|
|
||||||
cargo b -p libclide-macros --release
|
|
||||||
- name: Build clide
|
- name: Build clide
|
||||||
run: |
|
run: |
|
||||||
cargo b --release
|
cargo b --release
|
||||||
@@ -47,9 +44,6 @@ jobs:
|
|||||||
- name: Test libclide
|
- name: Test libclide
|
||||||
run: |
|
run: |
|
||||||
cargo test -p libclide
|
cargo test -p libclide
|
||||||
- name: Test libclide-macros
|
|
||||||
run: |
|
|
||||||
cargo test -p libclide-macros
|
|
||||||
- name: Test clide
|
- name: Test clide
|
||||||
run: |
|
run: |
|
||||||
cargo test
|
cargo test
|
||||||
@@ -67,31 +61,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Lint libclide
|
- name: Lint libclide
|
||||||
run: |
|
run: |
|
||||||
cargo clippy -p libclide -- -D warnings
|
cargo clippy --manifest-path libclide/Cargo.toml -- -D warnings
|
||||||
- name: Lint libclide-macros
|
|
||||||
run: |
|
|
||||||
cargo clippy -p libclide-macros -- -D warnings
|
|
||||||
- name: Lint clide
|
- name: Lint clide
|
||||||
run: |
|
run: |
|
||||||
cargo clippy -- -D warnings
|
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 libclide-macros
|
|
||||||
run: |
|
|
||||||
cargo fmt -p libclide-macros -- --check
|
|
||||||
- name: Format clide
|
|
||||||
run: |
|
|
||||||
cargo fmt --verbose -- --check
|
|
||||||
8
Cargo.lock
generated
8
Cargo.lock
generated
@@ -298,7 +298,7 @@ dependencies = [
|
|||||||
"devicons",
|
"devicons",
|
||||||
"dirs",
|
"dirs",
|
||||||
"edtui",
|
"edtui",
|
||||||
"libclide-macros",
|
"libclide",
|
||||||
"log",
|
"log",
|
||||||
"ratatui",
|
"ratatui",
|
||||||
"strum",
|
"strum",
|
||||||
@@ -1165,12 +1165,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112"
|
checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libclide-macros"
|
name = "libclide"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"anyhow",
|
||||||
"quote",
|
|
||||||
"syn 2.0.117",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
24
Cargo.toml
24
Cargo.toml
@@ -3,36 +3,22 @@ name = "clide"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "clide"
|
|
||||||
path = "src/bin/clide/main.rs"
|
|
||||||
|
|
||||||
[workspace]
|
|
||||||
resolver = "3"
|
|
||||||
members = [".", "libclide-macros", ]
|
|
||||||
|
|
||||||
[workspace.dependencies]
|
|
||||||
anyhow = "1.0.100"
|
|
||||||
strum = "0.27.2"
|
|
||||||
log = { version = "0.4.27", features = [] }
|
|
||||||
devicons = "0.6.12"
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cxx = "1.0.95"
|
cxx = "1.0.95"
|
||||||
cxx-qt = "0.8.0"
|
cxx-qt = "0.8.0"
|
||||||
cxx-qt-lib = { version = "0.8.0", features = ["qt_full", "qt_gui", "qt_qml"] }
|
cxx-qt-lib = { version = "0.8.0", features = ["qt_full", "qt_gui", "qt_qml"] }
|
||||||
|
log = { version = "0.4.27", features = [] }
|
||||||
dirs = "6.0.0"
|
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"
|
||||||
libclide-macros = { path = "./libclide-macros" }
|
strum = "0.27.2"
|
||||||
anyhow = { workspace = true }
|
devicons = "0.6.12"
|
||||||
strum = { workspace = true }
|
libclide = { path = "./libclide" }
|
||||||
log = { workspace = true }
|
|
||||||
devicons = { 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,6 +1,6 @@
|
|||||||
# CLIDE
|
# CLIDE
|
||||||
|
|
||||||
[](https://github.com/shaunrd0/clide/actions/workflows/check.yaml)
|
[](https://git.shaunreed.com/shaunrd0/clide/workflows/build.yml)
|
||||||
|
|
||||||
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.
|
||||||
@@ -21,7 +21,7 @@ And of course, [Rust](https://www.rust-lang.org/tools/install).
|
|||||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
||||||
```
|
```
|
||||||
|
|
||||||
This project requires at least Qt 6.7.3. To check your Qt version, you can use the following command
|
This project requires at least Qt 6.7.3 To check your Qt version
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
qmake6 -query QT_VERSION
|
qmake6 -query QT_VERSION
|
||||||
|
|||||||
4
build.rs
4
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",
|
||||||
@@ -28,6 +28,6 @@ fn main() {
|
|||||||
.qt_module("Svg")
|
.qt_module("Svg")
|
||||||
.qt_module("Xml")
|
.qt_module("Xml")
|
||||||
.qrc("./resources.qrc")
|
.qrc("./resources.qrc")
|
||||||
.files(["src/bin/clide/gui/colors.rs", "src/bin/clide/gui/filesystem.rs"])
|
.files(["src/gui/colors.rs", "src/gui/filesystem.rs"])
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "libclide-macros"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2024"
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
proc-macro = true
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
syn = { version = "2", features = ["full"] }
|
|
||||||
quote = "1"
|
|
||||||
proc-macro2 = "1"
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
|
||||||
|
|
||||||
use proc_macro::TokenStream;
|
|
||||||
use quote::quote;
|
|
||||||
use syn::{ItemStruct, parse_macro_input};
|
|
||||||
|
|
||||||
#[proc_macro_derive(Loggable)]
|
|
||||||
pub fn loggable(item: TokenStream) -> TokenStream {
|
|
||||||
let input = parse_macro_input!(item as ItemStruct);
|
|
||||||
let struct_name = &input.ident;
|
|
||||||
let generics = &input.generics;
|
|
||||||
|
|
||||||
let (impl_generics, type_generics, where_clause) = generics.split_for_impl();
|
|
||||||
let struct_name_str = struct_name.to_string();
|
|
||||||
let expanded = quote! {
|
|
||||||
impl #impl_generics clide::logging::Loggable for #struct_name #type_generics #where_clause {
|
|
||||||
const ID: &'static str = #struct_name_str;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
TokenStream::from(expanded)
|
|
||||||
}
|
|
||||||
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",
|
||||||
|
]
|
||||||
7
libclide/Cargo.toml
Normal file
7
libclide/Cargo.toml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[package]
|
||||||
|
name = "libclide"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
anyhow = "1.0.102"
|
||||||
@@ -3,5 +3,3 @@
|
|||||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||||
|
|
||||||
pub mod entry_meta;
|
pub mod entry_meta;
|
||||||
|
|
||||||
pub use entry_meta::icon;
|
|
||||||
@@ -2,16 +2,14 @@
|
|||||||
//
|
//
|
||||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
|
||||||
use devicons::FileIcon;
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use anyhow::{Context, Result};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct EntryMeta {
|
pub struct EntryMeta {
|
||||||
pub abs_path: String,
|
pub abs_path: String,
|
||||||
pub file_name: String,
|
pub file_name: String,
|
||||||
pub is_dir: bool,
|
pub is_dir: bool,
|
||||||
pub icon: FileIcon,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EntryMeta {
|
impl EntryMeta {
|
||||||
@@ -37,28 +35,16 @@ impl EntryMeta {
|
|||||||
pub fn new<P: AsRef<Path>>(p: P) -> Result<Self> {
|
pub fn new<P: AsRef<Path>>(p: P) -> Result<Self> {
|
||||||
let path = p.as_ref();
|
let path = p.as_ref();
|
||||||
let is_dir = path.is_dir();
|
let is_dir = path.is_dir();
|
||||||
let abs_path = Self::normalize(path).to_string_lossy().to_string();
|
let abs_path = Self::normalize(&path).to_string_lossy().to_string();
|
||||||
let file_name = Path::new(&abs_path)
|
let file_name = Path::new(&abs_path)
|
||||||
.file_name()
|
.file_name()
|
||||||
.context(format!("Failed to get file name for path: {abs_path:?}"))?
|
.context(format!("Failed to get file name for path: {abs_path:?}"))?
|
||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
.to_string();
|
.to_string();
|
||||||
let icon = icon(&abs_path);
|
|
||||||
Ok(EntryMeta {
|
Ok(EntryMeta {
|
||||||
abs_path,
|
abs_path,
|
||||||
file_name,
|
file_name,
|
||||||
is_dir,
|
is_dir,
|
||||||
icon,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn icon<P: AsRef<str>>(p: P) -> FileIcon {
|
|
||||||
let path = p.as_ref();
|
|
||||||
if Path::new(&path).is_dir() {
|
|
||||||
// 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.
|
|
||||||
return FileIcon::from("dir/");
|
|
||||||
}
|
|
||||||
FileIcon::from(path)
|
|
||||||
}
|
|
||||||
@@ -2,4 +2,4 @@
|
|||||||
//
|
//
|
||||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||||
|
|
||||||
pub mod colors;
|
pub mod fs;
|
||||||
@@ -3,6 +3,8 @@
|
|||||||
<file alias="kilroy.png">resources/images/kilroy-256.png</file>
|
<file alias="kilroy.png">resources/images/kilroy-256.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
<qresource prefix="/fonts">
|
<qresource prefix="/fonts">
|
||||||
|
<file alias="saucecodepro.ttf">resources/SauceCodeProNerdFont-Black.ttf</file>
|
||||||
|
<file alias="saucecodepro-light.ttf">resources/SauceCodeProNerdFont-Light.ttf</file>
|
||||||
<file alias="saucecodepro-xlight.ttf">resources/SauceCodeProNerdFont-ExtraLight.ttf</file>
|
<file alias="saucecodepro-xlight.ttf">resources/SauceCodeProNerdFont-ExtraLight.ttf</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
BIN
resources/SauceCodeProNerdFont-Black.ttf
Normal file
BIN
resources/SauceCodeProNerdFont-Black.ttf
Normal file
Binary file not shown.
BIN
resources/SauceCodeProNerdFont-Light.ttf
Normal file
BIN
resources/SauceCodeProNerdFont-Light.ttf
Normal file
Binary file not shown.
@@ -1,43 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
|
||||||
|
|
||||||
pub mod app_context;
|
|
||||||
|
|
||||||
use crate::cli::app_context::RunMode;
|
|
||||||
use anyhow::{Result, anyhow};
|
|
||||||
use clap::Parser;
|
|
||||||
|
|
||||||
/// Extendable command-line driven development environment written in Rust using the Qt UI framework.
|
|
||||||
/// If no flags are provided, the GUI editor is launched in a separate process.
|
|
||||||
/// If no path is provided, the current directory is used.
|
|
||||||
#[derive(Parser, Debug)]
|
|
||||||
#[structopt(name = "clide", verbatim_doc_comment)]
|
|
||||||
pub struct Cli {
|
|
||||||
/// The root directory for the project to open with the clide editor.
|
|
||||||
#[arg(value_parser = clap::value_parser!(std::path::PathBuf))]
|
|
||||||
pub path: Option<std::path::PathBuf>,
|
|
||||||
|
|
||||||
/// Run clide in headless mode.
|
|
||||||
#[arg(value_name = "tui", short, long)]
|
|
||||||
pub tui: bool,
|
|
||||||
|
|
||||||
/// Run the clide GUI in the current process, blocking the terminal and showing all output streams.
|
|
||||||
#[arg(value_name = "gui", short, long)]
|
|
||||||
pub gui: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Cli {
|
|
||||||
pub fn run_mode(&self) -> Result<RunMode> {
|
|
||||||
let mut modes = Vec::new();
|
|
||||||
self.tui.then(|| modes.push(RunMode::Tui));
|
|
||||||
self.gui.then(|| modes.push(RunMode::GuiAttached));
|
|
||||||
match &modes[..] {
|
|
||||||
[] => Ok(RunMode::Gui),
|
|
||||||
[mode] => Ok(*mode),
|
|
||||||
multiple => Err(anyhow!(
|
|
||||||
"More than one run mode found {multiple:?} please select one."
|
|
||||||
)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
|
||||||
|
|
||||||
use crate::cli::Cli;
|
|
||||||
use anyhow::{Context, Result};
|
|
||||||
|
|
||||||
pub struct AppContext {
|
|
||||||
pub path: std::path::PathBuf,
|
|
||||||
pub run_mode: RunMode,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AppContext {
|
|
||||||
pub fn new(cli: Cli) -> Result<Self> {
|
|
||||||
let path = match &cli.path {
|
|
||||||
// If the CLI was provided a directory, convert it to absolute.
|
|
||||||
Some(path) => std::path::absolute(path)?,
|
|
||||||
// If no path was provided, use the current directory.
|
|
||||||
None => std::env::current_dir().context("Failed to obtain current directory")?,
|
|
||||||
};
|
|
||||||
clide::info!(target:"main()", "Root path detected: {path:?}");
|
|
||||||
|
|
||||||
Ok(Self {
|
|
||||||
path,
|
|
||||||
run_mode: cli.run_mode()?,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Default)]
|
|
||||||
pub enum RunMode {
|
|
||||||
#[default]
|
|
||||||
Gui,
|
|
||||||
GuiAttached,
|
|
||||||
Tui,
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
|
||||||
|
|
||||||
mod cli;
|
|
||||||
mod gui;
|
|
||||||
mod tui;
|
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
|
||||||
use clap::Parser;
|
|
||||||
use cli::Cli;
|
|
||||||
use cli::app_context::{AppContext, RunMode};
|
|
||||||
use std::process::{Command, Stdio};
|
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
|
||||||
let args = Cli::parse();
|
|
||||||
let app_context = AppContext::new(args)?;
|
|
||||||
match app_context.run_mode {
|
|
||||||
RunMode::GuiAttached => gui::run(app_context),
|
|
||||||
RunMode::Tui => tui::run(app_context),
|
|
||||||
RunMode::Gui => {
|
|
||||||
clide::trace!(target:"main()", "Starting GUI in a new process");
|
|
||||||
Command::new(std::env::current_exe()?)
|
|
||||||
.args(["--gui", app_context.path.to_str().unwrap()])
|
|
||||||
.stdout(Stdio::null())
|
|
||||||
.stderr(Stdio::null())
|
|
||||||
.stdin(Stdio::null())
|
|
||||||
.spawn()
|
|
||||||
.context("Failed to start GUI")
|
|
||||||
.map(|_| ())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,16 +2,16 @@
|
|||||||
//
|
//
|
||||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||||
|
|
||||||
pub mod colors;
|
use crate::AppContext;
|
||||||
pub mod filesystem;
|
|
||||||
pub mod icon_provider;
|
|
||||||
|
|
||||||
use crate::cli::app_context::AppContext;
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use cxx_qt_lib::{QMapPair, QMapPair_QString_QVariant, QString, QVariant};
|
use cxx_qt_lib::{QMapPair, QMapPair_QString_QVariant, QString, QVariant};
|
||||||
|
use log::trace;
|
||||||
|
|
||||||
|
pub mod colors;
|
||||||
|
pub mod filesystem;
|
||||||
|
|
||||||
pub fn run(app_context: AppContext) -> Result<()> {
|
pub fn run(app_context: AppContext) -> Result<()> {
|
||||||
clide::trace!(target:"gui::run()", "Starting the GUI editor at {:?}", app_context.path);
|
trace!(target:"gui::run()", "Starting the GUI editor at {:?}", app_context.path);
|
||||||
|
|
||||||
use cxx_qt_lib::{QGuiApplication, QQmlApplicationEngine, QUrl};
|
use cxx_qt_lib::{QGuiApplication, QQmlApplicationEngine, QUrl};
|
||||||
|
|
||||||
@@ -2,10 +2,8 @@
|
|||||||
//
|
//
|
||||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||||
|
|
||||||
use clide::theme::colors::Colors;
|
|
||||||
use cxx_qt_lib::QColor;
|
|
||||||
|
|
||||||
#[cxx_qt::bridge]
|
#[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");
|
||||||
@@ -48,6 +46,8 @@ 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(Colors::HOVERED).unwrap(),
|
hovered: QColor::try_from("#303234").unwrap(),
|
||||||
unhovered: QColor::try_from(Colors::UNHOVERED).unwrap(),
|
unhovered: QColor::try_from("#3c3f41").unwrap(),
|
||||||
pressed: QColor::try_from(Colors::PRESSED).unwrap(),
|
pressed: QColor::try_from("#4b4f51").unwrap(),
|
||||||
menubar: QColor::try_from(Colors::MENUBAR).unwrap(),
|
menubar: QColor::try_from("#262626").unwrap(),
|
||||||
menubar_border: QColor::try_from(Colors::MENUBAR_BORDER).unwrap(),
|
menubar_border: QColor::try_from("#575757").unwrap(),
|
||||||
scrollbar: QColor::try_from(Colors::SCROLLBAR).unwrap(),
|
scrollbar: QColor::try_from("#4b4f51").unwrap(),
|
||||||
scrollbar_active: QColor::try_from(Colors::SCROLLBAR_ACTIVE).unwrap(),
|
scrollbar_active: QColor::try_from("#4b4f51").unwrap(),
|
||||||
scrollbar_gutter: QColor::try_from(Colors::SCROLLBAR_GUTTER).unwrap(),
|
scrollbar_gutter: QColor::try_from("#3b3b3b").unwrap(),
|
||||||
linenumber: QColor::try_from(Colors::LINENUMBER).unwrap(),
|
linenumber: QColor::try_from("#94989b").unwrap(),
|
||||||
active: QColor::try_from(Colors::ACTIVE).unwrap(),
|
active: QColor::try_from("#a9acb0").unwrap(),
|
||||||
inactive: QColor::try_from(Colors::INACTIVE).unwrap(),
|
inactive: QColor::try_from("#FFF").unwrap(),
|
||||||
editor_background: QColor::try_from(Colors::EDITOR_BACKGROUND).unwrap(),
|
editor_background: QColor::try_from("#1E1F22").unwrap(),
|
||||||
editor_text: QColor::try_from(Colors::EDITOR_TEXT).unwrap(),
|
editor_text: QColor::try_from("#acaea3").unwrap(),
|
||||||
editor_highlighted_text: QColor::try_from(Colors::EDITOR_HIGHLIGHTED_TEXT).unwrap(),
|
editor_highlighted_text: QColor::try_from("#ccced3").unwrap(),
|
||||||
editor_highlight: QColor::try_from(Colors::EDITOR_HIGHLIGHT).unwrap(),
|
editor_highlight: QColor::try_from("#ccced3").unwrap(),
|
||||||
gutter: QColor::try_from(Colors::GUTTER).unwrap(),
|
gutter: QColor::try_from("#1e1f22").unwrap(),
|
||||||
explorer_hovered: QColor::try_from(Colors::EXPLORER_HOVERED).unwrap(),
|
explorer_hovered: QColor::try_from("#4c5053").unwrap(),
|
||||||
explorer_text: QColor::try_from(Colors::EXPLORER_TEXT).unwrap(),
|
explorer_text: QColor::try_from("#FFF").unwrap(),
|
||||||
explorer_text_selected: QColor::try_from(Colors::EXPLORER_TEXT_SELECTED).unwrap(),
|
explorer_text_selected: QColor::try_from("#262626").unwrap(),
|
||||||
explorer_background: QColor::try_from(Colors::EXPLORER_BACKGROUND).unwrap(),
|
explorer_background: QColor::try_from("#1E1F22").unwrap(),
|
||||||
explorer_folder: QColor::try_from(Colors::EXPLORER_FOLDER).unwrap(),
|
explorer_folder: QColor::try_from("#54585b").unwrap(),
|
||||||
explorer_folder_open: QColor::try_from(Colors::EXPLORER_FOLDER_OPEN).unwrap(),
|
explorer_folder_open: QColor::try_from("#393B40").unwrap(),
|
||||||
terminal_background: QColor::try_from(Colors::TERMINAL_BACKGROUND).unwrap(),
|
terminal_background: QColor::try_from("#111111").unwrap(),
|
||||||
info_log: QColor::try_from(Colors::INFO_LOG).unwrap(),
|
info_log: QColor::try_from("#C4FFFF").unwrap(),
|
||||||
debug_log: QColor::try_from(Colors::DEBUG_LOG).unwrap(),
|
debug_log: QColor::try_from("#9148AF").unwrap(),
|
||||||
warn_log: QColor::try_from(Colors::WARN_LOG).unwrap(),
|
warn_log: QColor::try_from("#C4A958").unwrap(),
|
||||||
error_log: QColor::try_from(Colors::ERROR_LOG).unwrap(),
|
error_log: QColor::try_from("#ff5555").unwrap(),
|
||||||
trace_log: QColor::try_from(Colors::TRACE_LOG).unwrap(),
|
trace_log: QColor::try_from("#ffaa00").unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,9 @@
|
|||||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||||
|
|
||||||
use cxx_qt_lib::{QModelIndex, QString};
|
use cxx_qt_lib::{QModelIndex, QString};
|
||||||
|
use devicons::FileIcon;
|
||||||
use dirs;
|
use dirs;
|
||||||
|
use log::warn;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use syntect::easy::HighlightLines;
|
use syntect::easy::HighlightLines;
|
||||||
@@ -74,9 +76,9 @@ impl qobject::FileSystem {
|
|||||||
return QString::default();
|
return QString::default();
|
||||||
}
|
}
|
||||||
let meta = fs::metadata(path.to_string())
|
let meta = fs::metadata(path.to_string())
|
||||||
.unwrap_or_else(|_| panic!("Failed to get file metadata {path:?}"));
|
.expect(format!("Failed to get file metadata {path:?}").as_str());
|
||||||
if !meta.is_file() {
|
if !meta.is_file() {
|
||||||
clide::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();
|
||||||
}
|
}
|
||||||
let path_str = path.to_string();
|
let path_str = path.to_string();
|
||||||
@@ -112,7 +114,7 @@ impl qobject::FileSystem {
|
|||||||
output.push_str("</pre>\n");
|
output.push_str("</pre>\n");
|
||||||
QString::from(output)
|
QString::from(output)
|
||||||
} else {
|
} else {
|
||||||
QString::default()
|
return QString::default();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,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())
|
||||||
.unwrap_or_else(|_| panic!("Failed to get metadata for path {path:?}"))
|
.expect(format!("Failed to get metadata for path {path:?}").as_str())
|
||||||
.is_dir()
|
.is_dir()
|
||||||
{
|
{
|
||||||
self.set_root_path(path)
|
self.set_root_path(path)
|
||||||
@@ -141,6 +143,13 @@ impl qobject::FileSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn icon(self: std::pin::Pin<&mut Self>, path: &QString) -> QString {
|
fn icon(self: std::pin::Pin<&mut Self>, path: &QString) -> QString {
|
||||||
QString::from(clide::fs::icon(path.to_string().as_str()).to_string())
|
let str = path.to_string();
|
||||||
|
if Path::new(&str).is_dir() {
|
||||||
|
// 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.
|
||||||
|
return QString::from(FileIcon::from("dir/").to_string())
|
||||||
|
}
|
||||||
|
let icon = FileIcon::from(str);
|
||||||
|
QString::from(icon.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
|
||||||
|
|
||||||
pub mod fs;
|
|
||||||
pub mod logging;
|
|
||||||
pub mod theme;
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
|
||||||
|
|
||||||
pub mod macros;
|
|
||||||
|
|
||||||
pub use libclide_macros::Loggable;
|
|
||||||
pub trait Loggable {
|
|
||||||
const ID: &'static str;
|
|
||||||
}
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
|
||||||
|
|
||||||
//! Logging targets allow filtering of log messages by their source. By default, the log crate sets
|
|
||||||
//! the target to the module path where the log macro was invoked if no target is provided.
|
|
||||||
//!
|
|
||||||
//! These macros essentially disable using the default target and instead require the target to be
|
|
||||||
//! explicitly set. This is to avoid implicit pooling of log messages under the same default target,
|
|
||||||
//! which can make it difficult to filter log messages by their source.
|
|
||||||
//!
|
|
||||||
//! The Loggable trait can be implemented to automatically associate log messages with a struct.
|
|
||||||
//! ```
|
|
||||||
//! use clide::logging;
|
|
||||||
//! use libclide_macros::Loggable;
|
|
||||||
//!
|
|
||||||
//! #[derive(Loggable)]
|
|
||||||
//! struct MyStruct;
|
|
||||||
//! impl MyStruct {
|
|
||||||
//! fn my_method(&self) {
|
|
||||||
//! clide::info!("This log message will use target Self::ID, which is 'MyStruct'");
|
|
||||||
//! }
|
|
||||||
//! }
|
|
||||||
//! ```
|
|
||||||
//!
|
|
||||||
//! If the struct does not derive or implement Loggable, the target variant of the log macros must
|
|
||||||
//! be used instead.
|
|
||||||
//! ```
|
|
||||||
//! clide::info!(target: "CustomTarget", "This log message will have the target 'CustomTarget'");
|
|
||||||
//! ```
|
|
||||||
//!
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! info {
|
|
||||||
(target: $target:expr, $($arg:tt)+) => ({
|
|
||||||
::log::info!(target: $target, $($arg)+)
|
|
||||||
});
|
|
||||||
|
|
||||||
($($arg:tt)+) => (::log::info!(target: Self::ID, $($arg)+))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! debug {
|
|
||||||
(target: $target:expr, $($arg:tt)+) => ({
|
|
||||||
::log::debug!(target: $target, $($arg)+)
|
|
||||||
});
|
|
||||||
|
|
||||||
($($arg:tt)+) => (::log::debug!(target: Self::ID, $($arg)+))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! warn {
|
|
||||||
(target: $target:expr, $($arg:tt)+) => ({
|
|
||||||
::log::warn!(target: $target, $($arg)+)
|
|
||||||
});
|
|
||||||
|
|
||||||
($($arg:tt)+) => (::log::warn!(target: Self::ID, $($arg)+))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! error {
|
|
||||||
(target: $target:expr, $($arg:tt)+) => ({
|
|
||||||
::log::error!(target: $target, $($arg)+)
|
|
||||||
});
|
|
||||||
|
|
||||||
($($arg:tt)+) => (::log::error!(target: Self::ID, $($arg)+))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! trace {
|
|
||||||
(target: $target:expr, $($arg:tt)+) => ({
|
|
||||||
::log::trace!(target: $target, $($arg)+)
|
|
||||||
});
|
|
||||||
|
|
||||||
($($arg:tt)+) => (::log::trace!(target: Self::ID, $($arg)+))
|
|
||||||
}
|
|
||||||
94
src/main.rs
Normal file
94
src/main.rs
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||||
|
|
||||||
|
use anyhow::{Context, Result, anyhow};
|
||||||
|
use clap::Parser;
|
||||||
|
use log::{info, trace};
|
||||||
|
use std::process::{Command, Stdio};
|
||||||
|
|
||||||
|
pub mod gui;
|
||||||
|
pub mod tui;
|
||||||
|
/// Extendable command-line driven development environment written in Rust using the Qt UI framework.
|
||||||
|
/// If no flags are provided, the GUI editor is launched in a separate process.
|
||||||
|
/// If no path is provided, the current directory is used.
|
||||||
|
#[derive(Parser, Debug)]
|
||||||
|
#[structopt(name = "clide", verbatim_doc_comment)]
|
||||||
|
struct Cli {
|
||||||
|
/// The root directory for the project to open with the clide editor.
|
||||||
|
#[arg(value_parser = clap::value_parser!(std::path::PathBuf))]
|
||||||
|
pub path: Option<std::path::PathBuf>,
|
||||||
|
|
||||||
|
/// Run clide in headless mode.
|
||||||
|
#[arg(value_name = "tui", short, long)]
|
||||||
|
pub tui: bool,
|
||||||
|
|
||||||
|
/// Run the clide GUI in the current process, blocking the terminal and showing all output streams.
|
||||||
|
#[arg(value_name = "gui", short, long)]
|
||||||
|
pub gui: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Cli {
|
||||||
|
fn run_mode(&self) -> Result<RunMode> {
|
||||||
|
let mut modes = Vec::new();
|
||||||
|
self.tui.then(|| modes.push(RunMode::Tui));
|
||||||
|
self.gui.then(|| modes.push(RunMode::GuiAttached));
|
||||||
|
match &modes[..] {
|
||||||
|
[] => Ok(RunMode::Gui),
|
||||||
|
[mode] => Ok(*mode),
|
||||||
|
multiple => Err(anyhow!(
|
||||||
|
"More than one run mode found {multiple:?} please select one."
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct AppContext {
|
||||||
|
pub path: std::path::PathBuf,
|
||||||
|
pub run_mode: RunMode,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AppContext {
|
||||||
|
fn new(cli: Cli) -> Result<Self> {
|
||||||
|
let path = match &cli.path {
|
||||||
|
// If the CLI was provided a directory, convert it to absolute.
|
||||||
|
Some(path) => std::path::absolute(path)?,
|
||||||
|
// If no path was provided, use the current directory.
|
||||||
|
None => std::env::current_dir().context("Failed to obtain current directory")?,
|
||||||
|
};
|
||||||
|
info!(target:"main()", "Root path detected: {path:?}");
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
path,
|
||||||
|
run_mode: cli.run_mode()?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, Default)]
|
||||||
|
pub enum RunMode {
|
||||||
|
#[default]
|
||||||
|
Gui,
|
||||||
|
GuiAttached,
|
||||||
|
Tui,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> Result<()> {
|
||||||
|
let args = Cli::parse();
|
||||||
|
let app_context = AppContext::new(args)?;
|
||||||
|
match app_context.run_mode {
|
||||||
|
RunMode::GuiAttached => gui::run(app_context),
|
||||||
|
RunMode::Tui => tui::run(app_context),
|
||||||
|
RunMode::Gui => {
|
||||||
|
trace!(target:"main()", "Starting GUI in a new process");
|
||||||
|
Command::new(std::env::current_exe()?)
|
||||||
|
.args(&["--gui", app_context.path.to_str().unwrap()])
|
||||||
|
.stdout(Stdio::null())
|
||||||
|
.stderr(Stdio::null())
|
||||||
|
.stdin(Stdio::null())
|
||||||
|
.spawn()
|
||||||
|
.context("Failed to start GUI")
|
||||||
|
.map(|_| ())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
|
||||||
|
|
||||||
/// Colors shared between the TUI and GUI for the current theme.
|
|
||||||
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 = "#d1d33f";
|
|
||||||
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";
|
|
||||||
|
|
||||||
/// Converts a CSS hex color string (e.g., "#RRGGBB" or "#RGB") to u32 in 0x00RRGGBB format.
|
|
||||||
pub fn css_to_u32(css: &str) -> u32 {
|
|
||||||
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_n(c, 2).collect::<String>())
|
|
||||||
.collect::<String>(),
|
|
||||||
6 => hex.to_string(),
|
|
||||||
_ => panic!("Invalid hex color length: {hex:?}"),
|
|
||||||
};
|
|
||||||
// Parse the hex string as u32, masking to ensure the top (alpha) byte is 0x00.
|
|
||||||
u32::from_str_radix(&hex_full, 16)
|
|
||||||
.map(|rgb| rgb & 0x00FF_FFFF)
|
|
||||||
.unwrap_or_else(|e| panic!("Failed to parse hex: {e:?}"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,19 +2,18 @@
|
|||||||
//
|
//
|
||||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||||
|
|
||||||
pub mod about;
|
mod about;
|
||||||
pub mod app;
|
mod app;
|
||||||
pub mod component;
|
mod component;
|
||||||
pub mod editor;
|
mod editor;
|
||||||
pub mod editor_tab;
|
mod editor_tab;
|
||||||
pub mod explorer;
|
mod explorer;
|
||||||
pub mod logger;
|
mod logger;
|
||||||
pub mod menu_bar;
|
mod menu_bar;
|
||||||
|
|
||||||
use crate::cli::app_context::AppContext;
|
use crate::AppContext;
|
||||||
use ::log::LevelFilter;
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use clide::logging::Loggable;
|
use log::{LevelFilter, debug, info, trace};
|
||||||
use ratatui::Terminal;
|
use ratatui::Terminal;
|
||||||
use ratatui::backend::CrosstermBackend;
|
use ratatui::backend::CrosstermBackend;
|
||||||
use ratatui::crossterm::event::{
|
use ratatui::crossterm::event::{
|
||||||
@@ -29,22 +28,24 @@ use tui_logger::{
|
|||||||
TuiLoggerFile, TuiLoggerLevelOutput, init_logger, set_default_level, set_log_file,
|
TuiLoggerFile, TuiLoggerLevelOutput, init_logger, set_default_level, set_log_file,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Loggable)]
|
|
||||||
struct Tui {
|
struct Tui {
|
||||||
terminal: Terminal<CrosstermBackend<Stdout>>,
|
terminal: Terminal<CrosstermBackend<Stdout>>,
|
||||||
root_path: std::path::PathBuf,
|
root_path: std::path::PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(app_context: AppContext) -> Result<()> {
|
pub fn run(app_context: AppContext) -> Result<()> {
|
||||||
clide::trace!(target: "clide::tui::run", "Starting TUI");
|
trace!(target:Tui::ID, "Starting TUI");
|
||||||
Tui::new(app_context)?.start()
|
Tui::new(app_context)?.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tui {
|
impl Tui {
|
||||||
|
pub const ID: &str = "Tui";
|
||||||
|
|
||||||
fn new(app_context: AppContext) -> Result<Self> {
|
fn new(app_context: AppContext) -> Result<Self> {
|
||||||
|
trace!(target:Self::ID, "Building {}", Self::ID);
|
||||||
init_logger(LevelFilter::Trace)?;
|
init_logger(LevelFilter::Trace)?;
|
||||||
set_default_level(LevelFilter::Trace);
|
set_default_level(LevelFilter::Trace);
|
||||||
clide::debug!("Logging initialized");
|
debug!(target:Self::ID, "Logging initialized");
|
||||||
|
|
||||||
let mut dir = env::temp_dir();
|
let mut dir = env::temp_dir();
|
||||||
dir.push("clide.log");
|
dir.push("clide.log");
|
||||||
@@ -56,7 +57,7 @@ impl Tui {
|
|||||||
.output_file(false)
|
.output_file(false)
|
||||||
.output_separator(':');
|
.output_separator(':');
|
||||||
set_log_file(file_options);
|
set_log_file(file_options);
|
||||||
clide::debug!("Logging to file: {dir:?}");
|
debug!(target:Self::ID, "Logging to file: {dir:?}");
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
terminal: Terminal::new(CrosstermBackend::new(stdout()))?,
|
terminal: Terminal::new(CrosstermBackend::new(stdout()))?,
|
||||||
@@ -65,7 +66,7 @@ impl Tui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn start(self) -> Result<()> {
|
fn start(self) -> Result<()> {
|
||||||
clide::info!("Starting the TUI editor at {:?}", self.root_path);
|
info!(target:Self::ID, "Starting the TUI editor at {:?}", self.root_path);
|
||||||
ratatui::crossterm::execute!(
|
ratatui::crossterm::execute!(
|
||||||
stdout(),
|
stdout(),
|
||||||
EnterAlternateScreen,
|
EnterAlternateScreen,
|
||||||
@@ -82,7 +83,7 @@ impl Tui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn stop() -> Result<()> {
|
fn stop() -> Result<()> {
|
||||||
clide::info!("Stopping the TUI editor");
|
info!(target:Self::ID, "Stopping the TUI editor");
|
||||||
disable_raw_mode()?;
|
disable_raw_mode()?;
|
||||||
ratatui::crossterm::execute!(
|
ratatui::crossterm::execute!(
|
||||||
stdout(),
|
stdout(),
|
||||||
@@ -2,18 +2,19 @@
|
|||||||
//
|
//
|
||||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||||
|
|
||||||
use clide::logging::Loggable;
|
|
||||||
use ratatui::buffer::Buffer;
|
use ratatui::buffer::Buffer;
|
||||||
use ratatui::layout::{Constraint, Direction, Layout, Rect};
|
use ratatui::layout::{Constraint, Direction, Layout, Rect};
|
||||||
use ratatui::text::{Line, Span};
|
use ratatui::text::{Line, Span};
|
||||||
use ratatui::widgets::{Block, Borders, Clear, Padding, Paragraph, Widget, Wrap};
|
use ratatui::widgets::{Block, Borders, Clear, Padding, Paragraph, Widget, Wrap};
|
||||||
|
|
||||||
#[derive(Loggable, Default)]
|
|
||||||
pub struct About {}
|
pub struct About {}
|
||||||
|
|
||||||
impl About {
|
impl About {
|
||||||
|
#[allow(unused)]
|
||||||
|
pub const ID: &str = "About";
|
||||||
|
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
// clide::trace!("Building {}", Self::id());
|
// trace!(target:Self::id(), "Building {}", Self::id());
|
||||||
Self {}
|
Self {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,8 +68,8 @@ impl Widget for About {
|
|||||||
.map(|l| Line::from(Span::raw(*l)))
|
.map(|l| Line::from(Span::raw(*l)))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
Clear.render(kilroy_rect, buf);
|
Clear::default().render(kilroy_rect, buf);
|
||||||
Clear.render(chunks[1], buf);
|
Clear::default().render(chunks[1], buf);
|
||||||
Paragraph::new(about_lines)
|
Paragraph::new(about_lines)
|
||||||
.block(
|
.block(
|
||||||
Block::default()
|
Block::default()
|
||||||
@@ -3,13 +3,15 @@
|
|||||||
// 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 clide::logging::Loggable;
|
use AppComponent::AppMenuBar;
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
|
use log::{error, info, trace};
|
||||||
use ratatui::DefaultTerminal;
|
use ratatui::DefaultTerminal;
|
||||||
use ratatui::buffer::Buffer;
|
use ratatui::buffer::Buffer;
|
||||||
use ratatui::crossterm::event;
|
use ratatui::crossterm::event;
|
||||||
@@ -24,13 +26,12 @@ use std::time::Duration;
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum AppComponent {
|
pub enum AppComponent {
|
||||||
Editor,
|
AppEditor,
|
||||||
Explorer,
|
AppExplorer,
|
||||||
Logger,
|
AppLogger,
|
||||||
MenuBar,
|
AppMenuBar,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Loggable)]
|
|
||||||
pub struct App<'a> {
|
pub struct App<'a> {
|
||||||
editor_tab: EditorTab,
|
editor_tab: EditorTab,
|
||||||
explorer: Explorer<'a>,
|
explorer: Explorer<'a>,
|
||||||
@@ -41,14 +42,16 @@ pub struct App<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> App<'a> {
|
impl<'a> App<'a> {
|
||||||
|
pub const ID: &'static str = "App";
|
||||||
|
|
||||||
pub fn new(root_path: PathBuf) -> Result<Self> {
|
pub fn new(root_path: PathBuf) -> Result<Self> {
|
||||||
clide::trace!("Building");
|
trace!(target:Self::ID, "Building {}", Self::ID);
|
||||||
let app = Self {
|
let app = Self {
|
||||||
editor_tab: EditorTab::new(),
|
editor_tab: EditorTab::new(),
|
||||||
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: AppComponent::Editor,
|
last_active: AppEditor,
|
||||||
about: false,
|
about: false,
|
||||||
};
|
};
|
||||||
Ok(app)
|
Ok(app)
|
||||||
@@ -56,13 +59,13 @@ impl<'a> App<'a> {
|
|||||||
|
|
||||||
/// Logic that should be executed once on application startup.
|
/// Logic that should be executed once on application startup.
|
||||||
pub fn start(&mut self) -> Result<()> {
|
pub fn start(&mut self) -> Result<()> {
|
||||||
clide::trace!("Starting App");
|
trace!(target:Self::ID, "Starting App");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(mut self, mut terminal: DefaultTerminal) -> Result<()> {
|
pub fn run(mut self, mut terminal: DefaultTerminal) -> Result<()> {
|
||||||
self.start()?;
|
self.start()?;
|
||||||
clide::trace!("Entering App run loop");
|
trace!(target:Self::ID, "Entering App run loop");
|
||||||
loop {
|
loop {
|
||||||
terminal.draw(|f| {
|
terminal.draw(|f| {
|
||||||
f.render_widget(&mut self, f.area());
|
f.render_widget(&mut self, f.area());
|
||||||
@@ -84,18 +87,18 @@ 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 {
|
||||||
AppComponent::Editor => match self.editor_tab.current_editor() {
|
AppEditor => 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() {
|
||||||
clide::error!("Failed to get Editor while drawing bottom status bar");
|
error!(target:Self::ID, "Failed to get Editor while drawing bottom status bar");
|
||||||
}
|
}
|
||||||
"Failed to get current Editor while getting widget help text".to_string()
|
"Failed to get current Editor while getting widget help text".to_string()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
AppComponent::Explorer => self.explorer.component_state.help_text.clone(),
|
AppExplorer => self.explorer.component_state.help_text.clone(),
|
||||||
AppComponent::Logger => self.logger.component_state.help_text.clone(),
|
AppLogger => self.logger.component_state.help_text.clone(),
|
||||||
AppComponent::MenuBar => self.menu_bar.component_state.help_text.clone(),
|
AppMenuBar => self.menu_bar.component_state.help_text.clone(),
|
||||||
};
|
};
|
||||||
Paragraph::new(
|
Paragraph::new(
|
||||||
concat!(
|
concat!(
|
||||||
@@ -112,32 +115,32 @@ impl<'a> App<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn clear_focus(&mut self) {
|
fn clear_focus(&mut self) {
|
||||||
clide::info!("Clearing all widget focus");
|
info!(target:Self::ID, "Clearing all widget focus");
|
||||||
self.explorer.component_state.set_focus(Focus::Inactive);
|
self.explorer.component_state.set_focus(Focus::Inactive);
|
||||||
self.explorer.component_state.set_focus(Focus::Inactive);
|
self.explorer.component_state.set_focus(Focus::Inactive);
|
||||||
self.logger.component_state.set_focus(Focus::Inactive);
|
self.logger.component_state.set_focus(Focus::Inactive);
|
||||||
self.menu_bar.component_state.set_focus(Focus::Inactive);
|
self.menu_bar.component_state.set_focus(Focus::Inactive);
|
||||||
match self.editor_tab.current_editor_mut() {
|
match self.editor_tab.current_editor_mut() {
|
||||||
None => {
|
None => {
|
||||||
clide::error!("Failed to get current Editor while clearing focus")
|
error!(target:Self::ID, "Failed to get current Editor while clearing focus")
|
||||||
}
|
}
|
||||||
Some(editor) => editor.component_state.set_focus(Focus::Inactive),
|
Some(editor) => editor.component_state.set_focus(Focus::Inactive),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn change_focus(&mut self, focus: AppComponent) {
|
fn change_focus(&mut self, focus: AppComponent) {
|
||||||
clide::info!("Changing widget focus to {:?}", focus);
|
info!(target:Self::ID, "Changing widget focus to {:?}", focus);
|
||||||
self.clear_focus();
|
self.clear_focus();
|
||||||
match focus {
|
match focus {
|
||||||
AppComponent::Editor => match self.editor_tab.current_editor_mut() {
|
AppEditor => match self.editor_tab.current_editor_mut() {
|
||||||
None => {
|
None => {
|
||||||
clide::error!("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),
|
||||||
},
|
},
|
||||||
AppComponent::Explorer => self.explorer.component_state.set_focus(Focus::Active),
|
AppExplorer => self.explorer.component_state.set_focus(Focus::Active),
|
||||||
AppComponent::Logger => self.logger.component_state.set_focus(Focus::Active),
|
AppLogger => self.logger.component_state.set_focus(Focus::Active),
|
||||||
AppComponent::MenuBar => self.menu_bar.component_state.set_focus(Focus::Active),
|
AppMenuBar => self.menu_bar.component_state.set_focus(Focus::Active),
|
||||||
}
|
}
|
||||||
self.last_active = focus;
|
self.last_active = focus;
|
||||||
}
|
}
|
||||||
@@ -252,21 +255,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 {
|
||||||
AppComponent::Editor => self.editor_tab.handle_event(event.clone())?,
|
AppEditor => self.editor_tab.handle_event(event.clone())?,
|
||||||
AppComponent::Explorer => self.explorer.handle_event(event.clone())?,
|
AppExplorer => self.explorer.handle_event(event.clone())?,
|
||||||
AppComponent::Logger => self.logger.handle_event(event.clone())?,
|
AppLogger => self.logger.handle_event(event.clone())?,
|
||||||
AppComponent::MenuBar => self.menu_bar.handle_event(event.clone())?,
|
AppMenuBar => 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() {
|
||||||
&& mouse.kind == MouseEventKind::Down(MouseButton::Left)
|
if mouse.kind == MouseEventKind::Down(MouseButton::Left) {
|
||||||
{
|
if let Some(editor) = self.editor_tab.current_editor_mut() {
|
||||||
if let Some(editor) = self.editor_tab.current_editor_mut() {
|
editor.handle_mouse_events(mouse)?;
|
||||||
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.
|
||||||
@@ -274,13 +277,13 @@ impl<'a> Component for App<'a> {
|
|||||||
Action::Quit | Action::Handled => Ok(action),
|
Action::Quit | Action::Handled => Ok(action),
|
||||||
Action::Save => match self.editor_tab.current_editor_mut() {
|
Action::Save => match self.editor_tab.current_editor_mut() {
|
||||||
None => {
|
None => {
|
||||||
clide::error!("Failed to get current editor while handling App Action::Save");
|
error!(target:Self::ID, "Failed to get current editor while handling App Action::Save");
|
||||||
Ok(Action::Noop)
|
Ok(Action::Noop)
|
||||||
}
|
}
|
||||||
Some(editor) => match editor.save() {
|
Some(editor) => match editor.save() {
|
||||||
Ok(_) => Ok(Action::Handled),
|
Ok(_) => Ok(Action::Handled),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
clide::error!("Failed to save editor contents: {e}");
|
error!(target:Self::ID, "Failed to save editor contents: {e}");
|
||||||
Ok(Action::Noop)
|
Ok(Action::Noop)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -299,16 +302,14 @@ impl<'a> Component for App<'a> {
|
|||||||
Err(_) => Ok(Action::Noop),
|
Err(_) => Ok(Action::Noop),
|
||||||
},
|
},
|
||||||
Action::ReloadFile => {
|
Action::ReloadFile => {
|
||||||
clide::trace!("Reloading file for current editor");
|
trace!(target:Self::ID, "Reloading file for current editor");
|
||||||
if let Some(editor) = self.editor_tab.current_editor_mut() {
|
if let Some(editor) = self.editor_tab.current_editor_mut() {
|
||||||
editor
|
editor
|
||||||
.reload_contents()
|
.reload_contents()
|
||||||
.map(|_| Action::Handled)
|
.map(|_| Action::Handled)
|
||||||
.context("Failed to handle Action::ReloadFile")
|
.context("Failed to handle Action::ReloadFile")
|
||||||
} else {
|
} else {
|
||||||
clide::error!(
|
error!(target:Self::ID, "Failed to get current editor while handling App Action::ReloadFile");
|
||||||
"Failed to get current editor while handling App Action::ReloadFile"
|
|
||||||
);
|
|
||||||
Ok(Action::Noop)
|
Ok(Action::Noop)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -348,7 +349,7 @@ impl<'a> Component for App<'a> {
|
|||||||
kind: KeyEventKind::Press,
|
kind: KeyEventKind::Press,
|
||||||
state: _state,
|
state: _state,
|
||||||
} => {
|
} => {
|
||||||
self.change_focus(AppComponent::Explorer);
|
self.change_focus(AppExplorer);
|
||||||
Ok(Action::Handled)
|
Ok(Action::Handled)
|
||||||
}
|
}
|
||||||
KeyEvent {
|
KeyEvent {
|
||||||
@@ -357,7 +358,7 @@ impl<'a> Component for App<'a> {
|
|||||||
kind: KeyEventKind::Press,
|
kind: KeyEventKind::Press,
|
||||||
state: _state,
|
state: _state,
|
||||||
} => {
|
} => {
|
||||||
self.change_focus(AppComponent::Editor);
|
self.change_focus(AppEditor);
|
||||||
Ok(Action::Handled)
|
Ok(Action::Handled)
|
||||||
}
|
}
|
||||||
KeyEvent {
|
KeyEvent {
|
||||||
@@ -366,7 +367,7 @@ impl<'a> Component for App<'a> {
|
|||||||
kind: KeyEventKind::Press,
|
kind: KeyEventKind::Press,
|
||||||
state: _state,
|
state: _state,
|
||||||
} => {
|
} => {
|
||||||
self.change_focus(AppComponent::Logger);
|
self.change_focus(AppLogger);
|
||||||
Ok(Action::Handled)
|
Ok(Action::Handled)
|
||||||
}
|
}
|
||||||
KeyEvent {
|
KeyEvent {
|
||||||
@@ -375,7 +376,7 @@ impl<'a> Component for App<'a> {
|
|||||||
kind: KeyEventKind::Press,
|
kind: KeyEventKind::Press,
|
||||||
state: _state,
|
state: _state,
|
||||||
} => {
|
} => {
|
||||||
self.change_focus(AppComponent::MenuBar);
|
self.change_focus(AppMenuBar);
|
||||||
Ok(Action::Handled)
|
Ok(Action::Handled)
|
||||||
}
|
}
|
||||||
KeyEvent {
|
KeyEvent {
|
||||||
@@ -5,10 +5,9 @@
|
|||||||
#![allow(dead_code, unused_variables)]
|
#![allow(dead_code, unused_variables)]
|
||||||
|
|
||||||
use crate::tui::component::Focus::Inactive;
|
use crate::tui::component::Focus::Inactive;
|
||||||
use clide::logging::Loggable;
|
|
||||||
use clide::theme::colors::Colors;
|
|
||||||
use Focus::Active;
|
use Focus::Active;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
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;
|
||||||
|
|
||||||
@@ -62,7 +61,7 @@ pub trait Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, Loggable)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct ComponentState {
|
pub struct ComponentState {
|
||||||
pub(crate) focus: Focus,
|
pub(crate) focus: Focus,
|
||||||
pub(crate) vis: Visibility,
|
pub(crate) vis: Visibility,
|
||||||
@@ -75,7 +74,7 @@ impl ComponentState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
clide::trace!(target:Self::id(), "Building {}", Self::id());
|
trace!(target:Self::id(), "Building {}", Self::id());
|
||||||
Self {
|
Self {
|
||||||
focus: Active,
|
focus: Active,
|
||||||
vis: Visibility::Visible,
|
vis: Visibility::Visible,
|
||||||
@@ -99,8 +98,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::from_u32(Colors::css_to_u32(Colors::ACTIVE)),
|
Active => Color::LightYellow,
|
||||||
Inactive => Color::from_u32(Colors::css_to_u32(Colors::INACTIVE)),
|
Inactive => Color::White,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,11 +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::component::{Action, Component, ComponentState, Focus, FocusState};
|
use crate::tui::component::{Action, Component, ComponentState, Focus, FocusState};
|
||||||
use clide::logging::Loggable;
|
|
||||||
use anyhow::{Context, Result, bail};
|
use anyhow::{Context, Result, bail};
|
||||||
use edtui::{
|
use edtui::{
|
||||||
EditorEventHandler, EditorState, EditorTheme, EditorView, LineNumbers, Lines, SyntaxHighlighter,
|
EditorEventHandler, EditorState, EditorTheme, EditorView, LineNumbers, Lines, SyntaxHighlighter,
|
||||||
};
|
};
|
||||||
|
use log::{error, trace};
|
||||||
use ratatui::buffer::Buffer;
|
use ratatui::buffer::Buffer;
|
||||||
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
|
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
|
||||||
use ratatui::layout::{Alignment, Rect};
|
use ratatui::layout::{Alignment, Rect};
|
||||||
@@ -16,18 +16,19 @@ use ratatui::widgets::{Block, Borders, Padding, Widget};
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use syntect::parsing::SyntaxSet;
|
use syntect::parsing::SyntaxSet;
|
||||||
|
|
||||||
#[derive(Loggable)]
|
|
||||||
pub struct Editor {
|
pub struct Editor {
|
||||||
pub state: EditorState,
|
pub state: EditorState,
|
||||||
pub event_handler: EditorEventHandler,
|
pub event_handler: EditorEventHandler,
|
||||||
pub file_path: Option<PathBuf>,
|
pub file_path: Option<std::path::PathBuf>,
|
||||||
syntax_set: SyntaxSet,
|
syntax_set: SyntaxSet,
|
||||||
pub(crate) component_state: ComponentState,
|
pub(crate) component_state: ComponentState,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Editor {
|
impl Editor {
|
||||||
|
pub const ID: &str = "Editor";
|
||||||
|
|
||||||
pub fn new(path: &std::path::Path) -> Self {
|
pub fn new(path: &std::path::Path) -> Self {
|
||||||
clide::trace!("Building {}", <Self as Loggable>::ID);
|
trace!(target:Self::ID, "Building {}", Self::ID);
|
||||||
Editor {
|
Editor {
|
||||||
state: EditorState::default(),
|
state: EditorState::default(),
|
||||||
event_handler: EditorEventHandler::default(),
|
event_handler: EditorEventHandler::default(),
|
||||||
@@ -41,10 +42,10 @@ impl Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn reload_contents(&mut self) -> Result<()> {
|
pub fn reload_contents(&mut self) -> Result<()> {
|
||||||
clide::trace!("Reloading editor file contents {:?}", self.file_path);
|
trace!(target:Self::ID, "Reloading editor file contents {:?}", self.file_path);
|
||||||
match self.file_path.clone() {
|
match self.file_path.clone() {
|
||||||
None => {
|
None => {
|
||||||
clide::error!("Failed to reload editor contents with None file_path");
|
error!(target:Self::ID, "Failed to reload editor contents with None file_path");
|
||||||
bail!("Failed to reload editor contents with None file_path")
|
bail!("Failed to reload editor contents with None file_path")
|
||||||
}
|
}
|
||||||
Some(path) => self.set_contents(&path),
|
Some(path) => self.set_contents(&path),
|
||||||
@@ -52,7 +53,7 @@ impl Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_contents(&mut self, path: &std::path::Path) -> Result<()> {
|
pub fn set_contents(&mut self, path: &std::path::Path) -> Result<()> {
|
||||||
clide::trace!("Setting Editor contents from path {:?}", path);
|
trace!(target:Self::ID, "Setting Editor contents from path {:?}", path);
|
||||||
if let Ok(contents) = std::fs::read_to_string(path) {
|
if let Ok(contents) = std::fs::read_to_string(path) {
|
||||||
let lines: Vec<_> = contents
|
let lines: Vec<_> = contents
|
||||||
.lines()
|
.lines()
|
||||||
@@ -68,10 +69,10 @@ impl Editor {
|
|||||||
|
|
||||||
pub fn save(&self) -> Result<()> {
|
pub fn save(&self) -> Result<()> {
|
||||||
if let Some(path) = &self.file_path {
|
if let Some(path) = &self.file_path {
|
||||||
clide::trace!("Saving Editor contents {:?}", path);
|
trace!(target:Self::ID, "Saving Editor contents {:?}", path);
|
||||||
return std::fs::write(path, self.state.lines.to_string()).map_err(|e| e.into());
|
return std::fs::write(path, self.state.lines.to_string()).map_err(|e| e.into());
|
||||||
};
|
};
|
||||||
clide::error!("Failed saving Editor contents; file_path was None");
|
error!(target:Self::ID, "Failed saving Editor contents; file_path was None");
|
||||||
bail!("File not saved. No file path set.")
|
bail!("File not saved. No file path set.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,8 +115,9 @@ 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.
|
||||||
if let Action::Handled = self.handle_key_events(key_event)? {
|
match self.handle_key_events(key_event)? {
|
||||||
return Ok(Action::Handled);
|
Action::Handled => return Ok(Action::Handled),
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.event_handler.on_event(event, &mut self.state);
|
self.event_handler.on_event(event, &mut self.state);
|
||||||
@@ -2,21 +2,20 @@
|
|||||||
//
|
//
|
||||||
// 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::component::{Action, Component, Focus, FocusState};
|
||||||
use crate::tui::editor::Editor;
|
use crate::tui::editor::Editor;
|
||||||
use clide::logging::Loggable;
|
|
||||||
use anyhow::{Context, Result, anyhow};
|
use anyhow::{Context, Result, anyhow};
|
||||||
|
use log::{error, info, trace, warn};
|
||||||
use ratatui::buffer::Buffer;
|
use ratatui::buffer::Buffer;
|
||||||
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
|
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
|
||||||
use ratatui::layout::Rect;
|
use ratatui::layout::Rect;
|
||||||
use ratatui::prelude::{Color, Style};
|
use ratatui::prelude::{Color, Style};
|
||||||
use ratatui::widgets::{Block, Borders, Padding, Tabs, Widget};
|
use ratatui::widgets::{Block, Borders, Padding, Tabs, Widget};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use crate::tui::component::{Action, Component, Focus, FocusState};
|
|
||||||
|
|
||||||
// Render the tabs with keys as titles
|
// Render the tabs with keys as titles
|
||||||
// Tab keys can be file names.
|
// Tab keys can be file names.
|
||||||
// Render the editor using the key as a reference for lookup
|
// Render the editor using the key as a reference for lookup
|
||||||
#[derive(Loggable, Default)]
|
|
||||||
pub struct EditorTab {
|
pub struct EditorTab {
|
||||||
pub(crate) editors: HashMap<String, Editor>,
|
pub(crate) editors: HashMap<String, Editor>,
|
||||||
tab_order: Vec<String>,
|
tab_order: Vec<String>,
|
||||||
@@ -24,8 +23,10 @@ pub struct EditorTab {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EditorTab {
|
impl EditorTab {
|
||||||
|
pub const ID: &str = "EditorTab";
|
||||||
|
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
clide::trace!("Building {}", <Self as Loggable>::ID);
|
trace!(target:Self::ID, "Building {}", Self::ID);
|
||||||
Self {
|
Self {
|
||||||
editors: HashMap::new(),
|
editors: HashMap::new(),
|
||||||
tab_order: Vec::new(),
|
tab_order: Vec::new(),
|
||||||
@@ -35,11 +36,7 @@ impl EditorTab {
|
|||||||
|
|
||||||
pub fn next_editor(&mut self) {
|
pub fn next_editor(&mut self) {
|
||||||
let next = (self.current_editor + 1) % self.tab_order.len();
|
let next = (self.current_editor + 1) % self.tab_order.len();
|
||||||
clide::trace!(
|
trace!(target:Self::ID, "Moving from {} to next editor tab at {}", self.current_editor, next);
|
||||||
"Moving from {} to next editor tab at {}",
|
|
||||||
self.current_editor,
|
|
||||||
next
|
|
||||||
);
|
|
||||||
self.set_tab_focus(Focus::Active, next);
|
self.set_tab_focus(Focus::Active, next);
|
||||||
self.current_editor = next;
|
self.current_editor = next;
|
||||||
}
|
}
|
||||||
@@ -49,11 +46,7 @@ impl EditorTab {
|
|||||||
.current_editor
|
.current_editor
|
||||||
.checked_sub(1)
|
.checked_sub(1)
|
||||||
.unwrap_or(self.tab_order.len() - 1);
|
.unwrap_or(self.tab_order.len() - 1);
|
||||||
clide::trace!(
|
trace!(target:Self::ID, "Moving from {} to previous editor tab at {}", self.current_editor, prev);
|
||||||
"Moving from {} to previous editor tab at {}",
|
|
||||||
self.current_editor,
|
|
||||||
prev
|
|
||||||
);
|
|
||||||
self.set_tab_focus(Focus::Active, prev);
|
self.set_tab_focus(Focus::Active, prev);
|
||||||
self.current_editor = prev;
|
self.current_editor = prev;
|
||||||
}
|
}
|
||||||
@@ -62,7 +55,7 @@ impl EditorTab {
|
|||||||
match self.tab_order.get(index) {
|
match self.tab_order.get(index) {
|
||||||
None => {
|
None => {
|
||||||
if !self.tab_order.is_empty() {
|
if !self.tab_order.is_empty() {
|
||||||
clide::error!("Failed to get editor tab key with invalid index {index}");
|
error!(target:Self::ID, "Failed to get editor tab key with invalid index {index}");
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@@ -80,19 +73,16 @@ impl EditorTab {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_current_tab_focus(&mut self, focus: Focus) {
|
pub fn set_current_tab_focus(&mut self, focus: Focus) {
|
||||||
clide::trace!(
|
trace!(target:Self::ID, "Setting current tab {} focus to {:?}", self.current_editor, focus);
|
||||||
"Setting current tab {} focus to {:?}",
|
|
||||||
self.current_editor,
|
|
||||||
focus
|
|
||||||
);
|
|
||||||
self.set_tab_focus(focus, self.current_editor)
|
self.set_tab_focus(focus, self.current_editor)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_tab_focus(&mut self, focus: Focus, index: usize) {
|
pub fn set_tab_focus(&mut self, focus: Focus, index: usize) {
|
||||||
clide::trace!("Setting tab {} focus to {:?}", index, focus);
|
trace!(target:Self::ID, "Setting tab {} focus to {:?}", index, focus);
|
||||||
if focus == Focus::Active && index != self.current_editor {
|
if focus == Focus::Active && index != self.current_editor {
|
||||||
// If we are setting another tab to active, disable the current one.
|
// If we are setting another tab to active, disable the current one.
|
||||||
clide::trace!(
|
trace!(
|
||||||
|
target:Self::ID,
|
||||||
"New tab {} focus set to Active; Setting current tab {} to Inactive",
|
"New tab {} focus set to Active; Setting current tab {} to Inactive",
|
||||||
index,
|
index,
|
||||||
self.current_editor
|
self.current_editor
|
||||||
@@ -101,11 +91,12 @@ impl EditorTab {
|
|||||||
}
|
}
|
||||||
match self.get_editor_key(index) {
|
match self.get_editor_key(index) {
|
||||||
None => {
|
None => {
|
||||||
clide::error!("Failed setting tab focus for invalid key {index}");
|
error!(target:Self::ID, "Failed setting tab focus for invalid key {index}");
|
||||||
}
|
}
|
||||||
Some(key) => match self.editors.get_mut(&key) {
|
Some(key) => match self.editors.get_mut(&key) {
|
||||||
None => {
|
None => {
|
||||||
clide::error!(
|
error!(
|
||||||
|
target:Self::ID,
|
||||||
"Failed to update tab focus at index {} with invalid key: {}",
|
"Failed to update tab focus at index {} with invalid key: {}",
|
||||||
self.current_editor,
|
self.current_editor,
|
||||||
self.tab_order[self.current_editor]
|
self.tab_order[self.current_editor]
|
||||||
@@ -117,12 +108,12 @@ impl EditorTab {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn open_tab(&mut self, path: &std::path::Path) -> Result<()> {
|
pub fn open_tab(&mut self, path: &std::path::Path) -> Result<()> {
|
||||||
clide::trace!("Opening new EditorTab with path {:?}", path);
|
trace!(target:Self::ID, "Opening new EditorTab with path {:?}", path);
|
||||||
if self
|
if self
|
||||||
.editors
|
.editors
|
||||||
.contains_key(&path.to_string_lossy().to_string())
|
.contains_key(&path.to_string_lossy().to_string())
|
||||||
{
|
{
|
||||||
clide::warn!("EditorTab already opened with this file");
|
warn!(target:Self::ID, "EditorTab already opened with this file");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,12 +138,12 @@ impl EditorTab {
|
|||||||
.to_owned();
|
.to_owned();
|
||||||
match self.editors.remove(&key) {
|
match self.editors.remove(&key) {
|
||||||
None => {
|
None => {
|
||||||
clide::error!("Failed to remove editor tab {key} with invalid index {index}")
|
error!(target:Self::ID, "Failed to remove editor tab {key} with invalid index {index}")
|
||||||
}
|
}
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
self.prev_editor();
|
self.prev_editor();
|
||||||
self.tab_order.remove(index);
|
self.tab_order.remove(index);
|
||||||
clide::info!("Closed editor tab {key} at index {index}")
|
info!(target:Self::ID, "Closed editor tab {key} at index {index}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -4,8 +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 clide::fs::entry_meta::EntryMeta;
|
use log::{trace};
|
||||||
use clide::logging::Loggable;
|
|
||||||
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};
|
||||||
use ratatui::layout::{Alignment, Position, Rect};
|
use ratatui::layout::{Alignment, Position, Rect};
|
||||||
@@ -15,8 +14,9 @@ use ratatui::widgets::{Block, Borders, StatefulWidget, Widget};
|
|||||||
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};
|
||||||
|
use libclide::fs::entry_meta::EntryMeta;
|
||||||
|
|
||||||
#[derive(Debug, Loggable)]
|
#[derive(Debug)]
|
||||||
pub struct Explorer<'a> {
|
pub struct Explorer<'a> {
|
||||||
root_path: EntryMeta,
|
root_path: EntryMeta,
|
||||||
tree_items: TreeItem<'a, String>,
|
tree_items: TreeItem<'a, String>,
|
||||||
@@ -25,11 +25,13 @@ pub struct Explorer<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Explorer<'a> {
|
impl<'a> Explorer<'a> {
|
||||||
|
pub const ID: &'static str = "Explorer";
|
||||||
|
|
||||||
pub fn new(path: &PathBuf) -> Result<Self> {
|
pub fn new(path: &PathBuf) -> Result<Self> {
|
||||||
clide::trace!("Building {}", <Self as Loggable>::ID);
|
trace!(target:Self::ID, "Building {}", Self::ID);
|
||||||
let explorer = Explorer {
|
let explorer = Explorer {
|
||||||
root_path: EntryMeta::new(path)?,
|
root_path: EntryMeta::new(&path)?,
|
||||||
tree_items: Self::build_tree_from_path(path)?,
|
tree_items: Self::build_tree_from_path(path.to_owned())?,
|
||||||
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 |",
|
||||||
@@ -62,19 +64,17 @@ impl<'a> Explorer<'a> {
|
|||||||
} else {
|
} else {
|
||||||
children.push(TreeItem::new_leaf(
|
children.push(TreeItem::new_leaf(
|
||||||
entry_meta.abs_path.clone(),
|
entry_meta.abs_path.clone(),
|
||||||
format!("{}", entry_meta.file_name.as_str()),
|
entry_meta.file_name.clone(),
|
||||||
// format!("{} {}", entry_meta.icon.icon, entry_meta.file_name.as_str()),
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: The first argument is a unique identifier, where no. 2 TreeItems may share the same.
|
// 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.
|
// For a file tree this is fine because we shouldn't list the same object twice.
|
||||||
TreeItem::new(
|
TreeItem::new(
|
||||||
path_meta.abs_path.clone(),
|
path_meta.abs_path.clone(),
|
||||||
format!("{}", path_meta.file_name.as_str()),
|
path_meta.file_name.clone(),
|
||||||
// format!("{} {}", path_meta.icon.icon, path_meta.file_name.as_str()),
|
|
||||||
children,
|
children,
|
||||||
)
|
)
|
||||||
.context(format!(
|
.context(format!(
|
||||||
@@ -96,7 +96,7 @@ 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()) {
|
||||||
StatefulWidget::render(
|
StatefulWidget::render(
|
||||||
tree.block(
|
tree.block(
|
||||||
Block::default()
|
Block::default()
|
||||||
@@ -130,21 +130,23 @@ impl<'a> Component for Explorer<'a> {
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(mouse_event) = event.as_mouse_event()
|
if let Some(mouse_event) = event.as_mouse_event() {
|
||||||
&& let Action::Handled = self.handle_mouse_events(mouse_event)?
|
match 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 {
|
||||||
&& let Ok(selected) = self.selected()
|
if let Ok(selected) = self.selected() {
|
||||||
&& Path::new(&selected).is_file()
|
if 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 {
|
||||||
@@ -3,8 +3,7 @@
|
|||||||
// 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::component::{Action, Component, ComponentState, Focus, FocusState};
|
use crate::tui::component::{Action, Component, ComponentState, Focus, FocusState};
|
||||||
use clide::logging::Loggable;
|
use log::{LevelFilter, trace};
|
||||||
use log::LevelFilter;
|
|
||||||
use ratatui::buffer::Buffer;
|
use ratatui::buffer::Buffer;
|
||||||
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent};
|
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent};
|
||||||
use ratatui::layout::Rect;
|
use ratatui::layout::Rect;
|
||||||
@@ -12,17 +11,18 @@ use ratatui::style::{Color, Style};
|
|||||||
use ratatui::widgets::Widget;
|
use ratatui::widgets::Widget;
|
||||||
use tui_logger::{TuiLoggerLevelOutput, TuiLoggerSmartWidget, TuiWidgetEvent, TuiWidgetState};
|
use tui_logger::{TuiLoggerLevelOutput, TuiLoggerSmartWidget, TuiWidgetEvent, TuiWidgetState};
|
||||||
|
|
||||||
/// Any logging written as info!(target:self.id(), "message") will work with this logger.
|
/// Any log written as info!(target:self.id(), "message") will work with this logger.
|
||||||
/// The logger is bound to info!, debug!, error!, trace! macros within Tui::new().
|
/// The logger is bound to info!, debug!, error!, trace! macros within Tui::new().
|
||||||
#[derive(Loggable, Default)]
|
|
||||||
pub struct Logger {
|
pub struct Logger {
|
||||||
state: TuiWidgetState,
|
state: TuiWidgetState,
|
||||||
pub(crate) component_state: ComponentState,
|
pub(crate) component_state: ComponentState,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Logger {
|
impl Logger {
|
||||||
|
pub const ID: &str = "Logger";
|
||||||
|
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
clide::trace!("Building {}", <Self as Loggable>::ID);
|
trace!(target:Self::ID, "Building {}", Self::ID);
|
||||||
let state = TuiWidgetState::new();
|
let state = TuiWidgetState::new();
|
||||||
state.transition(TuiWidgetEvent::HideKey);
|
state.transition(TuiWidgetEvent::HideKey);
|
||||||
Self {
|
Self {
|
||||||
@@ -6,8 +6,8 @@ use crate::tui::component::{Action, Component, ComponentState, FocusState};
|
|||||||
use crate::tui::menu_bar::MenuBarItemOption::{
|
use crate::tui::menu_bar::MenuBarItemOption::{
|
||||||
About, CloseTab, Exit, Reload, Save, ShowHideExplorer, ShowHideLogger,
|
About, CloseTab, Exit, Reload, Save, ShowHideExplorer, ShowHideLogger,
|
||||||
};
|
};
|
||||||
use clide::logging::Loggable;
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
use log::trace;
|
||||||
use ratatui::buffer::Buffer;
|
use ratatui::buffer::Buffer;
|
||||||
use ratatui::crossterm::event::{KeyCode, KeyEvent};
|
use ratatui::crossterm::event::{KeyCode, KeyEvent};
|
||||||
use ratatui::layout::Rect;
|
use ratatui::layout::Rect;
|
||||||
@@ -18,9 +18,8 @@ use ratatui::widgets::{
|
|||||||
};
|
};
|
||||||
use strum::{EnumIter, FromRepr, IntoEnumIterator};
|
use strum::{EnumIter, FromRepr, IntoEnumIterator};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromRepr, EnumIter, Default)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromRepr, EnumIter)]
|
||||||
enum MenuBarItem {
|
enum MenuBarItem {
|
||||||
#[default]
|
|
||||||
File,
|
File,
|
||||||
View,
|
View,
|
||||||
Help,
|
Help,
|
||||||
@@ -81,7 +80,6 @@ impl MenuBarItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Loggable, Default)]
|
|
||||||
pub struct MenuBar {
|
pub struct MenuBar {
|
||||||
selected: MenuBarItem,
|
selected: MenuBarItem,
|
||||||
opened: Option<MenuBarItem>,
|
opened: Option<MenuBarItem>,
|
||||||
@@ -90,9 +88,11 @@ pub struct MenuBar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MenuBar {
|
impl MenuBar {
|
||||||
|
pub const ID: &str = "MenuBar";
|
||||||
|
|
||||||
const DEFAULT_HELP: &str = "(←/h)/(→/l): Select option | Enter: Choose selection";
|
const DEFAULT_HELP: &str = "(←/h)/(→/l): Select option | Enter: Choose selection";
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
clide::trace!("Building");
|
trace!(target:Self::ID, "Building {}", Self::ID);
|
||||||
Self {
|
Self {
|
||||||
selected: MenuBarItem::File,
|
selected: MenuBarItem::File,
|
||||||
opened: None,
|
opened: None,
|
||||||
@@ -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.render(popup_area, buf);
|
Clear::default().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,14 +150,15 @@ 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 {
|
||||||
Rect {
|
let 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!("Building Rect under MenuBar popup {}", rect);
|
// trace!(target:Self::ID, "Building Rect under MenuBar popup {}", rect);
|
||||||
|
rect
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user