Add macros for logging.
This commit is contained in:
12
.github/workflows/check.yaml
vendored
12
.github/workflows/check.yaml
vendored
@@ -26,6 +26,9 @@ 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
|
||||||
@@ -44,6 +47,9 @@ 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
|
||||||
@@ -62,6 +68,9 @@ jobs:
|
|||||||
- name: Lint libclide
|
- name: Lint libclide
|
||||||
run: |
|
run: |
|
||||||
cargo clippy -p libclide -- -D warnings
|
cargo clippy -p libclide -- -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
|
||||||
@@ -80,6 +89,9 @@ jobs:
|
|||||||
- name: Format libclide
|
- name: Format libclide
|
||||||
run: |
|
run: |
|
||||||
cargo fmt -p libclide --verbose -- --check
|
cargo fmt -p libclide --verbose -- --check
|
||||||
|
- name: Format libclide-macros
|
||||||
|
run: |
|
||||||
|
cargo fmt -p libclide-macros -- --check
|
||||||
- name: Format clide
|
- name: Format clide
|
||||||
run: |
|
run: |
|
||||||
cargo fmt --verbose -- --check
|
cargo fmt --verbose -- --check
|
||||||
|
|||||||
11
Cargo.lock
generated
11
Cargo.lock
generated
@@ -299,6 +299,7 @@ dependencies = [
|
|||||||
"dirs",
|
"dirs",
|
||||||
"edtui",
|
"edtui",
|
||||||
"libclide",
|
"libclide",
|
||||||
|
"libclide-macros",
|
||||||
"log",
|
"log",
|
||||||
"ratatui",
|
"ratatui",
|
||||||
"strum",
|
"strum",
|
||||||
@@ -1169,9 +1170,19 @@ name = "libclide"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"log",
|
||||||
"strum",
|
"strum",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libclide-macros"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.117",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libredox"
|
name = "libredox"
|
||||||
version = "0.1.12"
|
version = "0.1.12"
|
||||||
|
|||||||
11
Cargo.toml
11
Cargo.toml
@@ -5,20 +5,17 @@ edition = "2024"
|
|||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
resolver = "3"
|
resolver = "3"
|
||||||
members = [
|
members = [".", "libclide", "libclide-macros", ]
|
||||||
".",
|
|
||||||
"libclide",
|
|
||||||
]
|
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
anyhow = "1.0.100"
|
anyhow = "1.0.100"
|
||||||
strum = "0.27.2"
|
strum = "0.27.2"
|
||||||
|
log = { version = "0.4.27", features = [] }
|
||||||
|
|
||||||
[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"] }
|
||||||
@@ -28,9 +25,11 @@ tui-logger = "0.18.1"
|
|||||||
edtui = "0.11.1"
|
edtui = "0.11.1"
|
||||||
devicons = "0.6.12"
|
devicons = "0.6.12"
|
||||||
libclide = { path = "./libclide" }
|
libclide = { path = "./libclide" }
|
||||||
|
libclide-macros = { path = "./libclide-macros" }
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
strum = { workspace = true }
|
strum = { workspace = true }
|
||||||
|
log = { 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.
|
||||||
cxx-qt-build = { version = "0.8.0", features = ["link_qt_object_files"] }
|
cxx-qt-build = { version = "0.8.0", features = ["link_qt_object_files"] }
|
||||||
|
|||||||
12
libclide-macros/Cargo.toml
Normal file
12
libclide-macros/Cargo.toml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[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"
|
||||||
27
libclide-macros/src/lib.rs
Normal file
27
libclide-macros/src/lib.rs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
use proc_macro::TokenStream;
|
||||||
|
use quote::quote;
|
||||||
|
use syn::{ItemStruct, parse_macro_input};
|
||||||
|
|
||||||
|
#[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! {
|
||||||
|
#input
|
||||||
|
|
||||||
|
impl #impl_generics #struct_name #type_generics #where_clause {
|
||||||
|
#[allow(unused)]
|
||||||
|
pub const ID: &'static str = #struct_name_str;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TokenStream::from(expanded)
|
||||||
|
}
|
||||||
@@ -6,3 +6,4 @@ edition = "2024"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
strum = { workspace = true }
|
strum = { workspace = true }
|
||||||
|
log = { workspace = true }
|
||||||
|
|||||||
@@ -3,4 +3,5 @@
|
|||||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||||
|
|
||||||
pub mod fs;
|
pub mod fs;
|
||||||
|
pub mod log;
|
||||||
pub mod theme;
|
pub mod theme;
|
||||||
|
|||||||
5
libclide/src/log.rs
Normal file
5
libclide/src/log.rs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||||
|
|
||||||
|
pub mod macros;
|
||||||
106
libclide/src/log/macros.rs
Normal file
106
libclide/src/log/macros.rs
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
//! 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.
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! info {
|
||||||
|
// The target argument can be overridden using one of the following macros.
|
||||||
|
(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)+)
|
||||||
|
});
|
||||||
|
|
||||||
|
// The target argument will default to Self::ID if not provided.
|
||||||
|
// Obviously, this is an error if Self::ID is not defined, forcing you to use the explicit form.
|
||||||
|
(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 {
|
||||||
|
// The target argument can be overridden using one of the following macros.
|
||||||
|
(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)+)
|
||||||
|
});
|
||||||
|
|
||||||
|
// The target argument will default to Self::ID if not provided.
|
||||||
|
// Obviously, this is an error if Self::ID is not defined, forcing you to use the explicit form.
|
||||||
|
(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 {
|
||||||
|
// The target argument can be overridden using one of the following macros.
|
||||||
|
(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)+)
|
||||||
|
});
|
||||||
|
|
||||||
|
// The target argument will default to Self::ID if not provided.
|
||||||
|
// Obviously, this is an error if Self::ID is not defined, forcing you to use the explicit form.
|
||||||
|
(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 {
|
||||||
|
// The target argument can be overridden using one of the following macros.
|
||||||
|
(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)+)
|
||||||
|
});
|
||||||
|
|
||||||
|
// The target argument will default to Self::ID if not provided.
|
||||||
|
// Obviously, this is an error if Self::ID is not defined, forcing you to use the explicit form.
|
||||||
|
(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 {
|
||||||
|
// The target argument can be overridden using one of the following macros.
|
||||||
|
(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)+)
|
||||||
|
});
|
||||||
|
|
||||||
|
// The target argument will default to Self::ID if not provided.
|
||||||
|
// Obviously, this is an error if Self::ID is not defined, forcing you to use the explicit form.
|
||||||
|
(logger: $logger:expr, $($arg:tt)+) => ({
|
||||||
|
log::trace!(logger: $logger, target: Self::ID, $($arg)+)
|
||||||
|
});
|
||||||
|
|
||||||
|
($($arg:tt)+) => (log::trace!(target: Self::ID, $($arg)+))
|
||||||
|
}
|
||||||
@@ -41,7 +41,7 @@ impl Colors {
|
|||||||
let hex_full = match hex.len() {
|
let hex_full = match hex.len() {
|
||||||
3 => hex
|
3 => hex
|
||||||
.chars()
|
.chars()
|
||||||
.map(|c| std::iter::repeat(c).take(2).collect::<String>())
|
.map(|c| std::iter::repeat_n(c, 2).collect::<String>())
|
||||||
.collect::<String>(),
|
.collect::<String>(),
|
||||||
6 => hex.to_string(),
|
6 => hex.to_string(),
|
||||||
_ => panic!("Invalid hex color length: {hex:?}"),
|
_ => panic!("Invalid hex color length: {hex:?}"),
|
||||||
|
|||||||
@@ -5,13 +5,12 @@
|
|||||||
use crate::AppContext;
|
use crate::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 colors;
|
||||||
pub mod filesystem;
|
pub mod filesystem;
|
||||||
|
|
||||||
pub fn run(app_context: AppContext) -> Result<()> {
|
pub fn run(app_context: AppContext) -> Result<()> {
|
||||||
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};
|
use cxx_qt_lib::{QGuiApplication, QQmlApplicationEngine, QUrl};
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
use cxx_qt_lib::{QModelIndex, QString};
|
use cxx_qt_lib::{QModelIndex, QString};
|
||||||
use devicons::FileIcon;
|
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;
|
||||||
@@ -78,7 +77,7 @@ impl qobject::FileSystem {
|
|||||||
let meta = fs::metadata(path.to_string())
|
let meta = fs::metadata(path.to_string())
|
||||||
.unwrap_or_else(|_| panic!("Failed to get file metadata {path:?}"));
|
.unwrap_or_else(|_| panic!("Failed to get file metadata {path:?}"));
|
||||||
if !meta.is_file() {
|
if !meta.is_file() {
|
||||||
warn!(target:"FileSystem", "Attempted to open file {path:?} that is not a valid file");
|
libclide::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();
|
||||||
|
|||||||
18
src/tui.rs
18
src/tui.rs
@@ -13,7 +13,8 @@ mod menu_bar;
|
|||||||
|
|
||||||
use crate::AppContext;
|
use crate::AppContext;
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use log::{LevelFilter, debug, info, trace};
|
use libclide_macros::log_id;
|
||||||
|
use log::LevelFilter;
|
||||||
use ratatui::Terminal;
|
use ratatui::Terminal;
|
||||||
use ratatui::backend::CrosstermBackend;
|
use ratatui::backend::CrosstermBackend;
|
||||||
use ratatui::crossterm::event::{
|
use ratatui::crossterm::event::{
|
||||||
@@ -28,24 +29,23 @@ use tui_logger::{
|
|||||||
TuiLoggerFile, TuiLoggerLevelOutput, init_logger, set_default_level, set_log_file,
|
TuiLoggerFile, TuiLoggerLevelOutput, init_logger, set_default_level, set_log_file,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[log_id]
|
||||||
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<()> {
|
||||||
trace!(target:Tui::ID, "Starting TUI");
|
libclide::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);
|
libclide::trace!("Building {}", Self::ID);
|
||||||
init_logger(LevelFilter::Trace)?;
|
init_logger(LevelFilter::Trace)?;
|
||||||
set_default_level(LevelFilter::Trace);
|
set_default_level(LevelFilter::Trace);
|
||||||
debug!(target:Self::ID, "Logging initialized");
|
libclide::debug!("Logging initialized");
|
||||||
|
|
||||||
let mut dir = env::temp_dir();
|
let mut dir = env::temp_dir();
|
||||||
dir.push("clide.log");
|
dir.push("clide.log");
|
||||||
@@ -57,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);
|
||||||
debug!(target:Self::ID, "Logging to file: {dir:?}");
|
libclide::debug!("Logging to file: {dir:?}");
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
terminal: Terminal::new(CrosstermBackend::new(stdout()))?,
|
terminal: Terminal::new(CrosstermBackend::new(stdout()))?,
|
||||||
@@ -66,7 +66,7 @@ impl Tui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn start(self) -> Result<()> {
|
fn start(self) -> Result<()> {
|
||||||
info!(target:Self::ID, "Starting the TUI editor at {:?}", self.root_path);
|
libclide::info!("Starting the TUI editor at {:?}", self.root_path);
|
||||||
ratatui::crossterm::execute!(
|
ratatui::crossterm::execute!(
|
||||||
stdout(),
|
stdout(),
|
||||||
EnterAlternateScreen,
|
EnterAlternateScreen,
|
||||||
@@ -83,7 +83,7 @@ impl Tui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn stop() -> Result<()> {
|
fn stop() -> Result<()> {
|
||||||
info!(target:Self::ID, "Stopping the TUI editor");
|
libclide::info!("Stopping the TUI editor");
|
||||||
disable_raw_mode()?;
|
disable_raw_mode()?;
|
||||||
ratatui::crossterm::execute!(
|
ratatui::crossterm::execute!(
|
||||||
stdout(),
|
stdout(),
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
use libclide_macros::log_id;
|
||||||
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};
|
||||||
|
|
||||||
|
#[log_id]
|
||||||
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 {
|
||||||
// trace!(target:Self::id(), "Building {}", Self::id());
|
// libclide::trace!("Building {}", Self::id());
|
||||||
Self {}
|
Self {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ 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 anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use log::{error, info, trace};
|
use libclide_macros::log_id;
|
||||||
use ratatui::DefaultTerminal;
|
use ratatui::DefaultTerminal;
|
||||||
use ratatui::buffer::Buffer;
|
use ratatui::buffer::Buffer;
|
||||||
use ratatui::crossterm::event;
|
use ratatui::crossterm::event;
|
||||||
@@ -30,6 +30,7 @@ pub enum AppComponent {
|
|||||||
MenuBar,
|
MenuBar,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[log_id]
|
||||||
pub struct App<'a> {
|
pub struct App<'a> {
|
||||||
editor_tab: EditorTab,
|
editor_tab: EditorTab,
|
||||||
explorer: Explorer<'a>,
|
explorer: Explorer<'a>,
|
||||||
@@ -40,10 +41,8 @@ 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> {
|
||||||
trace!(target:Self::ID, "Building {}", Self::ID);
|
libclide::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)?,
|
||||||
@@ -57,13 +56,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<()> {
|
||||||
trace!(target:Self::ID, "Starting App");
|
libclide::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()?;
|
||||||
trace!(target:Self::ID, "Entering App run loop");
|
libclide::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());
|
||||||
@@ -89,7 +88,7 @@ impl<'a> App<'a> {
|
|||||||
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() {
|
||||||
error!(target:Self::ID, "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()
|
"Failed to get current Editor while getting widget help text".to_string()
|
||||||
}
|
}
|
||||||
@@ -113,26 +112,26 @@ impl<'a> App<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn clear_focus(&mut self) {
|
fn clear_focus(&mut self) {
|
||||||
info!(target:Self::ID, "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.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 => {
|
||||||
error!(target:Self::ID, "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),
|
Some(editor) => editor.component_state.set_focus(Focus::Inactive),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn change_focus(&mut self, focus: AppComponent) {
|
fn change_focus(&mut self, focus: AppComponent) {
|
||||||
info!(target:Self::ID, "Changing widget focus to {:?}", focus);
|
libclide::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() {
|
AppComponent::Editor => match self.editor_tab.current_editor_mut() {
|
||||||
None => {
|
None => {
|
||||||
error!(target:Self::ID, "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),
|
Some(editor) => editor.component_state.set_focus(Focus::Active),
|
||||||
},
|
},
|
||||||
@@ -275,13 +274,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 => {
|
||||||
error!(target:Self::ID, "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)
|
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) => {
|
||||||
error!(target:Self::ID, "Failed to save editor contents: {e}");
|
libclide::error!(target:Self::ID, "Failed to save editor contents: {e}");
|
||||||
Ok(Action::Noop)
|
Ok(Action::Noop)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -300,14 +299,14 @@ impl<'a> Component for App<'a> {
|
|||||||
Err(_) => Ok(Action::Noop),
|
Err(_) => Ok(Action::Noop),
|
||||||
},
|
},
|
||||||
Action::ReloadFile => {
|
Action::ReloadFile => {
|
||||||
trace!(target:Self::ID, "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() {
|
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 {
|
||||||
error!(target:Self::ID, "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)
|
Ok(Action::Noop)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use crate::tui::component::Focus::Inactive;
|
|||||||
use Focus::Active;
|
use Focus::Active;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use libclide::theme::colors::Colors;
|
use libclide::theme::colors::Colors;
|
||||||
use log::trace;
|
use libclide_macros::log_id;
|
||||||
use ratatui::crossterm::event::{Event, KeyEvent, MouseEvent};
|
use ratatui::crossterm::event::{Event, KeyEvent, MouseEvent};
|
||||||
use ratatui::style::Color;
|
use ratatui::style::Color;
|
||||||
|
|
||||||
@@ -63,6 +63,7 @@ pub trait Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
|
#[log_id]
|
||||||
pub struct ComponentState {
|
pub struct ComponentState {
|
||||||
pub(crate) focus: Focus,
|
pub(crate) focus: Focus,
|
||||||
pub(crate) vis: Visibility,
|
pub(crate) vis: Visibility,
|
||||||
@@ -75,7 +76,7 @@ impl ComponentState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
trace!(target:Self::id(), "Building {}", Self::id());
|
libclide::trace!(target:Self::id(), "Building {}", Self::id());
|
||||||
Self {
|
Self {
|
||||||
focus: Active,
|
focus: Active,
|
||||||
vis: Visibility::Visible,
|
vis: Visibility::Visible,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ 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 libclide_macros::log_id;
|
||||||
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,6 +16,7 @@ use ratatui::widgets::{Block, Borders, Padding, Widget};
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use syntect::parsing::SyntaxSet;
|
use syntect::parsing::SyntaxSet;
|
||||||
|
|
||||||
|
#[log_id]
|
||||||
pub struct Editor {
|
pub struct Editor {
|
||||||
pub state: EditorState,
|
pub state: EditorState,
|
||||||
pub event_handler: EditorEventHandler,
|
pub event_handler: EditorEventHandler,
|
||||||
@@ -25,10 +26,8 @@ pub struct Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
trace!(target:Self::ID, "Building {}", Self::ID);
|
libclide::trace!(target:Self::ID, "Building {}", Self::ID);
|
||||||
Editor {
|
Editor {
|
||||||
state: EditorState::default(),
|
state: EditorState::default(),
|
||||||
event_handler: EditorEventHandler::default(),
|
event_handler: EditorEventHandler::default(),
|
||||||
@@ -42,10 +41,10 @@ impl Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn reload_contents(&mut self) -> Result<()> {
|
pub fn reload_contents(&mut self) -> Result<()> {
|
||||||
trace!(target:Self::ID, "Reloading editor file contents {:?}", self.file_path);
|
libclide::trace!(target:Self::ID, "Reloading editor file contents {:?}", self.file_path);
|
||||||
match self.file_path.clone() {
|
match self.file_path.clone() {
|
||||||
None => {
|
None => {
|
||||||
error!(target:Self::ID, "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")
|
bail!("Failed to reload editor contents with None file_path")
|
||||||
}
|
}
|
||||||
Some(path) => self.set_contents(&path),
|
Some(path) => self.set_contents(&path),
|
||||||
@@ -53,7 +52,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<()> {
|
||||||
trace!(target:Self::ID, "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) {
|
if let Ok(contents) = std::fs::read_to_string(path) {
|
||||||
let lines: Vec<_> = contents
|
let lines: Vec<_> = contents
|
||||||
.lines()
|
.lines()
|
||||||
@@ -69,10 +68,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 {
|
||||||
trace!(target:Self::ID, "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());
|
return std::fs::write(path, self.state.lines.to_string()).map_err(|e| e.into());
|
||||||
};
|
};
|
||||||
error!(target:Self::ID, "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.")
|
bail!("File not saved. No file path set.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
use crate::tui::component::{Action, Component, Focus, FocusState};
|
use crate::tui::component::{Action, Component, Focus, FocusState};
|
||||||
use crate::tui::editor::Editor;
|
use crate::tui::editor::Editor;
|
||||||
use anyhow::{Context, Result, anyhow};
|
use anyhow::{Context, Result, anyhow};
|
||||||
use log::{error, info, trace, warn};
|
use libclide_macros::log_id;
|
||||||
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;
|
||||||
@@ -16,6 +16,7 @@ use std::collections::HashMap;
|
|||||||
// 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
|
||||||
|
#[log_id]
|
||||||
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>,
|
||||||
@@ -23,10 +24,8 @@ pub struct EditorTab {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl EditorTab {
|
impl EditorTab {
|
||||||
pub const ID: &str = "EditorTab";
|
|
||||||
|
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
trace!(target:Self::ID, "Building {}", Self::ID);
|
libclide::trace!(target:Self::ID, "Building {}", Self::ID);
|
||||||
Self {
|
Self {
|
||||||
editors: HashMap::new(),
|
editors: HashMap::new(),
|
||||||
tab_order: Vec::new(),
|
tab_order: Vec::new(),
|
||||||
@@ -36,7 +35,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();
|
||||||
trace!(target:Self::ID, "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.set_tab_focus(Focus::Active, next);
|
||||||
self.current_editor = next;
|
self.current_editor = next;
|
||||||
}
|
}
|
||||||
@@ -46,7 +45,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);
|
||||||
trace!(target:Self::ID, "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.set_tab_focus(Focus::Active, prev);
|
||||||
self.current_editor = prev;
|
self.current_editor = prev;
|
||||||
}
|
}
|
||||||
@@ -55,7 +54,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() {
|
||||||
error!(target:Self::ID, "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
|
None
|
||||||
}
|
}
|
||||||
@@ -73,15 +72,15 @@ impl EditorTab {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_current_tab_focus(&mut self, focus: Focus) {
|
pub fn set_current_tab_focus(&mut self, focus: Focus) {
|
||||||
trace!(target:Self::ID, "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)
|
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) {
|
||||||
trace!(target:Self::ID, "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 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.
|
||||||
trace!(
|
libclide::trace!(
|
||||||
target:Self::ID,
|
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,
|
||||||
@@ -91,11 +90,11 @@ impl EditorTab {
|
|||||||
}
|
}
|
||||||
match self.get_editor_key(index) {
|
match self.get_editor_key(index) {
|
||||||
None => {
|
None => {
|
||||||
error!(target:Self::ID, "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) {
|
Some(key) => match self.editors.get_mut(&key) {
|
||||||
None => {
|
None => {
|
||||||
error!(
|
libclide::error!(
|
||||||
target:Self::ID,
|
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,
|
||||||
@@ -108,12 +107,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<()> {
|
||||||
trace!(target:Self::ID, "Opening new EditorTab with path {:?}", path);
|
libclide::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())
|
||||||
{
|
{
|
||||||
warn!(target:Self::ID, "EditorTab already opened with this file");
|
libclide::warn!(target:Self::ID, "EditorTab already opened with this file");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,12 +137,12 @@ impl EditorTab {
|
|||||||
.to_owned();
|
.to_owned();
|
||||||
match self.editors.remove(&key) {
|
match self.editors.remove(&key) {
|
||||||
None => {
|
None => {
|
||||||
error!(target:Self::ID, "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(_) => {
|
Some(_) => {
|
||||||
self.prev_editor();
|
self.prev_editor();
|
||||||
self.tab_order.remove(index);
|
self.tab_order.remove(index);
|
||||||
info!(target:Self::ID, "Closed editor tab {key} at index {index}")
|
libclide::info!(target:Self::ID, "Closed editor tab {key} at index {index}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
use crate::tui::component::{Action, Component, ComponentState, Focus, FocusState};
|
use crate::tui::component::{Action, Component, ComponentState, Focus, FocusState};
|
||||||
use anyhow::{Context, Result, bail};
|
use anyhow::{Context, Result, bail};
|
||||||
use libclide::fs::entry_meta::EntryMeta;
|
use libclide::fs::entry_meta::EntryMeta;
|
||||||
use log::trace;
|
use libclide_macros::log_id;
|
||||||
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};
|
||||||
@@ -17,6 +17,7 @@ use std::path::{Path, PathBuf};
|
|||||||
use tui_tree_widget::{Tree, TreeItem, TreeState};
|
use tui_tree_widget::{Tree, TreeItem, TreeState};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[log_id]
|
||||||
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,10 +26,8 @@ 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> {
|
||||||
trace!(target:Self::ID, "Building {}", Self::ID);
|
libclide::trace!("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)?,
|
||||||
|
|||||||
@@ -3,7 +3,8 @@
|
|||||||
// 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 log::{LevelFilter, trace};
|
use libclide_macros::log_id;
|
||||||
|
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;
|
||||||
@@ -13,16 +14,15 @@ use tui_logger::{TuiLoggerLevelOutput, TuiLoggerSmartWidget, TuiWidgetEvent, Tui
|
|||||||
|
|
||||||
/// Any log 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().
|
||||||
|
#[log_id]
|
||||||
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 {
|
||||||
trace!(target:Self::ID, "Building {}", Self::ID);
|
libclide::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 {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use crate::tui::menu_bar::MenuBarItemOption::{
|
|||||||
About, CloseTab, Exit, Reload, Save, ShowHideExplorer, ShowHideLogger,
|
About, CloseTab, Exit, Reload, Save, ShowHideExplorer, ShowHideLogger,
|
||||||
};
|
};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use log::trace;
|
use libclide_macros::log_id;
|
||||||
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;
|
||||||
@@ -80,6 +80,7 @@ impl MenuBarItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[log_id]
|
||||||
pub struct MenuBar {
|
pub struct MenuBar {
|
||||||
selected: MenuBarItem,
|
selected: MenuBarItem,
|
||||||
opened: Option<MenuBarItem>,
|
opened: Option<MenuBarItem>,
|
||||||
@@ -88,11 +89,9 @@ 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 {
|
||||||
trace!(target:Self::ID, "Building {}", Self::ID);
|
libclide::trace!("Building {}", Self::ID);
|
||||||
Self {
|
Self {
|
||||||
selected: MenuBarItem::File,
|
selected: MenuBarItem::File,
|
||||||
opened: None,
|
opened: None,
|
||||||
@@ -157,7 +156,7 @@ impl MenuBar {
|
|||||||
height,
|
height,
|
||||||
}
|
}
|
||||||
// TODO: X offset for item option? It's fine as-is, but it might look nicer.
|
// TODO: X offset for item option? It's fine as-is, but it might look nicer.
|
||||||
// trace!(target:Self::ID, "Building Rect under MenuBar popup {}", rect);
|
// trace!("Building Rect under MenuBar popup {}", rect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user