Add bin directory.

This commit is contained in:
2026-02-28 14:38:42 -05:00
parent 1c3e3753d7
commit ed31ba7600
20 changed files with 86 additions and 90 deletions

View File

@@ -5,7 +5,7 @@ edition = "2024"
[[bin]]
name = "clide"
path = "src/main.rs"
path = "src/bin/clide/main.rs"
[workspace]
resolver = "3"

View File

@@ -28,6 +28,6 @@ fn main() {
.qt_module("Svg")
.qt_module("Xml")
.qrc("./resources.qrc")
.files(["src/ide/gui/colors.rs", "src/ide/gui/filesystem.rs"])
.files(["src/bin/clide/gui/colors.rs", "src/bin/clide/gui/filesystem.rs"])
.build();
}

View File

@@ -15,7 +15,7 @@ pub fn loggable(item: TokenStream) -> TokenStream {
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 crate::logging::Loggable for #struct_name #type_generics #where_clause {
impl #impl_generics clide::logging::Loggable for #struct_name #type_generics #where_clause {
const ID: &'static str = #struct_name_str;
}
};

View File

@@ -4,7 +4,7 @@
pub mod app_context;
use crate::ide::cli::app_context::RunMode;
use crate::cli::app_context::RunMode;
use anyhow::{Result, anyhow};
use clap::Parser;

View File

@@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: GNU General Public License v3.0 or later
use crate::ide::cli::Cli;
use crate::cli::Cli;
use anyhow::{Context, Result};
pub struct AppContext {
@@ -18,7 +18,7 @@ impl AppContext {
// If no path was provided, use the current directory.
None => std::env::current_dir().context("Failed to obtain current directory")?,
};
crate::info!(target:"main()", "Root path detected: {path:?}");
clide::info!(target:"main()", "Root path detected: {path:?}");
Ok(Self {
path,

View File

@@ -6,12 +6,12 @@ pub mod colors;
pub mod filesystem;
pub mod icon_provider;
use crate::ide::cli::app_context::AppContext;
use crate::cli::app_context::AppContext;
use anyhow::Result;
use cxx_qt_lib::{QMapPair, QMapPair_QString_QVariant, QString, QVariant};
pub fn run(app_context: AppContext) -> Result<()> {
crate::trace!(target:"gui::run()", "Starting the GUI editor at {:?}", app_context.path);
clide::trace!(target:"gui::run()", "Starting the GUI editor at {:?}", app_context.path);
use cxx_qt_lib::{QGuiApplication, QQmlApplicationEngine, QUrl};

View File

@@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: GNU General Public License v3.0 or later
use crate::theme::colors::Colors;
use clide::theme::colors::Colors;
use cxx_qt_lib::QColor;
#[cxx_qt::bridge]

View File

@@ -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() {
crate::warn!(target:"FileSystem", "Attempted to open file {path:?} that is not a valid file");
clide::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(crate::fs::icon(path.to_string().as_str()).to_string())
QString::from(clide::fs::icon(path.to_string().as_str()).to_string())
}
}

View File

@@ -2,18 +2,22 @@
//
// 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 clide::ide::cli::Cli;
use clide::ide::cli::app_context::{AppContext, RunMode};
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 => clide::ide::gui::run(app_context),
RunMode::Tui => clide::ide::tui::run(app_context),
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()?)

View File

@@ -11,10 +11,10 @@ pub mod explorer;
pub mod logger;
pub mod menu_bar;
use crate::ide::cli::app_context::AppContext;
use crate::logging::Loggable;
use crate::cli::app_context::AppContext;
use ::log::LevelFilter;
use anyhow::{Context, Result};
use clide::logging::Loggable;
use ratatui::Terminal;
use ratatui::backend::CrosstermBackend;
use ratatui::crossterm::event::{
@@ -36,7 +36,7 @@ struct Tui {
}
pub fn run(app_context: AppContext) -> Result<()> {
crate::trace!(target: "clide::tui::run", "Starting TUI");
clide::trace!(target: "clide::tui::run", "Starting TUI");
Tui::new(app_context)?.start()
}
@@ -44,7 +44,7 @@ impl Tui {
fn new(app_context: AppContext) -> Result<Self> {
init_logger(LevelFilter::Trace)?;
set_default_level(LevelFilter::Trace);
crate::debug!("Logging initialized");
clide::debug!("Logging initialized");
let mut dir = env::temp_dir();
dir.push("clide.log");
@@ -56,7 +56,7 @@ impl Tui {
.output_file(false)
.output_separator(':');
set_log_file(file_options);
crate::debug!("Logging to file: {dir:?}");
clide::debug!("Logging to file: {dir:?}");
Ok(Self {
terminal: Terminal::new(CrosstermBackend::new(stdout()))?,
@@ -65,7 +65,7 @@ impl Tui {
}
fn start(self) -> Result<()> {
crate::info!("Starting the TUI editor at {:?}", self.root_path);
clide::info!("Starting the TUI editor at {:?}", self.root_path);
ratatui::crossterm::execute!(
stdout(),
EnterAlternateScreen,
@@ -82,7 +82,7 @@ impl Tui {
}
fn stop() -> Result<()> {
crate::info!("Stopping the TUI editor");
clide::info!("Stopping the TUI editor");
disable_raw_mode()?;
ratatui::crossterm::execute!(
stdout(),

View File

@@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: GNU General Public License v3.0 or later
use crate::logging::Loggable;
use clide::logging::Loggable;
use ratatui::buffer::Buffer;
use ratatui::layout::{Constraint, Direction, Layout, Rect};
use ratatui::text::{Line, Span};
@@ -13,7 +13,7 @@ pub struct About {}
impl About {
pub fn new() -> Self {
// crate::trace!("Building {}", Self::id());
// clide::trace!("Building {}", Self::id());
Self {}
}
}

View File

@@ -2,13 +2,13 @@
//
// SPDX-License-Identifier: GNU General Public License v3.0 or later
use crate::ide::tui::about::About;
use crate::ide::tui::component::{Action, Component, Focus, FocusState, Visibility, VisibleState};
use crate::ide::tui::editor_tab::EditorTab;
use crate::ide::tui::explorer::Explorer;
use crate::ide::tui::logger::Logger;
use crate::ide::tui::menu_bar::MenuBar;
use crate::logging::Loggable;
use crate::tui::about::About;
use crate::tui::component::{Action, Component, Focus, FocusState, Visibility, VisibleState};
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 ratatui::DefaultTerminal;
use ratatui::buffer::Buffer;
@@ -42,7 +42,7 @@ pub struct App<'a> {
impl<'a> App<'a> {
pub fn new(root_path: PathBuf) -> Result<Self> {
crate::trace!("Building {}", Self::ID);
clide::trace!("Building");
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<()> {
crate::trace!("Starting App");
clide::trace!("Starting App");
Ok(())
}
pub fn run(mut self, mut terminal: DefaultTerminal) -> Result<()> {
self.start()?;
crate::trace!("Entering App run loop");
clide::trace!("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() {
crate::error!("Failed to get Editor while drawing bottom status bar");
clide::error!("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) {
crate::info!("Clearing all widget focus");
clide::info!("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 => {
crate::error!("Failed to get current Editor while clearing focus")
clide::error!("Failed to get current Editor while clearing focus")
}
Some(editor) => editor.component_state.set_focus(Focus::Inactive),
}
}
fn change_focus(&mut self, focus: AppComponent) {
crate::info!("Changing widget focus to {:?}", focus);
clide::info!("Changing widget focus to {:?}", focus);
self.clear_focus();
match focus {
AppComponent::Editor => match self.editor_tab.current_editor_mut() {
None => {
crate::error!("Failed to get current Editor while changing focus")
clide::error!("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 => {
crate::error!("Failed to get current editor while handling App Action::Save");
clide::error!("Failed to get current editor while handling App Action::Save");
Ok(Action::Noop)
}
Some(editor) => match editor.save() {
Ok(_) => Ok(Action::Handled),
Err(e) => {
crate::error!("Failed to save editor contents: {e}");
clide::error!("Failed to save editor contents: {e}");
Ok(Action::Noop)
}
},
@@ -299,14 +299,14 @@ impl<'a> Component for App<'a> {
Err(_) => Ok(Action::Noop),
},
Action::ReloadFile => {
crate::trace!("Reloading file for current editor");
clide::trace!("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 {
crate::error!(
clide::error!(
"Failed to get current editor while handling App Action::ReloadFile"
);
Ok(Action::Noop)

View File

@@ -4,9 +4,9 @@
#![allow(dead_code, unused_variables)]
use crate::ide::tui::component::Focus::Inactive;
use crate::logging::Loggable;
use crate::theme::colors::Colors;
use crate::tui::component::Focus::Inactive;
use clide::logging::Loggable;
use clide::theme::colors::Colors;
use Focus::Active;
use anyhow::Result;
use ratatui::crossterm::event::{Event, KeyEvent, MouseEvent};
@@ -75,7 +75,7 @@ impl ComponentState {
}
fn new() -> Self {
crate::trace!(target:Self::id(), "Building {}", Self::id());
clide::trace!(target:Self::id(), "Building {}", Self::id());
Self {
focus: Active,
vis: Visibility::Visible,

View File

@@ -2,8 +2,8 @@
//
// SPDX-License-Identifier: GNU General Public License v3.0 or later
use crate::ide::tui::component::{Action, Component, ComponentState, Focus, FocusState};
use crate::logging::Loggable;
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,
@@ -27,7 +27,7 @@ pub struct Editor {
impl Editor {
pub fn new(path: &std::path::Path) -> Self {
crate::trace!("Building {}", <Self as Loggable>::ID);
clide::trace!("Building {}", <Self as Loggable>::ID);
Editor {
state: EditorState::default(),
event_handler: EditorEventHandler::default(),
@@ -41,10 +41,10 @@ impl Editor {
}
pub fn reload_contents(&mut self) -> Result<()> {
crate::trace!("Reloading editor file contents {:?}", self.file_path);
clide::trace!("Reloading editor file contents {:?}", self.file_path);
match self.file_path.clone() {
None => {
crate::error!("Failed to reload editor contents with None file_path");
clide::error!("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<()> {
crate::trace!("Setting Editor contents from path {:?}", path);
clide::trace!("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 {
crate::trace!("Saving Editor contents {:?}", path);
clide::trace!("Saving Editor contents {:?}", path);
return std::fs::write(path, self.state.lines.to_string()).map_err(|e| e.into());
};
crate::error!("Failed saving Editor contents; file_path was None");
clide::error!("Failed saving Editor contents; file_path was None");
bail!("File not saved. No file path set.")
}
}

View File

@@ -2,9 +2,8 @@
//
// SPDX-License-Identifier: GNU General Public License v3.0 or later
use crate::ide::tui::component::{Action, Component, Focus, FocusState};
use crate::ide::tui::editor::Editor;
use crate::logging::Loggable;
use crate::tui::editor::Editor;
use clide::logging::Loggable;
use anyhow::{Context, Result, anyhow};
use ratatui::buffer::Buffer;
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers};
@@ -12,6 +11,7 @@ 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.
@@ -25,7 +25,7 @@ pub struct EditorTab {
impl EditorTab {
pub fn new() -> Self {
crate::trace!("Building {}", <Self as Loggable>::ID);
clide::trace!("Building {}", <Self as Loggable>::ID);
Self {
editors: HashMap::new(),
tab_order: Vec::new(),
@@ -35,7 +35,7 @@ impl EditorTab {
pub fn next_editor(&mut self) {
let next = (self.current_editor + 1) % self.tab_order.len();
crate::trace!(
clide::trace!(
"Moving from {} to next editor tab at {}",
self.current_editor,
next
@@ -49,7 +49,7 @@ impl EditorTab {
.current_editor
.checked_sub(1)
.unwrap_or(self.tab_order.len() - 1);
crate::trace!(
clide::trace!(
"Moving from {} to previous editor tab at {}",
self.current_editor,
prev
@@ -62,7 +62,7 @@ impl EditorTab {
match self.tab_order.get(index) {
None => {
if !self.tab_order.is_empty() {
crate::error!("Failed to get editor tab key with invalid index {index}");
clide::error!("Failed to get editor tab key with invalid index {index}");
}
None
}
@@ -80,7 +80,7 @@ impl EditorTab {
}
pub fn set_current_tab_focus(&mut self, focus: Focus) {
crate::trace!(
clide::trace!(
"Setting current tab {} focus to {:?}",
self.current_editor,
focus
@@ -89,10 +89,10 @@ impl EditorTab {
}
pub fn set_tab_focus(&mut self, focus: Focus, index: usize) {
crate::trace!("Setting tab {} focus to {:?}", index, focus);
clide::trace!("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.
crate::trace!(
clide::trace!(
"New tab {} focus set to Active; Setting current tab {} to Inactive",
index,
self.current_editor
@@ -101,11 +101,11 @@ impl EditorTab {
}
match self.get_editor_key(index) {
None => {
crate::error!("Failed setting tab focus for invalid key {index}");
clide::error!("Failed setting tab focus for invalid key {index}");
}
Some(key) => match self.editors.get_mut(&key) {
None => {
crate::error!(
clide::error!(
"Failed to update tab focus at index {} with invalid key: {}",
self.current_editor,
self.tab_order[self.current_editor]
@@ -117,12 +117,12 @@ impl EditorTab {
}
pub fn open_tab(&mut self, path: &std::path::Path) -> Result<()> {
crate::trace!("Opening new EditorTab with path {:?}", path);
clide::trace!("Opening new EditorTab with path {:?}", path);
if self
.editors
.contains_key(&path.to_string_lossy().to_string())
{
crate::warn!("EditorTab already opened with this file");
clide::warn!("EditorTab already opened with this file");
return Ok(());
}
@@ -147,12 +147,12 @@ impl EditorTab {
.to_owned();
match self.editors.remove(&key) {
None => {
crate::error!("Failed to remove editor tab {key} with invalid index {index}")
clide::error!("Failed to remove editor tab {key} with invalid index {index}")
}
Some(_) => {
self.prev_editor();
self.tab_order.remove(index);
crate::info!("Closed editor tab {key} at index {index}")
clide::info!("Closed editor tab {key} at index {index}")
}
}
Ok(())

View File

@@ -2,10 +2,10 @@
//
// SPDX-License-Identifier: GNU General Public License v3.0 or later
use crate::fs::entry_meta::EntryMeta;
use crate::ide::tui::component::{Action, Component, ComponentState, Focus, FocusState};
use crate::logging::Loggable;
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 ratatui::buffer::Buffer;
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, MouseEvent, MouseEventKind};
use ratatui::layout::{Alignment, Position, Rect};
@@ -26,7 +26,7 @@ pub struct Explorer<'a> {
impl<'a> Explorer<'a> {
pub fn new(path: &PathBuf) -> Result<Self> {
crate::trace!("Building {}", <Self as Loggable>::ID);
clide::trace!("Building {}", <Self as Loggable>::ID);
let explorer = Explorer {
root_path: EntryMeta::new(path)?,
tree_items: Self::build_tree_from_path(path)?,

View File

@@ -2,8 +2,8 @@
//
// SPDX-License-Identifier: GNU General Public License v3.0 or later
use crate::ide::tui::component::{Action, Component, ComponentState, Focus, FocusState};
use crate::logging::Loggable;
use crate::tui::component::{Action, Component, ComponentState, Focus, FocusState};
use clide::logging::Loggable;
use log::LevelFilter;
use ratatui::buffer::Buffer;
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent};
@@ -22,7 +22,7 @@ pub struct Logger {
impl Logger {
pub fn new() -> Self {
crate::trace!("Building {}", <Self as Loggable>::ID);
clide::trace!("Building {}", <Self as Loggable>::ID);
let state = TuiWidgetState::new();
state.transition(TuiWidgetEvent::HideKey);
Self {

View File

@@ -2,11 +2,11 @@
//
// SPDX-License-Identifier: GNU General Public License v3.0 or later
use crate::ide::tui::component::{Action, Component, ComponentState, FocusState};
use crate::ide::tui::menu_bar::MenuBarItemOption::{
use crate::tui::component::{Action, Component, ComponentState, FocusState};
use crate::tui::menu_bar::MenuBarItemOption::{
About, CloseTab, Exit, Reload, Save, ShowHideExplorer, ShowHideLogger,
};
use crate::logging::Loggable;
use clide::logging::Loggable;
use anyhow::Context;
use ratatui::buffer::Buffer;
use ratatui::crossterm::event::{KeyCode, KeyEvent};
@@ -92,7 +92,7 @@ pub struct MenuBar {
impl MenuBar {
const DEFAULT_HELP: &str = "(←/h)/(→/l): Select option | Enter: Choose selection";
pub fn new() -> Self {
crate::trace!("Building");
clide::trace!("Building");
Self {
selected: MenuBarItem::File,
opened: None,

View File

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

View File

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