Compare commits
51 Commits
shared-mod
...
01de2390ac
| Author | SHA1 | Date | |
|---|---|---|---|
| 01de2390ac | |||
| 784592658a | |||
| 779872b2f6 | |||
| e5f77ef51c | |||
| 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 |
11
Cargo.lock
generated
11
Cargo.lock
generated
@@ -298,6 +298,7 @@ dependencies = [
|
||||
"devicons",
|
||||
"dirs",
|
||||
"edtui",
|
||||
"libclide",
|
||||
"libclide-macros",
|
||||
"log",
|
||||
"ratatui",
|
||||
@@ -1164,6 +1165,16 @@ version = "0.2.182"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112"
|
||||
|
||||
[[package]]
|
||||
name = "libclide"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"devicons",
|
||||
"log",
|
||||
"strum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libclide-macros"
|
||||
version = "0.1.0"
|
||||
|
||||
@@ -3,13 +3,9 @@ name = "clide"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[[bin]]
|
||||
name = "clide"
|
||||
path = "src/bin/clide/main.rs"
|
||||
|
||||
[workspace]
|
||||
resolver = "3"
|
||||
members = [".", "libclide-macros", ]
|
||||
members = [".", "libclide", "libclide-macros", ]
|
||||
|
||||
[workspace.dependencies]
|
||||
anyhow = "1.0.100"
|
||||
@@ -28,6 +24,7 @@ ratatui = "0.30.0"
|
||||
tui-tree-widget = "0.24.0"
|
||||
tui-logger = "0.18.1"
|
||||
edtui = "0.11.1"
|
||||
libclide = { path = "./libclide" }
|
||||
libclide-macros = { path = "./libclide-macros" }
|
||||
anyhow = { workspace = true }
|
||||
strum = { workspace = true }
|
||||
|
||||
@@ -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
|
||||
```
|
||||
|
||||
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
|
||||
qmake6 -query QT_VERSION
|
||||
|
||||
2
build.rs
2
build.rs
@@ -28,6 +28,6 @@ fn main() {
|
||||
.qt_module("Svg")
|
||||
.qt_module("Xml")
|
||||
.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();
|
||||
}
|
||||
|
||||
@@ -6,17 +6,24 @@ use proc_macro::TokenStream;
|
||||
use quote::quote;
|
||||
use syn::{ItemStruct, parse_macro_input};
|
||||
|
||||
#[proc_macro_derive(Loggable)]
|
||||
pub fn loggable(item: TokenStream) -> TokenStream {
|
||||
#[proc_macro_attribute]
|
||||
pub fn log_id(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
let input = parse_macro_input!(item as ItemStruct);
|
||||
|
||||
let struct_name = &input.ident;
|
||||
let generics = &input.generics;
|
||||
|
||||
// This is the important part
|
||||
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;
|
||||
#input
|
||||
|
||||
impl #impl_generics #struct_name #type_generics #where_clause {
|
||||
#[allow(unused)]
|
||||
pub const ID: &'static str = #struct_name_str;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
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",
|
||||
]
|
||||
10
libclide/Cargo.toml
Normal file
10
libclide/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "libclide"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
anyhow = { workspace = true }
|
||||
strum = { workspace = true }
|
||||
log = { workspace = true }
|
||||
devicons = { workspace = true }
|
||||
18
libclide/src/fs.rs
Normal file
18
libclide/src/fs.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
|
||||
//
|
||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||
|
||||
pub mod entry_meta;
|
||||
|
||||
use devicons::FileIcon;
|
||||
use std::path::Path;
|
||||
|
||||
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)
|
||||
}
|
||||
@@ -43,7 +43,7 @@ impl EntryMeta {
|
||||
.context(format!("Failed to get file name for path: {abs_path:?}"))?
|
||||
.to_string_lossy()
|
||||
.to_string();
|
||||
let icon = icon(&abs_path);
|
||||
let icon = crate::fs::icon(&abs_path);
|
||||
Ok(EntryMeta {
|
||||
abs_path,
|
||||
file_name,
|
||||
@@ -52,13 +52,3 @@ impl EntryMeta {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
@@ -3,5 +3,5 @@
|
||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||
|
||||
pub mod fs;
|
||||
pub mod logging;
|
||||
pub mod log;
|
||||
pub mod theme;
|
||||
@@ -2,6 +2,4 @@
|
||||
//
|
||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||
|
||||
pub mod entry_meta;
|
||||
|
||||
pub use entry_meta::icon;
|
||||
pub mod macros;
|
||||
119
libclide/src/log/macros.rs
Normal file
119
libclide/src/log/macros.rs
Normal file
@@ -0,0 +1,119 @@
|
||||
// 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 target argument can be overridden using one of the following macros.
|
||||
//! ```
|
||||
//! libclide::log!(target: "CustomTarget", "This log message will have the target 'CustomTarget'");
|
||||
//! ```
|
||||
//!
|
||||
//! The target argument will default to Self::ID if not provided.
|
||||
//! This is an error if Self::ID is not defined, forcing you to use the explicit form.
|
||||
//! ```
|
||||
//! libclide::log!("This log message will use target Self::ID, the name of the struct it was invoked in");
|
||||
//! ```
|
||||
//!
|
||||
//! Self::ID can be defined using the `#[log_id]` attribute macro, which will automatically generate
|
||||
//! a constant ID field with the name of the struct as its value.
|
||||
//! ```
|
||||
//! #[log_id]
|
||||
//! struct MyStruct;
|
||||
//! impl MyStruct {
|
||||
//! fn my_method(&self) {
|
||||
//! libclide::log!("This log message will use target Self::ID, which is 'MyStruct'");
|
||||
//! }
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! info {
|
||||
(logger: $logger:expr, target: $target:expr, $($arg:tt)+) => ({
|
||||
log::info!(logger: $logger, target: $target, $($arg)+)
|
||||
});
|
||||
|
||||
(target: $target:expr, $($arg:tt)+) => ({
|
||||
log::info!(target: $target, $($arg)+)
|
||||
});
|
||||
|
||||
(logger: $logger:expr, $($arg:tt)+) => ({
|
||||
log::info!(logger: $logger, target: Self::ID, $($arg)+)
|
||||
});
|
||||
|
||||
($($arg:tt)+) => (log::info!(target: Self::ID, $($arg)+))
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! debug {
|
||||
(logger: $logger:expr, target: $target:expr, $($arg:tt)+) => ({
|
||||
log::debug!(logger: $logger, target: $target, $($arg)+)
|
||||
});
|
||||
|
||||
(target: $target:expr, $($arg:tt)+) => ({
|
||||
log::debug!(target: $target, $($arg)+)
|
||||
});
|
||||
|
||||
(logger: $logger:expr, $($arg:tt)+) => ({
|
||||
log::debug!(logger: $logger, target: Self::ID, $($arg)+)
|
||||
});
|
||||
|
||||
($($arg:tt)+) => (log::debug!(target: Self::ID, $($arg)+))
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! warn {
|
||||
(logger: $logger:expr, target: $target:expr, $($arg:tt)+) => ({
|
||||
log::warn!(logger: $logger, target: $target, $($arg)+)
|
||||
});
|
||||
|
||||
(target: $target:expr, $($arg:tt)+) => ({
|
||||
log::warn!(target: $target, $($arg)+)
|
||||
});
|
||||
|
||||
(logger: $logger:expr, $($arg:tt)+) => ({
|
||||
log::warn!(logger: $logger, target: Self::ID, $($arg)+)
|
||||
});
|
||||
|
||||
($($arg:tt)+) => (log::warn!(target: Self::ID, $($arg)+))
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! error {
|
||||
(logger: $logger:expr, target: $target:expr, $($arg:tt)+) => ({
|
||||
log::error!(logger: $logger, target: $target, $($arg)+)
|
||||
});
|
||||
|
||||
(target: $target:expr, $($arg:tt)+) => ({
|
||||
log::error!(target: $target, $($arg)+)
|
||||
});
|
||||
|
||||
(logger: $logger:expr, $($arg:tt)+) => ({
|
||||
log::error!(logger: $logger, target: Self::ID, $($arg)+)
|
||||
});
|
||||
|
||||
($($arg:tt)+) => (log::error!(target: Self::ID, $($arg)+))
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! trace {
|
||||
(logger: $logger:expr, target: $target:expr, $($arg:tt)+) => ({
|
||||
log::trace!(logger: $logger, target: $target, $($arg)+)
|
||||
});
|
||||
|
||||
(target: $target:expr, $($arg:tt)+) => ({
|
||||
log::trace!(target: $target, $($arg)+)
|
||||
});
|
||||
|
||||
(logger: $logger:expr, $($arg:tt)+) => ({
|
||||
log::trace!(logger: $logger, target: Self::ID, $($arg)+)
|
||||
});
|
||||
|
||||
($($arg:tt)+) => (log::trace!(target: Self::ID, $($arg)+))
|
||||
}
|
||||
@@ -3,6 +3,8 @@
|
||||
<file alias="kilroy.png">resources/images/kilroy-256.png</file>
|
||||
</qresource>
|
||||
<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>
|
||||
</qresource>
|
||||
</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,15 @@
|
||||
//
|
||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||
|
||||
pub mod colors;
|
||||
pub mod filesystem;
|
||||
pub mod icon_provider;
|
||||
|
||||
use crate::cli::app_context::AppContext;
|
||||
use crate::AppContext;
|
||||
use anyhow::Result;
|
||||
use cxx_qt_lib::{QMapPair, QMapPair_QString_QVariant, QString, QVariant};
|
||||
|
||||
pub mod colors;
|
||||
pub mod filesystem;
|
||||
|
||||
pub fn run(app_context: AppContext) -> Result<()> {
|
||||
clide::trace!(target:"gui::run()", "Starting the GUI editor at {:?}", app_context.path);
|
||||
libclide::trace!(target:"gui::run()", "Starting the GUI editor at {:?}", app_context.path);
|
||||
|
||||
use cxx_qt_lib::{QGuiApplication, QQmlApplicationEngine, QUrl};
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
//
|
||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||
|
||||
use clide::theme::colors::Colors;
|
||||
use cxx_qt_lib::QColor;
|
||||
use libclide::theme::colors::Colors;
|
||||
|
||||
#[cxx_qt::bridge]
|
||||
pub mod qobject {
|
||||
@@ -76,7 +76,7 @@ impl qobject::FileSystem {
|
||||
let meta = fs::metadata(path.to_string())
|
||||
.unwrap_or_else(|_| panic!("Failed to get file metadata {path:?}"));
|
||||
if !meta.is_file() {
|
||||
clide::warn!(target:"FileSystem", "Attempted to open file {path:?} that is not a valid file");
|
||||
libclide::warn!(target:"FileSystem", "Attempted to open file {path:?} that is not a valid file");
|
||||
return QString::default();
|
||||
}
|
||||
let path_str = path.to_string();
|
||||
@@ -141,6 +141,6 @@ impl qobject::FileSystem {
|
||||
}
|
||||
|
||||
fn icon(self: std::pin::Pin<&mut Self>, path: &QString) -> QString {
|
||||
QString::from(clide::fs::icon(path.to_string().as_str()).to_string())
|
||||
QString::from(libclide::fs::icon(path.to_string().as_str()).to_string())
|
||||
}
|
||||
}
|
||||
@@ -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)+))
|
||||
}
|
||||
93
src/main.rs
Normal file
93
src/main.rs
Normal file
@@ -0,0 +1,93 @@
|
||||
// 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 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")?,
|
||||
};
|
||||
libclide::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 => {
|
||||
libclide::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,19 +2,19 @@
|
||||
//
|
||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||
|
||||
pub mod about;
|
||||
pub mod app;
|
||||
pub mod component;
|
||||
pub mod editor;
|
||||
pub mod editor_tab;
|
||||
pub mod explorer;
|
||||
pub mod logger;
|
||||
pub mod menu_bar;
|
||||
mod about;
|
||||
mod app;
|
||||
mod component;
|
||||
mod editor;
|
||||
mod editor_tab;
|
||||
mod explorer;
|
||||
mod logger;
|
||||
mod menu_bar;
|
||||
|
||||
use crate::cli::app_context::AppContext;
|
||||
use ::log::LevelFilter;
|
||||
use crate::AppContext;
|
||||
use anyhow::{Context, Result};
|
||||
use clide::logging::Loggable;
|
||||
use libclide_macros::log_id;
|
||||
use log::LevelFilter;
|
||||
use ratatui::Terminal;
|
||||
use ratatui::backend::CrosstermBackend;
|
||||
use ratatui::crossterm::event::{
|
||||
@@ -29,22 +29,23 @@ use tui_logger::{
|
||||
TuiLoggerFile, TuiLoggerLevelOutput, init_logger, set_default_level, set_log_file,
|
||||
};
|
||||
|
||||
#[derive(Loggable)]
|
||||
#[log_id]
|
||||
struct Tui {
|
||||
terminal: Terminal<CrosstermBackend<Stdout>>,
|
||||
root_path: std::path::PathBuf,
|
||||
}
|
||||
|
||||
pub fn run(app_context: AppContext) -> Result<()> {
|
||||
clide::trace!(target: "clide::tui::run", "Starting TUI");
|
||||
libclide::trace!(target:Tui::ID, "Starting TUI");
|
||||
Tui::new(app_context)?.start()
|
||||
}
|
||||
|
||||
impl Tui {
|
||||
fn new(app_context: AppContext) -> Result<Self> {
|
||||
libclide::trace!("Building {}", Self::ID);
|
||||
init_logger(LevelFilter::Trace)?;
|
||||
set_default_level(LevelFilter::Trace);
|
||||
clide::debug!("Logging initialized");
|
||||
libclide::debug!("Logging initialized");
|
||||
|
||||
let mut dir = env::temp_dir();
|
||||
dir.push("clide.log");
|
||||
@@ -56,7 +57,7 @@ impl Tui {
|
||||
.output_file(false)
|
||||
.output_separator(':');
|
||||
set_log_file(file_options);
|
||||
clide::debug!("Logging to file: {dir:?}");
|
||||
libclide::debug!("Logging to file: {dir:?}");
|
||||
|
||||
Ok(Self {
|
||||
terminal: Terminal::new(CrosstermBackend::new(stdout()))?,
|
||||
@@ -65,7 +66,7 @@ impl Tui {
|
||||
}
|
||||
|
||||
fn start(self) -> Result<()> {
|
||||
clide::info!("Starting the TUI editor at {:?}", self.root_path);
|
||||
libclide::info!("Starting the TUI editor at {:?}", self.root_path);
|
||||
ratatui::crossterm::execute!(
|
||||
stdout(),
|
||||
EnterAlternateScreen,
|
||||
@@ -82,7 +83,7 @@ impl Tui {
|
||||
}
|
||||
|
||||
fn stop() -> Result<()> {
|
||||
clide::info!("Stopping the TUI editor");
|
||||
libclide::info!("Stopping the TUI editor");
|
||||
disable_raw_mode()?;
|
||||
ratatui::crossterm::execute!(
|
||||
stdout(),
|
||||
@@ -2,18 +2,18 @@
|
||||
//
|
||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||
|
||||
use clide::logging::Loggable;
|
||||
use libclide_macros::log_id;
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::layout::{Constraint, Direction, Layout, Rect};
|
||||
use ratatui::text::{Line, Span};
|
||||
use ratatui::widgets::{Block, Borders, Clear, Padding, Paragraph, Widget, Wrap};
|
||||
|
||||
#[derive(Loggable, Default)]
|
||||
#[log_id]
|
||||
pub struct About {}
|
||||
|
||||
impl About {
|
||||
pub fn new() -> Self {
|
||||
// clide::trace!("Building {}", Self::id());
|
||||
// libclide::trace!("Building {}", Self::id());
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,8 @@ use crate::tui::editor_tab::EditorTab;
|
||||
use crate::tui::explorer::Explorer;
|
||||
use crate::tui::logger::Logger;
|
||||
use crate::tui::menu_bar::MenuBar;
|
||||
use clide::logging::Loggable;
|
||||
use anyhow::{Context, Result};
|
||||
use libclide_macros::log_id;
|
||||
use ratatui::DefaultTerminal;
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::crossterm::event;
|
||||
@@ -30,7 +30,7 @@ pub enum AppComponent {
|
||||
MenuBar,
|
||||
}
|
||||
|
||||
#[derive(Loggable)]
|
||||
#[log_id]
|
||||
pub struct App<'a> {
|
||||
editor_tab: EditorTab,
|
||||
explorer: Explorer<'a>,
|
||||
@@ -42,7 +42,7 @@ pub struct App<'a> {
|
||||
|
||||
impl<'a> App<'a> {
|
||||
pub fn new(root_path: PathBuf) -> Result<Self> {
|
||||
clide::trace!("Building");
|
||||
libclide::trace!(target:Self::ID, "Building {}", Self::ID);
|
||||
let app = Self {
|
||||
editor_tab: EditorTab::new(),
|
||||
explorer: Explorer::new(&root_path)?,
|
||||
@@ -56,13 +56,13 @@ impl<'a> App<'a> {
|
||||
|
||||
/// Logic that should be executed once on application startup.
|
||||
pub fn start(&mut self) -> Result<()> {
|
||||
clide::trace!("Starting App");
|
||||
libclide::trace!(target:Self::ID, "Starting App");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn run(mut self, mut terminal: DefaultTerminal) -> Result<()> {
|
||||
self.start()?;
|
||||
clide::trace!("Entering App run loop");
|
||||
libclide::trace!(target:Self::ID, "Entering App run loop");
|
||||
loop {
|
||||
terminal.draw(|f| {
|
||||
f.render_widget(&mut self, f.area());
|
||||
@@ -88,7 +88,7 @@ impl<'a> App<'a> {
|
||||
Some(editor) => editor.component_state.help_text.clone(),
|
||||
None => {
|
||||
if !self.editor_tab.is_empty() {
|
||||
clide::error!("Failed to get Editor while drawing bottom status bar");
|
||||
libclide::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()
|
||||
}
|
||||
@@ -112,26 +112,26 @@ impl<'a> App<'a> {
|
||||
}
|
||||
|
||||
fn clear_focus(&mut self) {
|
||||
clide::info!("Clearing all widget focus");
|
||||
libclide::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.logger.component_state.set_focus(Focus::Inactive);
|
||||
self.menu_bar.component_state.set_focus(Focus::Inactive);
|
||||
match self.editor_tab.current_editor_mut() {
|
||||
None => {
|
||||
clide::error!("Failed to get current Editor while clearing focus")
|
||||
libclide::error!(target:Self::ID, "Failed to get current Editor while clearing focus")
|
||||
}
|
||||
Some(editor) => editor.component_state.set_focus(Focus::Inactive),
|
||||
}
|
||||
}
|
||||
|
||||
fn change_focus(&mut self, focus: AppComponent) {
|
||||
clide::info!("Changing widget focus to {:?}", focus);
|
||||
libclide::info!(target:Self::ID, "Changing widget focus to {:?}", focus);
|
||||
self.clear_focus();
|
||||
match focus {
|
||||
AppComponent::Editor => match self.editor_tab.current_editor_mut() {
|
||||
None => {
|
||||
clide::error!("Failed to get current Editor while changing focus")
|
||||
libclide::error!(target:Self::ID, "Failed to get current Editor while changing focus")
|
||||
}
|
||||
Some(editor) => editor.component_state.set_focus(Focus::Active),
|
||||
},
|
||||
@@ -274,13 +274,13 @@ impl<'a> Component for App<'a> {
|
||||
Action::Quit | Action::Handled => Ok(action),
|
||||
Action::Save => match self.editor_tab.current_editor_mut() {
|
||||
None => {
|
||||
clide::error!("Failed to get current editor while handling App Action::Save");
|
||||
libclide::error!(target:Self::ID, "Failed to get current editor while handling App Action::Save");
|
||||
Ok(Action::Noop)
|
||||
}
|
||||
Some(editor) => match editor.save() {
|
||||
Ok(_) => Ok(Action::Handled),
|
||||
Err(e) => {
|
||||
clide::error!("Failed to save editor contents: {e}");
|
||||
libclide::error!(target:Self::ID, "Failed to save editor contents: {e}");
|
||||
Ok(Action::Noop)
|
||||
}
|
||||
},
|
||||
@@ -299,16 +299,14 @@ impl<'a> Component for App<'a> {
|
||||
Err(_) => Ok(Action::Noop),
|
||||
},
|
||||
Action::ReloadFile => {
|
||||
clide::trace!("Reloading file for current editor");
|
||||
libclide::trace!(target:Self::ID, "Reloading file for current editor");
|
||||
if let Some(editor) = self.editor_tab.current_editor_mut() {
|
||||
editor
|
||||
.reload_contents()
|
||||
.map(|_| Action::Handled)
|
||||
.context("Failed to handle Action::ReloadFile")
|
||||
} else {
|
||||
clide::error!(
|
||||
"Failed to get current editor while handling App Action::ReloadFile"
|
||||
);
|
||||
libclide::error!(target:Self::ID, "Failed to get current editor while handling App Action::ReloadFile");
|
||||
Ok(Action::Noop)
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,10 @@
|
||||
#![allow(dead_code, unused_variables)]
|
||||
|
||||
use crate::tui::component::Focus::Inactive;
|
||||
use clide::logging::Loggable;
|
||||
use clide::theme::colors::Colors;
|
||||
use Focus::Active;
|
||||
use anyhow::Result;
|
||||
use libclide::theme::colors::Colors;
|
||||
use libclide_macros::log_id;
|
||||
use ratatui::crossterm::event::{Event, KeyEvent, MouseEvent};
|
||||
use ratatui::style::Color;
|
||||
|
||||
@@ -62,7 +62,8 @@ pub trait Component {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Loggable)]
|
||||
#[derive(Debug, Clone, Default)]
|
||||
#[log_id]
|
||||
pub struct ComponentState {
|
||||
pub(crate) focus: Focus,
|
||||
pub(crate) vis: Visibility,
|
||||
@@ -75,7 +76,7 @@ impl ComponentState {
|
||||
}
|
||||
|
||||
fn new() -> Self {
|
||||
clide::trace!(target:Self::id(), "Building {}", Self::id());
|
||||
libclide::trace!(target:Self::id(), "Building {}", Self::id());
|
||||
Self {
|
||||
focus: Active,
|
||||
vis: Visibility::Visible,
|
||||
@@ -3,11 +3,11 @@
|
||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||
|
||||
use crate::tui::component::{Action, Component, ComponentState, Focus, FocusState};
|
||||
use clide::logging::Loggable;
|
||||
use anyhow::{Context, Result, bail};
|
||||
use edtui::{
|
||||
EditorEventHandler, EditorState, EditorTheme, EditorView, LineNumbers, Lines, SyntaxHighlighter,
|
||||
};
|
||||
use libclide_macros::log_id;
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
|
||||
use ratatui::layout::{Alignment, Rect};
|
||||
@@ -16,18 +16,18 @@ use ratatui::widgets::{Block, Borders, Padding, Widget};
|
||||
use std::path::PathBuf;
|
||||
use syntect::parsing::SyntaxSet;
|
||||
|
||||
#[derive(Loggable)]
|
||||
#[log_id]
|
||||
pub struct Editor {
|
||||
pub state: EditorState,
|
||||
pub event_handler: EditorEventHandler,
|
||||
pub file_path: Option<PathBuf>,
|
||||
pub file_path: Option<std::path::PathBuf>,
|
||||
syntax_set: SyntaxSet,
|
||||
pub(crate) component_state: ComponentState,
|
||||
}
|
||||
|
||||
impl Editor {
|
||||
pub fn new(path: &std::path::Path) -> Self {
|
||||
clide::trace!("Building {}", <Self as Loggable>::ID);
|
||||
libclide::trace!(target:Self::ID, "Building {}", Self::ID);
|
||||
Editor {
|
||||
state: EditorState::default(),
|
||||
event_handler: EditorEventHandler::default(),
|
||||
@@ -41,10 +41,10 @@ impl Editor {
|
||||
}
|
||||
|
||||
pub fn reload_contents(&mut self) -> Result<()> {
|
||||
clide::trace!("Reloading editor file contents {:?}", self.file_path);
|
||||
libclide::trace!(target:Self::ID, "Reloading editor file contents {:?}", self.file_path);
|
||||
match self.file_path.clone() {
|
||||
None => {
|
||||
clide::error!("Failed to reload editor contents with None file_path");
|
||||
libclide::error!(target:Self::ID, "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),
|
||||
@@ -52,7 +52,7 @@ impl Editor {
|
||||
}
|
||||
|
||||
pub fn set_contents(&mut self, path: &std::path::Path) -> Result<()> {
|
||||
clide::trace!("Setting Editor contents from path {:?}", path);
|
||||
libclide::trace!(target:Self::ID, "Setting Editor contents from path {:?}", path);
|
||||
if let Ok(contents) = std::fs::read_to_string(path) {
|
||||
let lines: Vec<_> = contents
|
||||
.lines()
|
||||
@@ -68,10 +68,10 @@ impl Editor {
|
||||
|
||||
pub fn save(&self) -> Result<()> {
|
||||
if let Some(path) = &self.file_path {
|
||||
clide::trace!("Saving Editor contents {:?}", path);
|
||||
libclide::trace!(target:Self::ID, "Saving Editor contents {:?}", path);
|
||||
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");
|
||||
libclide::error!(target:Self::ID, "Failed saving Editor contents; file_path was None");
|
||||
bail!("File not saved. No file path set.")
|
||||
}
|
||||
}
|
||||
@@ -2,21 +2,21 @@
|
||||
//
|
||||
// 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 clide::logging::Loggable;
|
||||
use anyhow::{Context, Result, anyhow};
|
||||
use libclide_macros::log_id;
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
|
||||
use ratatui::layout::Rect;
|
||||
use ratatui::prelude::{Color, Style};
|
||||
use ratatui::widgets::{Block, Borders, Padding, Tabs, Widget};
|
||||
use std::collections::HashMap;
|
||||
use crate::tui::component::{Action, Component, Focus, FocusState};
|
||||
|
||||
// Render the tabs with keys as titles
|
||||
// Tab keys can be file names.
|
||||
// Render the editor using the key as a reference for lookup
|
||||
#[derive(Loggable, Default)]
|
||||
#[log_id]
|
||||
pub struct EditorTab {
|
||||
pub(crate) editors: HashMap<String, Editor>,
|
||||
tab_order: Vec<String>,
|
||||
@@ -25,7 +25,7 @@ pub struct EditorTab {
|
||||
|
||||
impl EditorTab {
|
||||
pub fn new() -> Self {
|
||||
clide::trace!("Building {}", <Self as Loggable>::ID);
|
||||
libclide::trace!(target:Self::ID, "Building {}", Self::ID);
|
||||
Self {
|
||||
editors: HashMap::new(),
|
||||
tab_order: Vec::new(),
|
||||
@@ -35,11 +35,7 @@ impl EditorTab {
|
||||
|
||||
pub fn next_editor(&mut self) {
|
||||
let next = (self.current_editor + 1) % self.tab_order.len();
|
||||
clide::trace!(
|
||||
"Moving from {} to next editor tab at {}",
|
||||
self.current_editor,
|
||||
next
|
||||
);
|
||||
libclide::trace!(target:Self::ID, "Moving from {} to next editor tab at {}", self.current_editor, next);
|
||||
self.set_tab_focus(Focus::Active, next);
|
||||
self.current_editor = next;
|
||||
}
|
||||
@@ -49,11 +45,7 @@ impl EditorTab {
|
||||
.current_editor
|
||||
.checked_sub(1)
|
||||
.unwrap_or(self.tab_order.len() - 1);
|
||||
clide::trace!(
|
||||
"Moving from {} to previous editor tab at {}",
|
||||
self.current_editor,
|
||||
prev
|
||||
);
|
||||
libclide::trace!(target:Self::ID, "Moving from {} to previous editor tab at {}", self.current_editor, prev);
|
||||
self.set_tab_focus(Focus::Active, prev);
|
||||
self.current_editor = prev;
|
||||
}
|
||||
@@ -62,7 +54,7 @@ impl EditorTab {
|
||||
match self.tab_order.get(index) {
|
||||
None => {
|
||||
if !self.tab_order.is_empty() {
|
||||
clide::error!("Failed to get editor tab key with invalid index {index}");
|
||||
libclide::error!(target:Self::ID, "Failed to get editor tab key with invalid index {index}");
|
||||
}
|
||||
None
|
||||
}
|
||||
@@ -80,19 +72,16 @@ impl EditorTab {
|
||||
}
|
||||
|
||||
pub fn set_current_tab_focus(&mut self, focus: Focus) {
|
||||
clide::trace!(
|
||||
"Setting current tab {} focus to {:?}",
|
||||
self.current_editor,
|
||||
focus
|
||||
);
|
||||
libclide::trace!(target:Self::ID, "Setting current tab {} focus to {:?}", self.current_editor, focus);
|
||||
self.set_tab_focus(focus, self.current_editor)
|
||||
}
|
||||
|
||||
pub fn set_tab_focus(&mut self, focus: Focus, index: usize) {
|
||||
clide::trace!("Setting tab {} focus to {:?}", index, focus);
|
||||
libclide::trace!(target:Self::ID, "Setting tab {} focus to {:?}", index, focus);
|
||||
if focus == Focus::Active && index != self.current_editor {
|
||||
// If we are setting another tab to active, disable the current one.
|
||||
clide::trace!(
|
||||
libclide::trace!(
|
||||
target:Self::ID,
|
||||
"New tab {} focus set to Active; Setting current tab {} to Inactive",
|
||||
index,
|
||||
self.current_editor
|
||||
@@ -101,11 +90,12 @@ impl EditorTab {
|
||||
}
|
||||
match self.get_editor_key(index) {
|
||||
None => {
|
||||
clide::error!("Failed setting tab focus for invalid key {index}");
|
||||
libclide::error!(target:Self::ID, "Failed setting tab focus for invalid key {index}");
|
||||
}
|
||||
Some(key) => match self.editors.get_mut(&key) {
|
||||
None => {
|
||||
clide::error!(
|
||||
libclide::error!(
|
||||
target:Self::ID,
|
||||
"Failed to update tab focus at index {} with invalid key: {}",
|
||||
self.current_editor,
|
||||
self.tab_order[self.current_editor]
|
||||
@@ -117,12 +107,12 @@ impl EditorTab {
|
||||
}
|
||||
|
||||
pub fn open_tab(&mut self, path: &std::path::Path) -> Result<()> {
|
||||
clide::trace!("Opening new EditorTab with path {:?}", path);
|
||||
libclide::trace!(target:Self::ID, "Opening new EditorTab with path {:?}", path);
|
||||
if self
|
||||
.editors
|
||||
.contains_key(&path.to_string_lossy().to_string())
|
||||
{
|
||||
clide::warn!("EditorTab already opened with this file");
|
||||
libclide::warn!(target:Self::ID, "EditorTab already opened with this file");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -147,12 +137,12 @@ impl EditorTab {
|
||||
.to_owned();
|
||||
match self.editors.remove(&key) {
|
||||
None => {
|
||||
clide::error!("Failed to remove editor tab {key} with invalid index {index}")
|
||||
libclide::error!(target:Self::ID, "Failed to remove editor tab {key} with invalid index {index}")
|
||||
}
|
||||
Some(_) => {
|
||||
self.prev_editor();
|
||||
self.tab_order.remove(index);
|
||||
clide::info!("Closed editor tab {key} at index {index}")
|
||||
libclide::info!(target:Self::ID, "Closed editor tab {key} at index {index}")
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
use crate::tui::component::{Action, Component, ComponentState, Focus, FocusState};
|
||||
use anyhow::{Context, Result, bail};
|
||||
use clide::fs::entry_meta::EntryMeta;
|
||||
use clide::logging::Loggable;
|
||||
use libclide::fs::entry_meta::EntryMeta;
|
||||
use libclide_macros::log_id;
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, MouseEvent, MouseEventKind};
|
||||
use ratatui::layout::{Alignment, Position, Rect};
|
||||
@@ -16,7 +16,8 @@ use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use tui_tree_widget::{Tree, TreeItem, TreeState};
|
||||
|
||||
#[derive(Debug, Loggable)]
|
||||
#[derive(Debug)]
|
||||
#[log_id]
|
||||
pub struct Explorer<'a> {
|
||||
root_path: EntryMeta,
|
||||
tree_items: TreeItem<'a, String>,
|
||||
@@ -26,7 +27,7 @@ pub struct Explorer<'a> {
|
||||
|
||||
impl<'a> Explorer<'a> {
|
||||
pub fn new(path: &PathBuf) -> Result<Self> {
|
||||
clide::trace!("Building {}", <Self as Loggable>::ID);
|
||||
libclide::trace!("Building {}", Self::ID);
|
||||
let explorer = Explorer {
|
||||
root_path: EntryMeta::new(path)?,
|
||||
tree_items: Self::build_tree_from_path(path)?,
|
||||
@@ -62,19 +63,17 @@ impl<'a> Explorer<'a> {
|
||||
} else {
|
||||
children.push(TreeItem::new_leaf(
|
||||
entry_meta.abs_path.clone(),
|
||||
format!("{}", entry_meta.file_name.as_str()),
|
||||
// format!("{} {}", entry_meta.icon.icon, entry_meta.file_name.as_str()),
|
||||
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.
|
||||
TreeItem::new(
|
||||
path_meta.abs_path.clone(),
|
||||
format!("{}", path_meta.file_name.as_str()),
|
||||
// format!("{} {}", path_meta.icon.icon, path_meta.file_name.as_str()),
|
||||
format!("{} {}", path_meta.icon.icon, path_meta.file_name.as_str()),
|
||||
children,
|
||||
)
|
||||
.context(format!(
|
||||
@@ -3,7 +3,7 @@
|
||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||
|
||||
use crate::tui::component::{Action, Component, ComponentState, Focus, FocusState};
|
||||
use clide::logging::Loggable;
|
||||
use libclide_macros::log_id;
|
||||
use log::LevelFilter;
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent};
|
||||
@@ -12,9 +12,9 @@ use ratatui::style::{Color, Style};
|
||||
use ratatui::widgets::Widget;
|
||||
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().
|
||||
#[derive(Loggable, Default)]
|
||||
#[log_id]
|
||||
pub struct Logger {
|
||||
state: TuiWidgetState,
|
||||
pub(crate) component_state: ComponentState,
|
||||
@@ -22,7 +22,7 @@ pub struct Logger {
|
||||
|
||||
impl Logger {
|
||||
pub fn new() -> Self {
|
||||
clide::trace!("Building {}", <Self as Loggable>::ID);
|
||||
libclide::trace!(target:Self::ID, "Building {}", Self::ID);
|
||||
let state = TuiWidgetState::new();
|
||||
state.transition(TuiWidgetEvent::HideKey);
|
||||
Self {
|
||||
@@ -6,8 +6,8 @@ use crate::tui::component::{Action, Component, ComponentState, FocusState};
|
||||
use crate::tui::menu_bar::MenuBarItemOption::{
|
||||
About, CloseTab, Exit, Reload, Save, ShowHideExplorer, ShowHideLogger,
|
||||
};
|
||||
use clide::logging::Loggable;
|
||||
use anyhow::Context;
|
||||
use libclide_macros::log_id;
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::crossterm::event::{KeyCode, KeyEvent};
|
||||
use ratatui::layout::Rect;
|
||||
@@ -18,9 +18,8 @@ use ratatui::widgets::{
|
||||
};
|
||||
use strum::{EnumIter, FromRepr, IntoEnumIterator};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromRepr, EnumIter, Default)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromRepr, EnumIter)]
|
||||
enum MenuBarItem {
|
||||
#[default]
|
||||
File,
|
||||
View,
|
||||
Help,
|
||||
@@ -81,7 +80,7 @@ impl MenuBarItem {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Loggable, Default)]
|
||||
#[log_id]
|
||||
pub struct MenuBar {
|
||||
selected: MenuBarItem,
|
||||
opened: Option<MenuBarItem>,
|
||||
@@ -92,7 +91,7 @@ pub struct MenuBar {
|
||||
impl MenuBar {
|
||||
const DEFAULT_HELP: &str = "(←/h)/(→/l): Select option | Enter: Choose selection";
|
||||
pub fn new() -> Self {
|
||||
clide::trace!("Building");
|
||||
libclide::trace!("Building {}", Self::ID);
|
||||
Self {
|
||||
selected: MenuBarItem::File,
|
||||
opened: None,
|
||||
Reference in New Issue
Block a user