TUI #1
1599
Cargo.lock
generated
1599
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -11,6 +11,8 @@ log = { version = "0.4.27", features = [] }
|
|||||||
dirs = "6.0.0"
|
dirs = "6.0.0"
|
||||||
syntect = "5.2.0"
|
syntect = "5.2.0"
|
||||||
structopt = "0.3.26"
|
structopt = "0.3.26"
|
||||||
|
ratatui = "0.30.0"
|
||||||
|
anyhow = "1.0.100"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
# The link_qt_object_files feature is required for statically linking Qt 6.
|
# The link_qt_object_files feature is required for statically linking Qt 6.
|
||||||
|
|||||||
@ -42,7 +42,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
true => gui::run(root_path),
|
true => gui::run(root_path),
|
||||||
false => match args.tui {
|
false => match args.tui {
|
||||||
// Open the TUI editor if requested, otherwise use the QML GUI by default.
|
// 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 => {
|
false => {
|
||||||
// Relaunch the CLIDE GUI in a separate process.
|
// Relaunch the CLIDE GUI in a separate process.
|
||||||
Command::new(std::env::current_exe()?)
|
Command::new(std::env::current_exe()?)
|
||||||
|
|||||||
38
src/tui.rs
38
src/tui.rs
@ -1,6 +1,42 @@
|
|||||||
|
use anyhow::{Context, Result};
|
||||||
|
use ratatui::{DefaultTerminal, Frame};
|
||||||
use std::error::Error;
|
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);
|
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(())
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user