Refactor crates.
This commit is contained in:
12
Cargo.lock
generated
12
Cargo.lock
generated
@@ -298,7 +298,6 @@ dependencies = [
|
|||||||
"devicons",
|
"devicons",
|
||||||
"dirs",
|
"dirs",
|
||||||
"edtui",
|
"edtui",
|
||||||
"libclide",
|
|
||||||
"libclide-macros",
|
"libclide-macros",
|
||||||
"log",
|
"log",
|
||||||
"ratatui",
|
"ratatui",
|
||||||
@@ -1165,17 +1164,6 @@ version = "0.2.182"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112"
|
checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "libclide"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"anyhow",
|
|
||||||
"devicons",
|
|
||||||
"libclide-macros",
|
|
||||||
"log",
|
|
||||||
"strum",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libclide-macros"
|
name = "libclide-macros"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|||||||
@@ -3,9 +3,13 @@ name = "clide"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "clide"
|
||||||
|
path = "src/main.rs"
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
resolver = "3"
|
resolver = "3"
|
||||||
members = [".", "libclide", "libclide-macros", ]
|
members = [".", "libclide-macros", ]
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
anyhow = "1.0.100"
|
anyhow = "1.0.100"
|
||||||
@@ -24,7 +28,6 @@ ratatui = "0.30.0"
|
|||||||
tui-tree-widget = "0.24.0"
|
tui-tree-widget = "0.24.0"
|
||||||
tui-logger = "0.18.1"
|
tui-logger = "0.18.1"
|
||||||
edtui = "0.11.1"
|
edtui = "0.11.1"
|
||||||
libclide = { path = "./libclide" }
|
|
||||||
libclide-macros = { path = "./libclide-macros" }
|
libclide-macros = { path = "./libclide-macros" }
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
strum = { 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
|
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
|
This project requires at least Qt 6.7.3. To check your Qt version, you can use the following command
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
qmake6 -query QT_VERSION
|
qmake6 -query QT_VERSION
|
||||||
|
|||||||
2
build.rs
2
build.rs
@@ -28,6 +28,6 @@ fn main() {
|
|||||||
.qt_module("Svg")
|
.qt_module("Svg")
|
||||||
.qt_module("Xml")
|
.qt_module("Xml")
|
||||||
.qrc("./resources.qrc")
|
.qrc("./resources.qrc")
|
||||||
.files(["src/gui/colors.rs", "src/gui/filesystem.rs"])
|
.files(["src/ide/gui/colors.rs", "src/ide/gui/filesystem.rs"])
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ pub fn loggable(item: TokenStream) -> TokenStream {
|
|||||||
let (impl_generics, type_generics, where_clause) = generics.split_for_impl();
|
let (impl_generics, type_generics, where_clause) = generics.split_for_impl();
|
||||||
let struct_name_str = struct_name.to_string();
|
let struct_name_str = struct_name.to_string();
|
||||||
let expanded = quote! {
|
let expanded = quote! {
|
||||||
impl #impl_generics libclide::log::Loggable for #struct_name #type_generics #where_clause {
|
impl #impl_generics crate::logging::Loggable for #struct_name #type_generics #where_clause {
|
||||||
const ID: &'static str = #struct_name_str;
|
const ID: &'static str = #struct_name_str;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
16
libclide/Cargo.lock
generated
16
libclide/Cargo.lock
generated
@@ -1,16 +0,0 @@
|
|||||||
# 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",
|
|
||||||
]
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "libclide"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2024"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
anyhow = { workspace = true }
|
|
||||||
strum = { workspace = true }
|
|
||||||
log = { workspace = true }
|
|
||||||
devicons = { workspace = true }
|
|
||||||
libclide-macros = { path = "../libclide-macros" }
|
|
||||||
@@ -43,7 +43,7 @@ impl EntryMeta {
|
|||||||
.context(format!("Failed to get file name for path: {abs_path:?}"))?
|
.context(format!("Failed to get file name for path: {abs_path:?}"))?
|
||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
.to_string();
|
.to_string();
|
||||||
let icon = crate::fs::icon(&abs_path);
|
let icon = icon(&abs_path);
|
||||||
Ok(EntryMeta {
|
Ok(EntryMeta {
|
||||||
abs_path,
|
abs_path,
|
||||||
file_name,
|
file_name,
|
||||||
7
src/ide.rs
Normal file
7
src/ide.rs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
// 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;
|
||||||
43
src/ide/cli.rs
Normal file
43
src/ide/cli.rs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
// 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::ide::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."
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/ide/cli/app_context.rs
Normal file
36
src/ide/cli/app_context.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||||
|
|
||||||
|
use crate::ide::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")?,
|
||||||
|
};
|
||||||
|
crate::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,
|
||||||
|
}
|
||||||
@@ -2,15 +2,16 @@
|
|||||||
//
|
//
|
||||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||||
|
|
||||||
use crate::AppContext;
|
pub mod colors;
|
||||||
|
pub mod filesystem;
|
||||||
|
pub mod icon_provider;
|
||||||
|
|
||||||
|
use crate::ide::cli::app_context::AppContext;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use cxx_qt_lib::{QMapPair, QMapPair_QString_QVariant, QString, QVariant};
|
use cxx_qt_lib::{QMapPair, QMapPair_QString_QVariant, QString, QVariant};
|
||||||
|
|
||||||
pub mod colors;
|
|
||||||
pub mod filesystem;
|
|
||||||
|
|
||||||
pub fn run(app_context: AppContext) -> Result<()> {
|
pub fn run(app_context: AppContext) -> Result<()> {
|
||||||
libclide::trace!(target:"gui::run()", "Starting the GUI editor at {:?}", app_context.path);
|
crate::trace!(target:"gui::run()", "Starting the GUI editor at {:?}", app_context.path);
|
||||||
|
|
||||||
use cxx_qt_lib::{QGuiApplication, QQmlApplicationEngine, QUrl};
|
use cxx_qt_lib::{QGuiApplication, QQmlApplicationEngine, QUrl};
|
||||||
|
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
//
|
//
|
||||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||||
|
|
||||||
|
use crate::theme::colors::Colors;
|
||||||
use cxx_qt_lib::QColor;
|
use cxx_qt_lib::QColor;
|
||||||
use libclide::theme::colors::Colors;
|
|
||||||
|
|
||||||
#[cxx_qt::bridge]
|
#[cxx_qt::bridge]
|
||||||
pub mod qobject {
|
pub mod qobject {
|
||||||
@@ -76,7 +76,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() {
|
||||||
libclide::warn!(target:"FileSystem", "Attempted to open file {path:?} that is not a valid file");
|
crate::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();
|
||||||
@@ -141,6 +141,6 @@ impl qobject::FileSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn icon(self: std::pin::Pin<&mut Self>, path: &QString) -> QString {
|
fn icon(self: std::pin::Pin<&mut Self>, path: &QString) -> QString {
|
||||||
QString::from(libclide::fs::icon(path.to_string().as_str()).to_string())
|
QString::from(crate::fs::icon(path.to_string().as_str()).to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,20 +2,20 @@
|
|||||||
//
|
//
|
||||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||||
|
|
||||||
mod about;
|
pub mod about;
|
||||||
mod app;
|
pub mod app;
|
||||||
mod component;
|
pub mod component;
|
||||||
mod editor;
|
pub mod editor;
|
||||||
mod editor_tab;
|
pub mod editor_tab;
|
||||||
mod explorer;
|
pub mod explorer;
|
||||||
mod logger;
|
pub mod logger;
|
||||||
mod menu_bar;
|
pub mod menu_bar;
|
||||||
|
|
||||||
use crate::AppContext;
|
use crate::ide::cli::app_context::AppContext;
|
||||||
|
use crate::logging::Loggable;
|
||||||
|
use ::log::LevelFilter;
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use log::LevelFilter;
|
|
||||||
use ratatui::Terminal;
|
use ratatui::Terminal;
|
||||||
use libclide::log::Loggable;
|
|
||||||
use ratatui::backend::CrosstermBackend;
|
use ratatui::backend::CrosstermBackend;
|
||||||
use ratatui::crossterm::event::{
|
use ratatui::crossterm::event::{
|
||||||
DisableBracketedPaste, DisableMouseCapture, EnableBracketedPaste, EnableMouseCapture,
|
DisableBracketedPaste, DisableMouseCapture, EnableBracketedPaste, EnableMouseCapture,
|
||||||
@@ -36,7 +36,7 @@ struct Tui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(app_context: AppContext) -> Result<()> {
|
pub fn run(app_context: AppContext) -> Result<()> {
|
||||||
libclide::trace!(target: "clide::tui::run", "Starting TUI");
|
crate::trace!(target: "clide::tui::run", "Starting TUI");
|
||||||
Tui::new(app_context)?.start()
|
Tui::new(app_context)?.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ impl Tui {
|
|||||||
fn new(app_context: AppContext) -> Result<Self> {
|
fn new(app_context: AppContext) -> Result<Self> {
|
||||||
init_logger(LevelFilter::Trace)?;
|
init_logger(LevelFilter::Trace)?;
|
||||||
set_default_level(LevelFilter::Trace);
|
set_default_level(LevelFilter::Trace);
|
||||||
libclide::debug!("Logging initialized");
|
crate::debug!("Logging initialized");
|
||||||
|
|
||||||
let mut dir = env::temp_dir();
|
let mut dir = env::temp_dir();
|
||||||
dir.push("clide.log");
|
dir.push("clide.log");
|
||||||
@@ -56,7 +56,7 @@ impl Tui {
|
|||||||
.output_file(false)
|
.output_file(false)
|
||||||
.output_separator(':');
|
.output_separator(':');
|
||||||
set_log_file(file_options);
|
set_log_file(file_options);
|
||||||
libclide::debug!("Logging to file: {dir:?}");
|
crate::debug!("Logging to file: {dir:?}");
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
terminal: Terminal::new(CrosstermBackend::new(stdout()))?,
|
terminal: Terminal::new(CrosstermBackend::new(stdout()))?,
|
||||||
@@ -65,7 +65,7 @@ impl Tui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn start(self) -> Result<()> {
|
fn start(self) -> Result<()> {
|
||||||
libclide::info!("Starting the TUI editor at {:?}", self.root_path);
|
crate::info!("Starting the TUI editor at {:?}", self.root_path);
|
||||||
ratatui::crossterm::execute!(
|
ratatui::crossterm::execute!(
|
||||||
stdout(),
|
stdout(),
|
||||||
EnterAlternateScreen,
|
EnterAlternateScreen,
|
||||||
@@ -82,7 +82,7 @@ impl Tui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn stop() -> Result<()> {
|
fn stop() -> Result<()> {
|
||||||
libclide::info!("Stopping the TUI editor");
|
crate::info!("Stopping the TUI editor");
|
||||||
disable_raw_mode()?;
|
disable_raw_mode()?;
|
||||||
ratatui::crossterm::execute!(
|
ratatui::crossterm::execute!(
|
||||||
stdout(),
|
stdout(),
|
||||||
@@ -2,18 +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::log::Loggable;
|
use crate::logging::Loggable;
|
||||||
use ratatui::buffer::Buffer;
|
use ratatui::buffer::Buffer;
|
||||||
use ratatui::layout::{Constraint, Direction, Layout, Rect};
|
use ratatui::layout::{Constraint, Direction, Layout, Rect};
|
||||||
use ratatui::text::{Line, Span};
|
use ratatui::text::{Line, Span};
|
||||||
use ratatui::widgets::{Block, Borders, Clear, Padding, Paragraph, Widget, Wrap};
|
use ratatui::widgets::{Block, Borders, Clear, Padding, Paragraph, Widget, Wrap};
|
||||||
|
|
||||||
#[derive(Loggable)]
|
#[derive(Loggable, Default)]
|
||||||
pub struct About {}
|
pub struct About {}
|
||||||
|
|
||||||
impl About {
|
impl About {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
// libclide::trace!("Building {}", Self::id());
|
// crate::trace!("Building {}", Self::id());
|
||||||
Self {}
|
Self {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,14 +2,14 @@
|
|||||||
//
|
//
|
||||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||||
|
|
||||||
use crate::tui::about::About;
|
use crate::ide::tui::about::About;
|
||||||
use crate::tui::component::{Action, Component, Focus, FocusState, Visibility, VisibleState};
|
use crate::ide::tui::component::{Action, Component, Focus, FocusState, Visibility, VisibleState};
|
||||||
use crate::tui::editor_tab::EditorTab;
|
use crate::ide::tui::editor_tab::EditorTab;
|
||||||
use crate::tui::explorer::Explorer;
|
use crate::ide::tui::explorer::Explorer;
|
||||||
use crate::tui::logger::Logger;
|
use crate::ide::tui::logger::Logger;
|
||||||
use crate::tui::menu_bar::MenuBar;
|
use crate::ide::tui::menu_bar::MenuBar;
|
||||||
|
use crate::logging::Loggable;
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use libclide::log::Loggable;
|
|
||||||
use ratatui::DefaultTerminal;
|
use ratatui::DefaultTerminal;
|
||||||
use ratatui::buffer::Buffer;
|
use ratatui::buffer::Buffer;
|
||||||
use ratatui::crossterm::event;
|
use ratatui::crossterm::event;
|
||||||
@@ -42,7 +42,7 @@ pub struct App<'a> {
|
|||||||
|
|
||||||
impl<'a> App<'a> {
|
impl<'a> App<'a> {
|
||||||
pub fn new(root_path: PathBuf) -> Result<Self> {
|
pub fn new(root_path: PathBuf) -> Result<Self> {
|
||||||
libclide::trace!("Building {}", Self::ID);
|
crate::trace!("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)?,
|
||||||
@@ -56,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<()> {
|
||||||
libclide::trace!("Starting App");
|
crate::trace!("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()?;
|
||||||
libclide::trace!("Entering App run loop");
|
crate::trace!("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());
|
||||||
@@ -88,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() {
|
||||||
libclide::error!("Failed to get Editor while drawing bottom status bar");
|
crate::error!("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()
|
||||||
}
|
}
|
||||||
@@ -112,26 +112,26 @@ impl<'a> App<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn clear_focus(&mut self) {
|
fn clear_focus(&mut self) {
|
||||||
libclide::info!("Clearing all widget focus");
|
crate::info!("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 => {
|
||||||
libclide::error!("Failed to get current Editor while clearing focus")
|
crate::error!("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) {
|
||||||
libclide::info!("Changing widget focus to {:?}", focus);
|
crate::info!("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 => {
|
||||||
libclide::error!("Failed to get current Editor while changing focus")
|
crate::error!("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),
|
||||||
},
|
},
|
||||||
@@ -274,15 +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 => {
|
||||||
libclide::error!(
|
crate::error!("Failed to get current editor while handling App Action::Save");
|
||||||
"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) => {
|
||||||
libclide::error!("Failed to save editor contents: {e}");
|
crate::error!("Failed to save editor contents: {e}");
|
||||||
Ok(Action::Noop)
|
Ok(Action::Noop)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -301,14 +299,14 @@ impl<'a> Component for App<'a> {
|
|||||||
Err(_) => Ok(Action::Noop),
|
Err(_) => Ok(Action::Noop),
|
||||||
},
|
},
|
||||||
Action::ReloadFile => {
|
Action::ReloadFile => {
|
||||||
libclide::trace!("Reloading file for current editor");
|
crate::trace!("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 {
|
||||||
libclide::error!(
|
crate::error!(
|
||||||
"Failed to get current editor while handling App Action::ReloadFile"
|
"Failed to get current editor while handling App Action::ReloadFile"
|
||||||
);
|
);
|
||||||
Ok(Action::Noop)
|
Ok(Action::Noop)
|
||||||
@@ -4,11 +4,11 @@
|
|||||||
|
|
||||||
#![allow(dead_code, unused_variables)]
|
#![allow(dead_code, unused_variables)]
|
||||||
|
|
||||||
use crate::tui::component::Focus::Inactive;
|
use crate::ide::tui::component::Focus::Inactive;
|
||||||
|
use crate::logging::Loggable;
|
||||||
|
use crate::theme::colors::Colors;
|
||||||
use Focus::Active;
|
use Focus::Active;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use libclide::theme::colors::Colors;
|
|
||||||
use libclide::log::Loggable;
|
|
||||||
use ratatui::crossterm::event::{Event, KeyEvent, MouseEvent};
|
use ratatui::crossterm::event::{Event, KeyEvent, MouseEvent};
|
||||||
use ratatui::style::Color;
|
use ratatui::style::Color;
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ impl ComponentState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
libclide::trace!(target:Self::id(), "Building {}", Self::id());
|
crate::trace!(target:Self::id(), "Building {}", Self::id());
|
||||||
Self {
|
Self {
|
||||||
focus: Active,
|
focus: Active,
|
||||||
vis: Visibility::Visible,
|
vis: Visibility::Visible,
|
||||||
@@ -2,12 +2,12 @@
|
|||||||
//
|
//
|
||||||
// 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::ide::tui::component::{Action, Component, ComponentState, Focus, FocusState};
|
||||||
|
use crate::logging::Loggable;
|
||||||
use anyhow::{Context, Result, bail};
|
use anyhow::{Context, Result, bail};
|
||||||
use edtui::{
|
use edtui::{
|
||||||
EditorEventHandler, EditorState, EditorTheme, EditorView, LineNumbers, Lines, SyntaxHighlighter,
|
EditorEventHandler, EditorState, EditorTheme, EditorView, LineNumbers, Lines, SyntaxHighlighter,
|
||||||
};
|
};
|
||||||
use libclide::log::Loggable;
|
|
||||||
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};
|
||||||
@@ -27,7 +27,7 @@ pub struct Editor {
|
|||||||
|
|
||||||
impl Editor {
|
impl Editor {
|
||||||
pub fn new(path: &std::path::Path) -> Self {
|
pub fn new(path: &std::path::Path) -> Self {
|
||||||
libclide::trace!("Building {}", <Self as Loggable>::ID);
|
crate::trace!("Building {}", <Self as Loggable>::ID);
|
||||||
Editor {
|
Editor {
|
||||||
state: EditorState::default(),
|
state: EditorState::default(),
|
||||||
event_handler: EditorEventHandler::default(),
|
event_handler: EditorEventHandler::default(),
|
||||||
@@ -41,10 +41,10 @@ impl Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn reload_contents(&mut self) -> Result<()> {
|
pub fn reload_contents(&mut self) -> Result<()> {
|
||||||
libclide::trace!("Reloading editor file contents {:?}", self.file_path);
|
crate::trace!("Reloading editor file contents {:?}", self.file_path);
|
||||||
match self.file_path.clone() {
|
match self.file_path.clone() {
|
||||||
None => {
|
None => {
|
||||||
libclide::error!("Failed to reload editor contents with None file_path");
|
crate::error!("Failed to reload editor contents with None file_path");
|
||||||
bail!("Failed to reload editor contents with None file_path")
|
bail!("Failed to reload editor contents with None file_path")
|
||||||
}
|
}
|
||||||
Some(path) => self.set_contents(&path),
|
Some(path) => self.set_contents(&path),
|
||||||
@@ -52,7 +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<()> {
|
||||||
libclide::trace!("Setting Editor contents from path {:?}", path);
|
crate::trace!("Setting Editor contents from path {:?}", path);
|
||||||
if let Ok(contents) = std::fs::read_to_string(path) {
|
if let Ok(contents) = std::fs::read_to_string(path) {
|
||||||
let lines: Vec<_> = contents
|
let lines: Vec<_> = contents
|
||||||
.lines()
|
.lines()
|
||||||
@@ -68,10 +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 {
|
||||||
libclide::trace!("Saving Editor contents {:?}", path);
|
crate::trace!("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());
|
||||||
};
|
};
|
||||||
libclide::error!("Failed saving Editor contents; file_path was None");
|
crate::error!("Failed saving Editor contents; file_path was None");
|
||||||
bail!("File not saved. No file path set.")
|
bail!("File not saved. No file path set.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,10 +2,10 @@
|
|||||||
//
|
//
|
||||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||||
|
|
||||||
use crate::tui::component::{Action, Component, Focus, FocusState};
|
use crate::ide::tui::component::{Action, Component, Focus, FocusState};
|
||||||
use crate::tui::editor::Editor;
|
use crate::ide::tui::editor::Editor;
|
||||||
|
use crate::logging::Loggable;
|
||||||
use anyhow::{Context, Result, anyhow};
|
use anyhow::{Context, Result, anyhow};
|
||||||
use libclide::log::Loggable;
|
|
||||||
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,7 +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
|
||||||
#[derive(Loggable)]
|
#[derive(Loggable, Default)]
|
||||||
pub struct EditorTab {
|
pub struct EditorTab {
|
||||||
pub(crate) editors: HashMap<String, Editor>,
|
pub(crate) editors: HashMap<String, Editor>,
|
||||||
tab_order: Vec<String>,
|
tab_order: Vec<String>,
|
||||||
@@ -25,7 +25,7 @@ pub struct EditorTab {
|
|||||||
|
|
||||||
impl EditorTab {
|
impl EditorTab {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
libclide::trace!("Building {}", <Self as Loggable>::ID);
|
crate::trace!("Building {}", <Self as Loggable>::ID);
|
||||||
Self {
|
Self {
|
||||||
editors: HashMap::new(),
|
editors: HashMap::new(),
|
||||||
tab_order: Vec::new(),
|
tab_order: Vec::new(),
|
||||||
@@ -35,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();
|
||||||
libclide::trace!(
|
crate::trace!(
|
||||||
"Moving from {} to next editor tab at {}",
|
"Moving from {} to next editor tab at {}",
|
||||||
self.current_editor,
|
self.current_editor,
|
||||||
next
|
next
|
||||||
@@ -49,7 +49,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);
|
||||||
libclide::trace!(
|
crate::trace!(
|
||||||
"Moving from {} to previous editor tab at {}",
|
"Moving from {} to previous editor tab at {}",
|
||||||
self.current_editor,
|
self.current_editor,
|
||||||
prev
|
prev
|
||||||
@@ -62,7 +62,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() {
|
||||||
libclide::error!("Failed to get editor tab key with invalid index {index}");
|
crate::error!("Failed to get editor tab key with invalid index {index}");
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@@ -80,7 +80,7 @@ impl EditorTab {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_current_tab_focus(&mut self, focus: Focus) {
|
pub fn set_current_tab_focus(&mut self, focus: Focus) {
|
||||||
libclide::trace!(
|
crate::trace!(
|
||||||
"Setting current tab {} focus to {:?}",
|
"Setting current tab {} focus to {:?}",
|
||||||
self.current_editor,
|
self.current_editor,
|
||||||
focus
|
focus
|
||||||
@@ -89,10 +89,10 @@ impl EditorTab {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_tab_focus(&mut self, focus: Focus, index: usize) {
|
pub fn set_tab_focus(&mut self, focus: Focus, index: usize) {
|
||||||
libclide::trace!("Setting tab {} focus to {:?}", index, focus);
|
crate::trace!("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.
|
||||||
libclide::trace!(
|
crate::trace!(
|
||||||
"New tab {} focus set to Active; Setting current tab {} to Inactive",
|
"New tab {} focus set to Active; Setting current tab {} to Inactive",
|
||||||
index,
|
index,
|
||||||
self.current_editor
|
self.current_editor
|
||||||
@@ -101,11 +101,11 @@ impl EditorTab {
|
|||||||
}
|
}
|
||||||
match self.get_editor_key(index) {
|
match self.get_editor_key(index) {
|
||||||
None => {
|
None => {
|
||||||
libclide::error!("Failed setting tab focus for invalid key {index}");
|
crate::error!("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 => {
|
||||||
libclide::error!(
|
crate::error!(
|
||||||
"Failed to update tab focus at index {} with invalid key: {}",
|
"Failed to update tab focus at index {} with invalid key: {}",
|
||||||
self.current_editor,
|
self.current_editor,
|
||||||
self.tab_order[self.current_editor]
|
self.tab_order[self.current_editor]
|
||||||
@@ -117,12 +117,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<()> {
|
||||||
libclide::trace!("Opening new EditorTab with path {:?}", path);
|
crate::trace!("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())
|
||||||
{
|
{
|
||||||
libclide::warn!("EditorTab already opened with this file");
|
crate::warn!("EditorTab already opened with this file");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,12 +147,12 @@ impl EditorTab {
|
|||||||
.to_owned();
|
.to_owned();
|
||||||
match self.editors.remove(&key) {
|
match self.editors.remove(&key) {
|
||||||
None => {
|
None => {
|
||||||
libclide::error!("Failed to remove editor tab {key} with invalid index {index}")
|
crate::error!("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);
|
||||||
libclide::info!("Closed editor tab {key} at index {index}")
|
crate::info!("Closed editor tab {key} at index {index}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -2,10 +2,10 @@
|
|||||||
//
|
//
|
||||||
// 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::fs::entry_meta::EntryMeta;
|
||||||
|
use crate::ide::tui::component::{Action, Component, ComponentState, Focus, FocusState};
|
||||||
|
use crate::logging::Loggable;
|
||||||
use anyhow::{Context, Result, bail};
|
use anyhow::{Context, Result, bail};
|
||||||
use libclide::fs::entry_meta::EntryMeta;
|
|
||||||
use libclide::log::Loggable;
|
|
||||||
use ratatui::buffer::Buffer;
|
use ratatui::buffer::Buffer;
|
||||||
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, MouseEvent, MouseEventKind};
|
use ratatui::crossterm::event::{Event, KeyCode, KeyEvent, MouseEvent, MouseEventKind};
|
||||||
use ratatui::layout::{Alignment, Position, Rect};
|
use ratatui::layout::{Alignment, Position, Rect};
|
||||||
@@ -26,7 +26,7 @@ pub struct Explorer<'a> {
|
|||||||
|
|
||||||
impl<'a> Explorer<'a> {
|
impl<'a> Explorer<'a> {
|
||||||
pub fn new(path: &PathBuf) -> Result<Self> {
|
pub fn new(path: &PathBuf) -> Result<Self> {
|
||||||
libclide::trace!("Building {}", <Self as Loggable>::ID);
|
crate::trace!("Building {}", <Self as Loggable>::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)?,
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
//
|
//
|
||||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||||
|
|
||||||
use crate::tui::component::{Action, Component, ComponentState, Focus, FocusState};
|
use crate::ide::tui::component::{Action, Component, ComponentState, Focus, FocusState};
|
||||||
use libclide::log::Loggable;
|
use crate::logging::Loggable;
|
||||||
use log::LevelFilter;
|
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};
|
||||||
@@ -12,9 +12,9 @@ use ratatui::style::{Color, Style};
|
|||||||
use ratatui::widgets::Widget;
|
use ratatui::widgets::Widget;
|
||||||
use tui_logger::{TuiLoggerLevelOutput, TuiLoggerSmartWidget, TuiWidgetEvent, TuiWidgetState};
|
use tui_logger::{TuiLoggerLevelOutput, TuiLoggerSmartWidget, TuiWidgetEvent, TuiWidgetState};
|
||||||
|
|
||||||
/// Any log written as info!(target:self.id(), "message") will work with this logger.
|
/// Any logging written as info!(target:self.id(), "message") will work with this logger.
|
||||||
/// The logger is bound to info!, debug!, error!, trace! macros within Tui::new().
|
/// The logger is bound to info!, debug!, error!, trace! macros within Tui::new().
|
||||||
#[derive(Loggable)]
|
#[derive(Loggable, Default)]
|
||||||
pub struct Logger {
|
pub struct Logger {
|
||||||
state: TuiWidgetState,
|
state: TuiWidgetState,
|
||||||
pub(crate) component_state: ComponentState,
|
pub(crate) component_state: ComponentState,
|
||||||
@@ -22,7 +22,7 @@ pub struct Logger {
|
|||||||
|
|
||||||
impl Logger {
|
impl Logger {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
libclide::trace!("Building {}", <Self as Loggable>::ID);
|
crate::trace!("Building {}", <Self as Loggable>::ID);
|
||||||
let state = TuiWidgetState::new();
|
let state = TuiWidgetState::new();
|
||||||
state.transition(TuiWidgetEvent::HideKey);
|
state.transition(TuiWidgetEvent::HideKey);
|
||||||
Self {
|
Self {
|
||||||
@@ -2,12 +2,12 @@
|
|||||||
//
|
//
|
||||||
// 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, FocusState};
|
use crate::ide::tui::component::{Action, Component, ComponentState, FocusState};
|
||||||
use crate::tui::menu_bar::MenuBarItemOption::{
|
use crate::ide::tui::menu_bar::MenuBarItemOption::{
|
||||||
About, CloseTab, Exit, Reload, Save, ShowHideExplorer, ShowHideLogger,
|
About, CloseTab, Exit, Reload, Save, ShowHideExplorer, ShowHideLogger,
|
||||||
};
|
};
|
||||||
|
use crate::logging::Loggable;
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use libclide::log::Loggable;
|
|
||||||
use ratatui::buffer::Buffer;
|
use ratatui::buffer::Buffer;
|
||||||
use ratatui::crossterm::event::{KeyCode, KeyEvent};
|
use ratatui::crossterm::event::{KeyCode, KeyEvent};
|
||||||
use ratatui::layout::Rect;
|
use ratatui::layout::Rect;
|
||||||
@@ -18,8 +18,9 @@ use ratatui::widgets::{
|
|||||||
};
|
};
|
||||||
use strum::{EnumIter, FromRepr, IntoEnumIterator};
|
use strum::{EnumIter, FromRepr, IntoEnumIterator};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromRepr, EnumIter)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromRepr, EnumIter, Default)]
|
||||||
enum MenuBarItem {
|
enum MenuBarItem {
|
||||||
|
#[default]
|
||||||
File,
|
File,
|
||||||
View,
|
View,
|
||||||
Help,
|
Help,
|
||||||
@@ -80,7 +81,7 @@ impl MenuBarItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Loggable)]
|
#[derive(Debug, Loggable, Default)]
|
||||||
pub struct MenuBar {
|
pub struct MenuBar {
|
||||||
selected: MenuBarItem,
|
selected: MenuBarItem,
|
||||||
opened: Option<MenuBarItem>,
|
opened: Option<MenuBarItem>,
|
||||||
@@ -91,7 +92,7 @@ pub struct MenuBar {
|
|||||||
impl MenuBar {
|
impl 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 {
|
||||||
libclide::trace!("Building");
|
crate::trace!("Building");
|
||||||
Self {
|
Self {
|
||||||
selected: MenuBarItem::File,
|
selected: MenuBarItem::File,
|
||||||
opened: None,
|
opened: None,
|
||||||
@@ -3,5 +3,6 @@
|
|||||||
// 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 ide;
|
||||||
|
pub mod logging;
|
||||||
pub mod theme;
|
pub mod theme;
|
||||||
@@ -11,13 +11,14 @@
|
|||||||
//!
|
//!
|
||||||
//! The Loggable trait can be implemented to automatically associate log messages with a struct.
|
//! The Loggable trait can be implemented to automatically associate log messages with a struct.
|
||||||
//! ```
|
//! ```
|
||||||
//! use libclide::log::Loggable;
|
//! use clide::logging;
|
||||||
|
//! use libclide_macros::Loggable;
|
||||||
//!
|
//!
|
||||||
//! #[derive(Loggable)]
|
//! #[derive(Loggable)]
|
||||||
//! struct MyStruct;
|
//! struct MyStruct;
|
||||||
//! impl MyStruct {
|
//! impl MyStruct {
|
||||||
//! fn my_method(&self) {
|
//! fn my_method(&self) {
|
||||||
//! libclide::info!("This log message will use target <Self as Loggable>::ID, which is 'MyStruct'");
|
//! clide::info!("This log message will use target Self::ID, which is 'MyStruct'");
|
||||||
//! }
|
//! }
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
@@ -25,51 +26,51 @@
|
|||||||
//! If the struct does not derive or implement Loggable, the target variant of the log macros must
|
//! If the struct does not derive or implement Loggable, the target variant of the log macros must
|
||||||
//! be used instead.
|
//! be used instead.
|
||||||
//! ```
|
//! ```
|
||||||
//! libclide::info!(target: "CustomTarget", "This log message will have the target 'CustomTarget'");
|
//! clide::info!(target: "CustomTarget", "This log message will have the target 'CustomTarget'");
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! info {
|
macro_rules! info {
|
||||||
(target: $target:expr, $($arg:tt)+) => ({
|
(target: $target:expr, $($arg:tt)+) => ({
|
||||||
log::info!(target: $target, $($arg)+)
|
::log::info!(target: $target, $($arg)+)
|
||||||
});
|
});
|
||||||
|
|
||||||
($($arg:tt)+) => (log::info!(target: Self::ID, $($arg)+))
|
($($arg:tt)+) => (::log::info!(target: Self::ID, $($arg)+))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! debug {
|
macro_rules! debug {
|
||||||
(target: $target:expr, $($arg:tt)+) => ({
|
(target: $target:expr, $($arg:tt)+) => ({
|
||||||
log::debug!(target: $target, $($arg)+)
|
::log::debug!(target: $target, $($arg)+)
|
||||||
});
|
});
|
||||||
|
|
||||||
($($arg:tt)+) => (log::debug!(target: Self::ID, $($arg)+))
|
($($arg:tt)+) => (::log::debug!(target: Self::ID, $($arg)+))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! warn {
|
macro_rules! warn {
|
||||||
(target: $target:expr, $($arg:tt)+) => ({
|
(target: $target:expr, $($arg:tt)+) => ({
|
||||||
log::warn!(target: $target, $($arg)+)
|
::log::warn!(target: $target, $($arg)+)
|
||||||
});
|
});
|
||||||
|
|
||||||
($($arg:tt)+) => (log::warn!(target: Self::ID, $($arg)+))
|
($($arg:tt)+) => (::log::warn!(target: Self::ID, $($arg)+))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! error {
|
macro_rules! error {
|
||||||
(target: $target:expr, $($arg:tt)+) => ({
|
(target: $target:expr, $($arg:tt)+) => ({
|
||||||
log::error!(target: $target, $($arg)+)
|
::log::error!(target: $target, $($arg)+)
|
||||||
});
|
});
|
||||||
|
|
||||||
($($arg:tt)+) => (log::error!(target: Self::ID, $($arg)+))
|
($($arg:tt)+) => (::log::error!(target: Self::ID, $($arg)+))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! trace {
|
macro_rules! trace {
|
||||||
(target: $target:expr, $($arg:tt)+) => ({
|
(target: $target:expr, $($arg:tt)+) => ({
|
||||||
log::trace!(target: $target, $($arg)+)
|
::log::trace!(target: $target, $($arg)+)
|
||||||
});
|
});
|
||||||
|
|
||||||
($($arg:tt)+) => (log::trace!(target: Self::ID, $($arg)+))
|
($($arg:tt)+) => (::log::trace!(target: Self::ID, $($arg)+))
|
||||||
}
|
}
|
||||||
76
src/main.rs
76
src/main.rs
@@ -2,84 +2,20 @@
|
|||||||
//
|
//
|
||||||
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
||||||
|
|
||||||
use anyhow::{Context, Result, anyhow};
|
use anyhow::{Context, Result};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use clide::ide::cli::Cli;
|
||||||
|
use clide::ide::cli::app_context::{AppContext, RunMode};
|
||||||
use std::process::{Command, Stdio};
|
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<()> {
|
fn main() -> Result<()> {
|
||||||
let args = Cli::parse();
|
let args = Cli::parse();
|
||||||
let app_context = AppContext::new(args)?;
|
let app_context = AppContext::new(args)?;
|
||||||
match app_context.run_mode {
|
match app_context.run_mode {
|
||||||
RunMode::GuiAttached => gui::run(app_context),
|
RunMode::GuiAttached => clide::ide::gui::run(app_context),
|
||||||
RunMode::Tui => tui::run(app_context),
|
RunMode::Tui => clide::ide::tui::run(app_context),
|
||||||
RunMode::Gui => {
|
RunMode::Gui => {
|
||||||
libclide::trace!(target:"main()", "Starting GUI in a new process");
|
clide::trace!(target:"main()", "Starting GUI in a new process");
|
||||||
Command::new(std::env::current_exe()?)
|
Command::new(std::env::current_exe()?)
|
||||||
.args(["--gui", app_context.path.to_str().unwrap()])
|
.args(["--gui", app_context.path.to_str().unwrap()])
|
||||||
.stdout(Stdio::null())
|
.stdout(Stdio::null())
|
||||||
|
|||||||
Reference in New Issue
Block a user