1 Commits

Author SHA1 Message Date
3450d6db9b WIP 2026-02-21 21:10:12 -05:00
21 changed files with 88 additions and 257 deletions

View File

@@ -26,9 +26,6 @@ jobs:
- name: Build libclide
run: |
cargo b -p libclide --release
- name: Build libclide-macros
run: |
cargo b -p libclide-macros --release
- name: Build clide
run: |
cargo b --release
@@ -47,9 +44,6 @@ jobs:
- name: Test libclide
run: |
cargo test -p libclide
- name: Test libclide-macros
run: |
cargo test -p libclide-macros
- name: Test clide
run: |
cargo test
@@ -68,9 +62,6 @@ jobs:
- name: Lint libclide
run: |
cargo clippy -p libclide -- -D warnings
- name: Lint libclide-macros
run: |
cargo clippy -p libclide-macros -- -D warnings
- name: Lint clide
run: |
cargo clippy -- -D warnings
@@ -89,9 +80,6 @@ jobs:
- 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

11
Cargo.lock generated
View File

@@ -299,7 +299,6 @@ dependencies = [
"dirs",
"edtui",
"libclide",
"libclide-macros",
"log",
"ratatui",
"strum",
@@ -1170,19 +1169,9 @@ name = "libclide"
version = "0.1.0"
dependencies = [
"anyhow",
"log",
"strum",
]
[[package]]
name = "libclide-macros"
version = "0.1.0"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.117",
]
[[package]]
name = "libredox"
version = "0.1.12"

View File

@@ -5,17 +5,20 @@ edition = "2024"
[workspace]
resolver = "3"
members = [".", "libclide", "libclide-macros", ]
members = [
".",
"libclide",
]
[workspace.dependencies]
anyhow = "1.0.100"
strum = "0.27.2"
log = { version = "0.4.27", features = [] }
[dependencies]
cxx = "1.0.95"
cxx-qt = "0.8.0"
cxx-qt-lib = { version = "0.8.0", features = ["qt_full", "qt_gui", "qt_qml"] }
log = { version = "0.4.27", features = [] }
dirs = "6.0.0"
syntect = "5.2.0"
clap = { version = "4.5.54", features = ["derive"] }
@@ -25,11 +28,9 @@ tui-logger = "0.18.1"
edtui = "0.11.1"
devicons = "0.6.12"
libclide = { path = "./libclide" }
libclide-macros = { path = "./libclide-macros" }
anyhow = { workspace = true }
strum = { workspace = true }
log = { workspace = true }
[build-dependencies]
# 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"] }

View File

@@ -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"

View File

@@ -1,27 +0,0 @@
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)
}

View File

@@ -6,4 +6,3 @@ edition = "2024"
[dependencies]
anyhow = { workspace = true }
strum = { workspace = true }
log = { workspace = true }

View File

@@ -3,5 +3,4 @@
// SPDX-License-Identifier: GNU General Public License v3.0 or later
pub mod fs;
pub mod log;
pub mod theme;

View File

@@ -1,5 +0,0 @@
// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
//
// SPDX-License-Identifier: GNU General Public License v3.0 or later
pub mod macros;

View File

@@ -1,106 +0,0 @@
//! 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)+))
}

View File

@@ -2,8 +2,8 @@
//
// 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";
@@ -14,7 +14,7 @@ impl Colors {
pub const SCROLLBAR_ACTIVE: &str = "#4b4f51";
pub const SCROLLBAR_GUTTER: &str = "#3b3b3b";
pub const LINENUMBER: &str = "#94989b";
pub const ACTIVE: &str = "#d1d33f";
pub const ACTIVE: &str = "#a9acb0";
pub const INACTIVE: &str = "#FFF";
pub const EDITOR_BACKGROUND: &str = "#1E1F22";
pub const EDITOR_TEXT: &str = "#acaea3";
@@ -34,21 +34,19 @@ impl Colors {
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 {
pub fn css_to_u32(css: &str) -> Result<u32, String> {
let hex = css.trim_start_matches('#');
// Expand shorthand #RGB to #RRGGBB
let hex_full = match hex.len() {
3 => hex
.chars()
.map(|c| std::iter::repeat_n(c, 2).collect::<String>())
3 => hex.chars()
.map(|c| std::iter::repeat(c).take(2).collect::<String>())
.collect::<String>(),
6 => hex.to_string(),
_ => panic!("Invalid hex color length: {hex:?}"),
_ => return Err(format!("Invalid hex color length: {}", hex)),
};
// Parse the hex string as u32, masking to ensure the top (alpha) byte is 0x00.
// Parse the hex string as u32, masking to ensure the top byte is 0x00.
u32::from_str_radix(&hex_full, 16)
.map(|rgb| rgb & 0x00FF_FFFF)
.unwrap_or_else(|e| panic!("Failed to parse hex: {e:?}"))
.map_err(|e| format!("Failed to parse hex: {}", e))
}
}

View File

@@ -5,12 +5,13 @@
use crate::AppContext;
use anyhow::Result;
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<()> {
libclide::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};

View File

@@ -5,6 +5,7 @@
use cxx_qt_lib::{QModelIndex, QString};
use devicons::FileIcon;
use dirs;
use log::warn;
use std::fs;
use std::path::Path;
use syntect::easy::HighlightLines;
@@ -77,7 +78,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() {
libclide::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();
}
let path_str = path.to_string();

View File

@@ -13,8 +13,7 @@ mod menu_bar;
use crate::AppContext;
use anyhow::{Context, Result};
use libclide_macros::log_id;
use log::LevelFilter;
use log::{LevelFilter, debug, info, trace};
use ratatui::Terminal;
use ratatui::backend::CrosstermBackend;
use ratatui::crossterm::event::{
@@ -29,23 +28,24 @@ use tui_logger::{
TuiLoggerFile, TuiLoggerLevelOutput, init_logger, set_default_level, set_log_file,
};
#[log_id]
struct Tui {
terminal: Terminal<CrosstermBackend<Stdout>>,
root_path: std::path::PathBuf,
}
pub fn run(app_context: AppContext) -> Result<()> {
libclide::trace!(target:Tui::ID, "Starting TUI");
trace!(target:Tui::ID, "Starting TUI");
Tui::new(app_context)?.start()
}
impl Tui {
pub const ID: &str = "Tui";
fn new(app_context: AppContext) -> Result<Self> {
libclide::trace!("Building {}", Self::ID);
trace!(target:Self::ID, "Building {}", Self::ID);
init_logger(LevelFilter::Trace)?;
set_default_level(LevelFilter::Trace);
libclide::debug!("Logging initialized");
debug!(target:Self::ID, "Logging initialized");
let mut dir = env::temp_dir();
dir.push("clide.log");
@@ -57,7 +57,7 @@ impl Tui {
.output_file(false)
.output_separator(':');
set_log_file(file_options);
libclide::debug!("Logging to file: {dir:?}");
debug!(target:Self::ID, "Logging to file: {dir:?}");
Ok(Self {
terminal: Terminal::new(CrosstermBackend::new(stdout()))?,
@@ -66,7 +66,7 @@ impl Tui {
}
fn start(self) -> Result<()> {
libclide::info!("Starting the TUI editor at {:?}", self.root_path);
info!(target:Self::ID, "Starting the TUI editor at {:?}", self.root_path);
ratatui::crossterm::execute!(
stdout(),
EnterAlternateScreen,
@@ -83,7 +83,7 @@ impl Tui {
}
fn stop() -> Result<()> {
libclide::info!("Stopping the TUI editor");
info!(target:Self::ID, "Stopping the TUI editor");
disable_raw_mode()?;
ratatui::crossterm::execute!(
stdout(),

View File

@@ -2,18 +2,19 @@
//
// SPDX-License-Identifier: GNU General Public License v3.0 or later
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};
#[log_id]
pub struct About {}
impl About {
#[allow(unused)]
pub const ID: &str = "About";
pub fn new() -> Self {
// libclide::trace!("Building {}", Self::id());
// trace!(target:Self::id(), "Building {}", Self::id());
Self {}
}
}

View File

@@ -9,7 +9,7 @@ use crate::tui::explorer::Explorer;
use crate::tui::logger::Logger;
use crate::tui::menu_bar::MenuBar;
use anyhow::{Context, Result};
use libclide_macros::log_id;
use log::{error, info, trace};
use ratatui::DefaultTerminal;
use ratatui::buffer::Buffer;
use ratatui::crossterm::event;
@@ -30,7 +30,6 @@ pub enum AppComponent {
MenuBar,
}
#[log_id]
pub struct App<'a> {
editor_tab: EditorTab,
explorer: Explorer<'a>,
@@ -41,8 +40,10 @@ pub struct App<'a> {
}
impl<'a> App<'a> {
pub const ID: &'static str = "App";
pub fn new(root_path: PathBuf) -> Result<Self> {
libclide::trace!(target:Self::ID, "Building {}", Self::ID);
trace!(target:Self::ID, "Building {}", Self::ID);
let app = Self {
editor_tab: EditorTab::new(),
explorer: Explorer::new(&root_path)?,
@@ -56,13 +57,13 @@ impl<'a> App<'a> {
/// Logic that should be executed once on application startup.
pub fn start(&mut self) -> Result<()> {
libclide::trace!(target:Self::ID, "Starting App");
trace!(target:Self::ID, "Starting App");
Ok(())
}
pub fn run(mut self, mut terminal: DefaultTerminal) -> Result<()> {
self.start()?;
libclide::trace!(target:Self::ID, "Entering App run loop");
trace!(target:Self::ID, "Entering App run loop");
loop {
terminal.draw(|f| {
f.render_widget(&mut self, f.area());
@@ -88,7 +89,7 @@ impl<'a> App<'a> {
Some(editor) => editor.component_state.help_text.clone(),
None => {
if !self.editor_tab.is_empty() {
libclide::error!(target:Self::ID, "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()
}
@@ -112,26 +113,26 @@ impl<'a> App<'a> {
}
fn clear_focus(&mut self) {
libclide::info!(target:Self::ID, "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.logger.component_state.set_focus(Focus::Inactive);
self.menu_bar.component_state.set_focus(Focus::Inactive);
match self.editor_tab.current_editor_mut() {
None => {
libclide::error!(target:Self::ID, "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),
}
}
fn change_focus(&mut self, focus: AppComponent) {
libclide::info!(target:Self::ID, "Changing widget focus to {:?}", focus);
info!(target:Self::ID, "Changing widget focus to {:?}", focus);
self.clear_focus();
match focus {
AppComponent::Editor => match self.editor_tab.current_editor_mut() {
None => {
libclide::error!(target:Self::ID, "Failed to get current Editor while changing focus")
error!(target:Self::ID, "Failed to get current Editor while changing focus")
}
Some(editor) => editor.component_state.set_focus(Focus::Active),
},
@@ -274,13 +275,13 @@ impl<'a> Component for App<'a> {
Action::Quit | Action::Handled => Ok(action),
Action::Save => match self.editor_tab.current_editor_mut() {
None => {
libclide::error!(target:Self::ID, "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)
}
Some(editor) => match editor.save() {
Ok(_) => Ok(Action::Handled),
Err(e) => {
libclide::error!(target:Self::ID, "Failed to save editor contents: {e}");
error!(target:Self::ID, "Failed to save editor contents: {e}");
Ok(Action::Noop)
}
},
@@ -299,14 +300,14 @@ impl<'a> Component for App<'a> {
Err(_) => Ok(Action::Noop),
},
Action::ReloadFile => {
libclide::trace!(target:Self::ID, "Reloading file for current editor");
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 {
libclide::error!(target:Self::ID, "Failed to get current editor while handling App Action::ReloadFile");
error!(target:Self::ID, "Failed to get current editor while handling App Action::ReloadFile");
Ok(Action::Noop)
}
}

View File

@@ -8,7 +8,7 @@ use crate::tui::component::Focus::Inactive;
use Focus::Active;
use anyhow::Result;
use libclide::theme::colors::Colors;
use libclide_macros::log_id;
use log::trace;
use ratatui::crossterm::event::{Event, KeyEvent, MouseEvent};
use ratatui::style::Color;
@@ -63,7 +63,6 @@ pub trait Component {
}
#[derive(Debug, Clone, Default)]
#[log_id]
pub struct ComponentState {
pub(crate) focus: Focus,
pub(crate) vis: Visibility,
@@ -76,7 +75,7 @@ impl ComponentState {
}
fn new() -> Self {
libclide::trace!(target:Self::id(), "Building {}", Self::id());
trace!(target:Self::id(), "Building {}", Self::id());
Self {
focus: Active,
vis: Visibility::Visible,
@@ -100,8 +99,8 @@ pub enum Focus {
impl Focus {
pub(crate) fn get_active_color(&self) -> Color {
match self {
Active => Color::from_u32(Colors::css_to_u32(Colors::ACTIVE)),
Inactive => Color::from_u32(Colors::css_to_u32(Colors::INACTIVE)),
Active => Color::from_u32(Colors::css_to_u32(Colors::ACTIVE)?),
Inactive => Color::from_u32(Colors::css_to_u32(Colors::INACTIVE)?),
}
}
}

View File

@@ -7,7 +7,7 @@ use anyhow::{Context, Result, bail};
use edtui::{
EditorEventHandler, EditorState, EditorTheme, EditorView, LineNumbers, Lines, SyntaxHighlighter,
};
use libclide_macros::log_id;
use log::{error, trace};
use ratatui::buffer::Buffer;
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
use ratatui::layout::{Alignment, Rect};
@@ -16,7 +16,6 @@ use ratatui::widgets::{Block, Borders, Padding, Widget};
use std::path::PathBuf;
use syntect::parsing::SyntaxSet;
#[log_id]
pub struct Editor {
pub state: EditorState,
pub event_handler: EditorEventHandler,
@@ -26,8 +25,10 @@ pub struct Editor {
}
impl Editor {
pub const ID: &str = "Editor";
pub fn new(path: &std::path::Path) -> Self {
libclide::trace!(target:Self::ID, "Building {}", Self::ID);
trace!(target:Self::ID, "Building {}", Self::ID);
Editor {
state: EditorState::default(),
event_handler: EditorEventHandler::default(),
@@ -41,10 +42,10 @@ impl Editor {
}
pub fn reload_contents(&mut self) -> Result<()> {
libclide::trace!(target:Self::ID, "Reloading editor file contents {:?}", self.file_path);
trace!(target:Self::ID, "Reloading editor file contents {:?}", self.file_path);
match self.file_path.clone() {
None => {
libclide::error!(target:Self::ID, "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")
}
Some(path) => self.set_contents(&path),
@@ -52,7 +53,7 @@ impl Editor {
}
pub fn set_contents(&mut self, path: &std::path::Path) -> Result<()> {
libclide::trace!(target:Self::ID, "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) {
let lines: Vec<_> = contents
.lines()
@@ -68,10 +69,10 @@ impl Editor {
pub fn save(&self) -> Result<()> {
if let Some(path) = &self.file_path {
libclide::trace!(target:Self::ID, "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());
};
libclide::error!(target:Self::ID, "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.")
}
}

View File

@@ -5,7 +5,7 @@
use crate::tui::component::{Action, Component, Focus, FocusState};
use crate::tui::editor::Editor;
use anyhow::{Context, Result, anyhow};
use libclide_macros::log_id;
use log::{error, info, trace, warn};
use ratatui::buffer::Buffer;
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
use ratatui::layout::Rect;
@@ -16,7 +16,6 @@ use std::collections::HashMap;
// Render the tabs with keys as titles
// Tab keys can be file names.
// Render the editor using the key as a reference for lookup
#[log_id]
pub struct EditorTab {
pub(crate) editors: HashMap<String, Editor>,
tab_order: Vec<String>,
@@ -24,8 +23,10 @@ pub struct EditorTab {
}
impl EditorTab {
pub const ID: &str = "EditorTab";
pub fn new() -> Self {
libclide::trace!(target:Self::ID, "Building {}", Self::ID);
trace!(target:Self::ID, "Building {}", Self::ID);
Self {
editors: HashMap::new(),
tab_order: Vec::new(),
@@ -35,7 +36,7 @@ impl EditorTab {
pub fn next_editor(&mut self) {
let next = (self.current_editor + 1) % self.tab_order.len();
libclide::trace!(target:Self::ID, "Moving from {} to next editor tab at {}", self.current_editor, next);
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;
}
@@ -45,7 +46,7 @@ impl EditorTab {
.current_editor
.checked_sub(1)
.unwrap_or(self.tab_order.len() - 1);
libclide::trace!(target:Self::ID, "Moving from {} to previous editor tab at {}", self.current_editor, prev);
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;
}
@@ -54,7 +55,7 @@ impl EditorTab {
match self.tab_order.get(index) {
None => {
if !self.tab_order.is_empty() {
libclide::error!(target:Self::ID, "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
}
@@ -72,15 +73,15 @@ impl EditorTab {
}
pub fn set_current_tab_focus(&mut self, focus: Focus) {
libclide::trace!(target:Self::ID, "Setting current tab {} focus to {:?}", self.current_editor, focus);
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) {
libclide::trace!(target:Self::ID, "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 we are setting another tab to active, disable the current one.
libclide::trace!(
trace!(
target:Self::ID,
"New tab {} focus set to Active; Setting current tab {} to Inactive",
index,
@@ -90,11 +91,11 @@ impl EditorTab {
}
match self.get_editor_key(index) {
None => {
libclide::error!(target:Self::ID, "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) {
None => {
libclide::error!(
error!(
target:Self::ID,
"Failed to update tab focus at index {} with invalid key: {}",
self.current_editor,
@@ -107,12 +108,12 @@ impl EditorTab {
}
pub fn open_tab(&mut self, path: &std::path::Path) -> Result<()> {
libclide::trace!(target:Self::ID, "Opening new EditorTab with path {:?}", path);
trace!(target:Self::ID, "Opening new EditorTab with path {:?}", path);
if self
.editors
.contains_key(&path.to_string_lossy().to_string())
{
libclide::warn!(target:Self::ID, "EditorTab already opened with this file");
warn!(target:Self::ID, "EditorTab already opened with this file");
return Ok(());
}
@@ -137,12 +138,12 @@ impl EditorTab {
.to_owned();
match self.editors.remove(&key) {
None => {
libclide::error!(target:Self::ID, "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(_) => {
self.prev_editor();
self.tab_order.remove(index);
libclide::info!(target:Self::ID, "Closed editor tab {key} at index {index}")
info!(target:Self::ID, "Closed editor tab {key} at index {index}")
}
}
Ok(())

View File

@@ -5,7 +5,7 @@
use crate::tui::component::{Action, Component, ComponentState, Focus, FocusState};
use anyhow::{Context, Result, bail};
use libclide::fs::entry_meta::EntryMeta;
use libclide_macros::log_id;
use log::trace;
use ratatui::buffer::Buffer;
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, MouseEvent, MouseEventKind};
use ratatui::layout::{Alignment, Position, Rect};
@@ -17,7 +17,6 @@ use std::path::{Path, PathBuf};
use tui_tree_widget::{Tree, TreeItem, TreeState};
#[derive(Debug)]
#[log_id]
pub struct Explorer<'a> {
root_path: EntryMeta,
tree_items: TreeItem<'a, String>,
@@ -26,8 +25,10 @@ pub struct Explorer<'a> {
}
impl<'a> Explorer<'a> {
pub const ID: &'static str = "Explorer";
pub fn new(path: &PathBuf) -> Result<Self> {
libclide::trace!("Building {}", Self::ID);
trace!(target:Self::ID, "Building {}", Self::ID);
let explorer = Explorer {
root_path: EntryMeta::new(path)?,
tree_items: Self::build_tree_from_path(path)?,

View File

@@ -3,8 +3,7 @@
// SPDX-License-Identifier: GNU General Public License v3.0 or later
use crate::tui::component::{Action, Component, ComponentState, Focus, FocusState};
use libclide_macros::log_id;
use log::LevelFilter;
use log::{LevelFilter, trace};
use ratatui::buffer::Buffer;
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent};
use ratatui::layout::Rect;
@@ -14,15 +13,16 @@ use tui_logger::{TuiLoggerLevelOutput, TuiLoggerSmartWidget, TuiWidgetEvent, Tui
/// 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().
#[log_id]
pub struct Logger {
state: TuiWidgetState,
pub(crate) component_state: ComponentState,
}
impl Logger {
pub const ID: &str = "Logger";
pub fn new() -> Self {
libclide::trace!(target:Self::ID, "Building {}", Self::ID);
trace!(target:Self::ID, "Building {}", Self::ID);
let state = TuiWidgetState::new();
state.transition(TuiWidgetEvent::HideKey);
Self {

View File

@@ -7,7 +7,7 @@ use crate::tui::menu_bar::MenuBarItemOption::{
About, CloseTab, Exit, Reload, Save, ShowHideExplorer, ShowHideLogger,
};
use anyhow::Context;
use libclide_macros::log_id;
use log::trace;
use ratatui::buffer::Buffer;
use ratatui::crossterm::event::{KeyCode, KeyEvent};
use ratatui::layout::Rect;
@@ -80,7 +80,6 @@ impl MenuBarItem {
}
}
#[log_id]
pub struct MenuBar {
selected: MenuBarItem,
opened: Option<MenuBarItem>,
@@ -89,9 +88,11 @@ pub struct MenuBar {
}
impl MenuBar {
pub const ID: &str = "MenuBar";
const DEFAULT_HELP: &str = "(←/h)/(→/l): Select option | Enter: Choose selection";
pub fn new() -> Self {
libclide::trace!("Building {}", Self::ID);
trace!(target:Self::ID, "Building {}", Self::ID);
Self {
selected: MenuBarItem::File,
opened: None,
@@ -156,7 +157,7 @@ impl MenuBar {
height,
}
// 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);
}
}