forked from trinitrix/core
1
0
Fork 0

feat(ui): make tui compile again

This also refactors the tui codebase,
mainly making module locations more sane
This commit is contained in:
Silas Schöffel 2024-05-08 22:06:36 +02:00
parent e560790e00
commit a86c42deae
Signed by: sils
GPG Key ID: 6A587D46E3F44592
7 changed files with 68 additions and 25 deletions

View File

@ -28,7 +28,7 @@ use clap::Parser;
use crate::{
cli::{Args, Command},
ui::repl::Repl,
ui::{repl::Repl, tui::Tui},
};
#[tokio::main]
@ -37,7 +37,12 @@ async fn main() -> anyhow::Result<()> {
let args = Args::parse();
match args.subcommand {
Command::Tui {} => {}
Command::Tui {} => {
let mut app = app::App::new(Tui::new().context("Failed to setup tui")?)?;
// NOTE(@soispha): The `None` here is temporary <2024-05-08>
app.run(None, args.plugin_path).await?;
}
Command::Repl {} => {
let mut app = app::App::new(Repl::new().context("Failed to setup repl")?)?;

View File

@ -20,4 +20,5 @@
*/
pub mod repl;
pub mod tui;
pub mod ui_trait;

View File

@ -19,7 +19,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
pub mod update;
pub mod trinitrixui;
pub mod utils;
use std::io::Stdout;
@ -30,7 +31,7 @@ use crossterm::{
execute,
terminal::{disable_raw_mode, LeaveAlternateScreen},
};
use tui::{
use ratatui::{
backend::CrosstermBackend,
style::Color,
widgets::{Block, Borders, ListState},
@ -38,9 +39,10 @@ use tui::{
};
use tui_textarea::TextArea;
use crate::ui::{terminal_prepare, textarea_activate, textarea_inactivate};
use super::ui_trait::TirinitrixUi;
use crate::ui::{
tui::utils::{terminal_prepare, textarea_activate, textarea_inactivate},
ui_trait::TrinitrixUi,
};
#[derive(Clone, Copy, PartialEq)]
pub enum InputPosition {
@ -163,7 +165,7 @@ impl InputPosition {
}
}
pub struct UI<'a> {
pub struct Tui<'a> {
terminal: Terminal<CrosstermBackend<Stdout>>,
input_position: InputPosition,
pub rooms_state: ListState,
@ -171,9 +173,7 @@ pub struct UI<'a> {
pub cli: Option<TextArea<'a>>,
}
impl<'r> TirinitrixUi for UI<'r> {}
impl Drop for UI<'_> {
impl Drop for Tui<'_> {
fn drop(&mut self) {
info!("Destructing UI");
disable_raw_mode().expect("While destructing UI -> Failed to disable raw mode");
@ -188,7 +188,7 @@ impl Drop for UI<'_> {
}
}
impl UI<'_> {
impl Tui<'_> {
pub fn new() -> Result<Self> {
let stdout = terminal_prepare().context("Falied to prepare terminal")?;
let backend = CrosstermBackend::new(stdout);

View File

@ -21,21 +21,26 @@
use std::cmp;
use crate::{
app::status::Status,
ui::{
tui::{trinitrixui::widgets::command_monitor, Tui},
ui_trait::TrinitrixUi,
},
};
use anyhow::Result;
use tui::{
use cli_log::{debug, info};
use keymaps::key_repr::{Key, KeyValue};
use ratatui::{
layout::{Constraint, Direction, Layout},
style::{Color, Style},
widgets::{Block, Borders, Paragraph},
};
use self::widgets::command_monitor;
use super::UI;
use crate::app::status::Status;
pub mod widgets;
impl UI<'_> {
pub async fn update(&mut self, status: &Status) -> Result<()> {
impl<'r> TrinitrixUi for Tui<'r> {
async fn update(&mut self, status: &Status) -> Result<()> {
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Min(10), Constraint::Length(3)].as_ref())
@ -112,4 +117,38 @@ impl UI<'_> {
Ok(())
}
fn input(&mut self, input: Key) {
debug!("Input received in tui: {}", input);
if let Some(value) = input.value() {
match value {
KeyValue::Backspace => todo!(),
KeyValue::Enter => todo!(),
KeyValue::Left => todo!(),
KeyValue::Right => todo!(),
KeyValue::Up => todo!(),
KeyValue::Down => todo!(),
KeyValue::Home => todo!(),
KeyValue::End => todo!(),
KeyValue::PageUp => todo!(),
KeyValue::PageDown => todo!(),
KeyValue::Tab => todo!(),
KeyValue::BackTab => todo!(),
KeyValue::Delete => todo!(),
KeyValue::Insert => todo!(),
KeyValue::F(_) => todo!(),
KeyValue::Char(_) => todo!(),
KeyValue::Null => todo!(),
KeyValue::Esc => todo!(),
KeyValue::CapsLock => todo!(),
KeyValue::ScrollLock => todo!(),
KeyValue::NumLock => todo!(),
KeyValue::PrintScreen => todo!(),
KeyValue::Pause => todo!(),
KeyValue::Menu => todo!(),
KeyValue::KeypadBegin => todo!(),
}
} else {
info!("User wrote: '{}'", input.to_string_repr());
}
}
}

View File

@ -19,14 +19,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use tui::{
use ratatui::{
layout::Alignment,
style::{Color, Style},
text::Text,
widgets::{Block, Borders, Paragraph},
};
use crate::{app::status::StatusMessage, ui::central::InputPosition};
use crate::{app::status::StatusMessage, ui::tui::InputPosition};
pub fn init<'a>(status_events: &Vec<StatusMessage>, colors: &Vec<Color>) -> Paragraph<'a> {
let mut command_monitor = Text::default();

View File

@ -19,8 +19,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
pub mod central;
use std::{io, io::Stdout};
use anyhow::{Context, Result};
@ -30,13 +28,13 @@ use crossterm::{
execute,
terminal::{enable_raw_mode, EnterAlternateScreen},
};
use tui::{
use ratatui::{
style::{Color, Modifier, Style},
widgets::{Block, Borders},
};
use tui_textarea::TextArea;
fn terminal_prepare() -> Result<Stdout> {
pub(super) fn terminal_prepare() -> Result<Stdout> {
enable_raw_mode().context("Failed to enable raw mode")?;
let mut stdout = io::stdout();
execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?;