TUI #1

Merged
shaunrd0 merged 73 commits from ui into master 2026-01-25 20:57:37 +00:00
4 changed files with 1418 additions and 223 deletions
Showing only changes of commit 7fe3e3e14d - Show all commits

1599
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -11,6 +11,8 @@ log = { version = "0.4.27", features = [] }
dirs = "6.0.0"
syntect = "5.2.0"
structopt = "0.3.26"
ratatui = "0.30.0"
anyhow = "1.0.100"
[build-dependencies]
# The link_qt_object_files feature is required for statically linking Qt 6.

View File

@ -42,7 +42,7 @@ fn main() -> Result<(), Box<dyn Error>> {
true => gui::run(root_path),
false => match args.tui {
// Open the TUI editor if requested, otherwise use the QML GUI by default.
true => tui::run(root_path),
true => Ok(tui::start(root_path)?),
false => {
// Relaunch the CLIDE GUI in a separate process.
Command::new(std::env::current_exe()?)

View File

@ -1,6 +1,42 @@
use anyhow::{Context, Result};
use ratatui::{DefaultTerminal, Frame};
use std::error::Error;
use std::time::Duration;
use ratatui::crossterm::event;
use ratatui::crossterm::event::{Event, KeyCode};
use ratatui::widgets::Paragraph;
pub fn run(root_path: std::path::PathBuf) -> Result<(), Box<dyn Error>> {
pub fn start(root_path: std::path::PathBuf) -> Result<()> {
println!("Starting the TUI editor at {:?}", root_path);
let terminal = ratatui::init();
let app_result = run(terminal, root_path).context("Failed to start the TUI editor.");
ratatui::restore();
app_result
}
pub fn run(
mut terminal: DefaultTerminal,
root_path: std::path::PathBuf,
) -> Result<()> {
loop {
terminal.draw(draw)?;
if should_quit()? {
break;
}
}
Ok(())
}
fn should_quit() -> Result<bool> {
if event::poll(Duration::from_millis(250)).context("event poll failed")? {
if let Event::Key(key) = event::read().context("event read failed")? {
return Ok(KeyCode::Char('q') == key.code);
}
}
Ok(false)
}
fn draw(frame: &mut Frame) {
let greeting = Paragraph::new("Hello World! (press 'q' to quit)");
frame.render_widget(greeting, frame.area());
}