release/0.3.0 #6
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -853,7 +853,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mould"
|
name = "mould"
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"clap",
|
"clap",
|
||||||
|
|||||||
16
README.md
16
README.md
@@ -11,6 +11,8 @@ mould is a modern Terminal User Interface (TUI) tool designed for interactively
|
|||||||
- **Modern UI**: A polished, rounded interface featuring the Catppuccin Mocha palette.
|
- **Modern UI**: A polished, rounded interface featuring the Catppuccin Mocha palette.
|
||||||
- **Highly Configurable**: Customize keybindings and themes via a simple TOML configuration.
|
- **Highly Configurable**: Customize keybindings and themes via a simple TOML configuration.
|
||||||
- **Dynamic Alignment**: Automatically aligns keys and values for perfect vertical readability.
|
- **Dynamic Alignment**: Automatically aligns keys and values for perfect vertical readability.
|
||||||
|
- **Default Value Visibility**: Keep track of original template values while editing.
|
||||||
|
- **Incremental Merging**: Load existing values from an output file to continue where you left off.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -72,7 +74,19 @@ quit = ":q"
|
|||||||
normal_mode = "Esc"
|
normal_mode = "Esc"
|
||||||
|
|
||||||
[theme]
|
[theme]
|
||||||
name = "catppuccin_mocha"
|
# Enable transparency to let your terminal background show through
|
||||||
|
transparent = false
|
||||||
|
|
||||||
|
# Custom color palette (Catppuccin Mocha defaults)
|
||||||
|
crust = "#11111b"
|
||||||
|
surface0 = "#313244"
|
||||||
|
surface1 = "#45475a"
|
||||||
|
text = "#cdd6f4"
|
||||||
|
blue = "#89b4fa"
|
||||||
|
green = "#a6e3a1"
|
||||||
|
lavender = "#b4befe"
|
||||||
|
mauve = "#cba6f7"
|
||||||
|
peach = "#fab387"
|
||||||
```
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|||||||
46
config.example.toml
Normal file
46
config.example.toml
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
# mould Configuration Example
|
||||||
|
# Place this file at ~/.config/mould/config.toml (Linux/macOS)
|
||||||
|
# or %AppData%\mould\config.toml (Windows)
|
||||||
|
|
||||||
|
[theme]
|
||||||
|
# If true, skip rendering the background block to let the terminal's transparency show.
|
||||||
|
transparent = false
|
||||||
|
|
||||||
|
# Colors are specified in hex format ("#RRGGBB").
|
||||||
|
# Default values follow the Catppuccin Mocha palette.
|
||||||
|
|
||||||
|
# Main background color (used when transparent = false).
|
||||||
|
crust = "#11111b"
|
||||||
|
|
||||||
|
# Status bar background and other secondary UI elements.
|
||||||
|
surface0 = "#313244"
|
||||||
|
|
||||||
|
# Border and separator color.
|
||||||
|
surface1 = "#45475a"
|
||||||
|
|
||||||
|
# Default text color.
|
||||||
|
text = "#cdd6f4"
|
||||||
|
|
||||||
|
# Selection highlight and "NORMAL" mode tag color.
|
||||||
|
blue = "#89b4fa"
|
||||||
|
|
||||||
|
# Insert mode highlight and "INSERT" mode tag color.
|
||||||
|
green = "#a6e3a1"
|
||||||
|
|
||||||
|
# Keys/labels color.
|
||||||
|
lavender = "#b4befe"
|
||||||
|
|
||||||
|
# Section titles color.
|
||||||
|
mauve = "#cba6f7"
|
||||||
|
|
||||||
|
# Input field titles color.
|
||||||
|
peach = "#fab387"
|
||||||
|
|
||||||
|
[keybinds]
|
||||||
|
# Keybindings for navigation and application control.
|
||||||
|
down = "j"
|
||||||
|
up = "k"
|
||||||
|
edit = "i"
|
||||||
|
save = ":w"
|
||||||
|
quit = ":q"
|
||||||
|
normal_mode = "Esc"
|
||||||
@@ -4,8 +4,8 @@ use std::path::PathBuf;
|
|||||||
/// mould: A TUI tool to generate and edit configuration files (.env, json, yaml, toml)
|
/// mould: A TUI tool to generate and edit configuration files (.env, json, yaml, toml)
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(
|
#[command(
|
||||||
author,
|
author,
|
||||||
version,
|
version,
|
||||||
about = "mould: A TUI tool to generate and edit configuration files (.env, json, yaml, toml)",
|
about = "mould: A TUI tool to generate and edit configuration files (.env, json, yaml, toml)",
|
||||||
long_about = "mould allows you to interactively edit and generate configuration files using templates. It supports various formats including .env, JSON, YAML, and TOML. It features a modern TUI with Vim-inspired keybindings and out-of-the-box support for theming.",
|
long_about = "mould allows you to interactively edit and generate configuration files using templates. It supports various formats including .env, JSON, YAML, and TOML. It features a modern TUI with Vim-inspired keybindings and out-of-the-box support for theming.",
|
||||||
after_help = "EXAMPLES:\n mould .env.example\n mould docker-compose.yml\n mould config.template.json -o config.json"
|
after_help = "EXAMPLES:\n mould .env.example\n mould docker-compose.yml\n mould config.template.json -o config.json"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
use ratatui::style::Color;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use ratatui::style::Color;
|
|
||||||
|
|
||||||
/// Configuration for the application's appearance.
|
/// Configuration for the application's appearance.
|
||||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||||
@@ -42,15 +42,33 @@ impl ThemeConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn crust(&self) -> Color { Self::parse_hex(&self.crust) }
|
pub fn crust(&self) -> Color {
|
||||||
pub fn surface0(&self) -> Color { Self::parse_hex(&self.surface0) }
|
Self::parse_hex(&self.crust)
|
||||||
pub fn surface1(&self) -> Color { Self::parse_hex(&self.surface1) }
|
}
|
||||||
pub fn text(&self) -> Color { Self::parse_hex(&self.text) }
|
pub fn surface0(&self) -> Color {
|
||||||
pub fn blue(&self) -> Color { Self::parse_hex(&self.blue) }
|
Self::parse_hex(&self.surface0)
|
||||||
pub fn green(&self) -> Color { Self::parse_hex(&self.green) }
|
}
|
||||||
pub fn lavender(&self) -> Color { Self::parse_hex(&self.lavender) }
|
pub fn surface1(&self) -> Color {
|
||||||
pub fn mauve(&self) -> Color { Self::parse_hex(&self.mauve) }
|
Self::parse_hex(&self.surface1)
|
||||||
pub fn peach(&self) -> Color { Self::parse_hex(&self.peach) }
|
}
|
||||||
|
pub fn text(&self) -> Color {
|
||||||
|
Self::parse_hex(&self.text)
|
||||||
|
}
|
||||||
|
pub fn blue(&self) -> Color {
|
||||||
|
Self::parse_hex(&self.blue)
|
||||||
|
}
|
||||||
|
pub fn green(&self) -> Color {
|
||||||
|
Self::parse_hex(&self.green)
|
||||||
|
}
|
||||||
|
pub fn lavender(&self) -> Color {
|
||||||
|
Self::parse_hex(&self.lavender)
|
||||||
|
}
|
||||||
|
pub fn mauve(&self) -> Color {
|
||||||
|
Self::parse_hex(&self.mauve)
|
||||||
|
}
|
||||||
|
pub fn peach(&self) -> Color {
|
||||||
|
Self::parse_hex(&self.peach)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ThemeConfig {
|
impl Default for ThemeConfig {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use thiserror::Error;
|
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
/// Custom error types for the mould application.
|
/// Custom error types for the mould application.
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
|
|||||||
@@ -16,9 +16,12 @@ impl HierarchicalHandler {
|
|||||||
fn read_value(&self, path: &Path) -> io::Result<Value> {
|
fn read_value(&self, path: &Path) -> io::Result<Value> {
|
||||||
let content = fs::read_to_string(path)?;
|
let content = fs::read_to_string(path)?;
|
||||||
let value = match self.format_type {
|
let value = match self.format_type {
|
||||||
FormatType::Json => serde_json::from_str(&content).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?,
|
FormatType::Json => serde_json::from_str(&content)
|
||||||
FormatType::Yaml => serde_yaml::from_str(&content).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?,
|
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?,
|
||||||
FormatType::Toml => toml::from_str(&content).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?,
|
FormatType::Yaml => serde_yaml::from_str(&content)
|
||||||
|
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?,
|
||||||
|
FormatType::Toml => toml::from_str(&content)
|
||||||
|
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?,
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
Ok(value)
|
Ok(value)
|
||||||
@@ -26,15 +29,22 @@ impl HierarchicalHandler {
|
|||||||
|
|
||||||
fn write_value(&self, path: &Path, value: &Value) -> io::Result<()> {
|
fn write_value(&self, path: &Path, value: &Value) -> io::Result<()> {
|
||||||
let content = match self.format_type {
|
let content = match self.format_type {
|
||||||
FormatType::Json => serde_json::to_string_pretty(value).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?,
|
FormatType::Json => serde_json::to_string_pretty(value)
|
||||||
FormatType::Yaml => serde_yaml::to_string(value).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?,
|
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?,
|
||||||
|
FormatType::Yaml => serde_yaml::to_string(value)
|
||||||
|
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?,
|
||||||
FormatType::Toml => {
|
FormatType::Toml => {
|
||||||
// toml requires the root to be a table
|
// toml requires the root to be a table
|
||||||
if value.is_object() {
|
if value.is_object() {
|
||||||
let toml_value: toml::Value = serde_json::from_value(value.clone()).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
|
let toml_value: toml::Value = serde_json::from_value(value.clone())
|
||||||
toml::to_string_pretty(&toml_value).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?
|
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
|
||||||
|
toml::to_string_pretty(&toml_value)
|
||||||
|
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?
|
||||||
} else {
|
} else {
|
||||||
return Err(io::Error::new(io::ErrorKind::InvalidData, "Root of TOML must be an object"));
|
return Err(io::Error::new(
|
||||||
|
io::ErrorKind::InvalidData,
|
||||||
|
"Root of TOML must be an object",
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
@@ -143,7 +153,7 @@ fn insert_into_value(root: &mut Value, path: &str, new_val_str: &str) {
|
|||||||
*current = Value::Object(Map::new());
|
*current = Value::Object(Map::new());
|
||||||
}
|
}
|
||||||
let map = current.as_object_mut().unwrap();
|
let map = current.as_object_mut().unwrap();
|
||||||
|
|
||||||
let next_node = map.entry(key.to_string()).or_insert_with(|| {
|
let next_node = map.entry(key.to_string()).or_insert_with(|| {
|
||||||
if idx.is_some() {
|
if idx.is_some() {
|
||||||
Value::Array(Vec::new())
|
Value::Array(Vec::new())
|
||||||
@@ -171,7 +181,7 @@ fn insert_into_value(root: &mut Value, path: &str, new_val_str: &str) {
|
|||||||
*current = Value::Object(Map::new());
|
*current = Value::Object(Map::new());
|
||||||
}
|
}
|
||||||
let map = current.as_object_mut().unwrap();
|
let map = current.as_object_mut().unwrap();
|
||||||
|
|
||||||
// Attempt basic type inference
|
// Attempt basic type inference
|
||||||
let final_val = if let Ok(n) = new_val_str.parse::<i64>() {
|
let final_val = if let Ok(n) = new_val_str.parse::<i64>() {
|
||||||
Value::Number(n.into())
|
Value::Number(n.into())
|
||||||
@@ -182,7 +192,9 @@ fn insert_into_value(root: &mut Value, path: &str, new_val_str: &str) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Some(i) = final_idx {
|
if let Some(i) = final_idx {
|
||||||
let next_node = map.entry(final_key.to_string()).or_insert_with(|| Value::Array(Vec::new()));
|
let next_node = map
|
||||||
|
.entry(final_key.to_string())
|
||||||
|
.or_insert_with(|| Value::Array(Vec::new()));
|
||||||
if !next_node.is_array() {
|
if !next_node.is_array() {
|
||||||
*next_node = Value::Array(Vec::new());
|
*next_node = Value::Array(Vec::new());
|
||||||
}
|
}
|
||||||
@@ -200,7 +212,7 @@ fn parse_array_key(part: &str) -> (&str, Option<usize>) {
|
|||||||
if part.ends_with(']') && part.contains('[') {
|
if part.ends_with(']') && part.contains('[') {
|
||||||
let start_idx = part.find('[').unwrap();
|
let start_idx = part.find('[').unwrap();
|
||||||
let key = &part[..start_idx];
|
let key = &part[..start_idx];
|
||||||
let idx = part[start_idx+1..part.len()-1].parse::<usize>().ok();
|
let idx = part[start_idx + 1..part.len() - 1].parse::<usize>().ok();
|
||||||
(key, idx)
|
(key, idx)
|
||||||
} else {
|
} else {
|
||||||
(part, None)
|
(part, None)
|
||||||
@@ -224,15 +236,15 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
flatten(&json, "", &mut vars);
|
flatten(&json, "", &mut vars);
|
||||||
assert_eq!(vars.len(), 2);
|
assert_eq!(vars.len(), 2);
|
||||||
|
|
||||||
let mut root = Value::Object(Map::new());
|
let mut root = Value::Object(Map::new());
|
||||||
for var in vars {
|
for var in vars {
|
||||||
insert_into_value(&mut root, &var.key, &var.value);
|
insert_into_value(&mut root, &var.key, &var.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// When unflattening, it parses bool back
|
// When unflattening, it parses bool back
|
||||||
let unflattened_json = serde_json::to_string(&root).unwrap();
|
let unflattened_json = serde_json::to_string(&root).unwrap();
|
||||||
assert!(unflattened_json.contains("\"8080:80\""));
|
assert!(unflattened_json.contains("\"8080:80\""));
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use std::path::Path;
|
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
pub mod env;
|
pub mod env;
|
||||||
pub mod hierarchical;
|
pub mod hierarchical;
|
||||||
|
|||||||
36
src/main.rs
36
src/main.rs
@@ -18,32 +18,32 @@ use std::path::{Path, PathBuf};
|
|||||||
use crossterm::{
|
use crossterm::{
|
||||||
event::{DisableMouseCapture, EnableMouseCapture},
|
event::{DisableMouseCapture, EnableMouseCapture},
|
||||||
execute,
|
execute,
|
||||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
terminal::{EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode},
|
||||||
};
|
};
|
||||||
use ratatui::{backend::CrosstermBackend, Terminal};
|
use ratatui::{Terminal, backend::CrosstermBackend};
|
||||||
|
|
||||||
/// Helper to automatically determine the output file path based on common naming conventions.
|
/// Helper to automatically determine the output file path based on common naming conventions.
|
||||||
fn determine_output_path(input: &Path) -> PathBuf {
|
fn determine_output_path(input: &Path) -> PathBuf {
|
||||||
let file_name = input.file_name().unwrap_or_default().to_string_lossy();
|
let file_name = input.file_name().unwrap_or_default().to_string_lossy();
|
||||||
|
|
||||||
if file_name == ".env.example" {
|
if file_name == ".env.example" {
|
||||||
return input.with_file_name(".env");
|
return input.with_file_name(".env");
|
||||||
}
|
}
|
||||||
|
|
||||||
if file_name == "docker-compose.yml" {
|
if file_name == "docker-compose.yml" || file_name == "compose.yml" {
|
||||||
return input.with_file_name("docker-compose.override.yml");
|
return input.with_file_name("compose.override.yml");
|
||||||
}
|
}
|
||||||
if file_name == "docker-compose.yaml" {
|
if file_name == "docker-compose.yaml" || file_name == "compose.yaml" {
|
||||||
return input.with_file_name("docker-compose.override.yaml");
|
return input.with_file_name("compose.override.yaml");
|
||||||
}
|
}
|
||||||
|
|
||||||
if file_name.ends_with(".example.json") {
|
if file_name.ends_with(".example.json") {
|
||||||
return input.with_file_name(file_name.replace(".example.json", ".json"));
|
return input.with_file_name(file_name.replace(".example.json", ".json"));
|
||||||
}
|
}
|
||||||
if file_name.ends_with(".template.json") {
|
if file_name.ends_with(".template.json") {
|
||||||
return input.with_file_name(file_name.replace(".template.json", ".json"));
|
return input.with_file_name(file_name.replace(".template.json", ".json"));
|
||||||
}
|
}
|
||||||
|
|
||||||
input.with_extension(format!(
|
input.with_extension(format!(
|
||||||
"{}.out",
|
"{}.out",
|
||||||
input.extension().unwrap_or_default().to_string_lossy()
|
input.extension().unwrap_or_default().to_string_lossy()
|
||||||
@@ -98,7 +98,8 @@ fn main() -> anyhow::Result<()> {
|
|||||||
let mut app = App::new(vars);
|
let mut app = App::new(vars);
|
||||||
|
|
||||||
// Terminal lifecycle
|
// Terminal lifecycle
|
||||||
enable_raw_mode().map_err(|e| MouldError::Terminal(format!("Failed to enable raw mode: {}", e)))?;
|
enable_raw_mode()
|
||||||
|
.map_err(|e| MouldError::Terminal(format!("Failed to enable raw mode: {}", e)))?;
|
||||||
let mut stdout = io::stdout();
|
let mut stdout = io::stdout();
|
||||||
execute!(stdout, EnterAlternateScreen, EnableMouseCapture)
|
execute!(stdout, EnterAlternateScreen, EnableMouseCapture)
|
||||||
.map_err(|e| MouldError::Terminal(format!("Failed to enter alternate screen: {}", e)))?;
|
.map_err(|e| MouldError::Terminal(format!("Failed to enter alternate screen: {}", e)))?;
|
||||||
@@ -106,7 +107,13 @@ fn main() -> anyhow::Result<()> {
|
|||||||
let mut terminal = Terminal::new(backend)
|
let mut terminal = Terminal::new(backend)
|
||||||
.map_err(|e| MouldError::Terminal(format!("Failed to create terminal backend: {}", e)))?;
|
.map_err(|e| MouldError::Terminal(format!("Failed to create terminal backend: {}", e)))?;
|
||||||
|
|
||||||
let mut runner = AppRunner::new(&mut terminal, &mut app, &config, &output_path, handler.as_ref());
|
let mut runner = AppRunner::new(
|
||||||
|
&mut terminal,
|
||||||
|
&mut app,
|
||||||
|
&config,
|
||||||
|
&output_path,
|
||||||
|
handler.as_ref(),
|
||||||
|
);
|
||||||
let res = runner.run();
|
let res = runner.run();
|
||||||
|
|
||||||
// Restoration
|
// Restoration
|
||||||
@@ -115,14 +122,15 @@ fn main() -> anyhow::Result<()> {
|
|||||||
terminal.backend_mut(),
|
terminal.backend_mut(),
|
||||||
LeaveAlternateScreen,
|
LeaveAlternateScreen,
|
||||||
DisableMouseCapture
|
DisableMouseCapture
|
||||||
).ok();
|
)
|
||||||
|
.ok();
|
||||||
terminal.show_cursor().ok();
|
terminal.show_cursor().ok();
|
||||||
|
|
||||||
match res {
|
match res {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
info!("Successfully finished mould session.");
|
info!("Successfully finished mould session.");
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Application error during run: {}", e);
|
error!("Application error during run: {}", e);
|
||||||
Err(e.into())
|
Err(e.into())
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ use crate::app::{App, Mode};
|
|||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::format::FormatHandler;
|
use crate::format::FormatHandler;
|
||||||
use crossterm::event::{self, Event, KeyCode, KeyEvent};
|
use crossterm::event::{self, Event, KeyCode, KeyEvent};
|
||||||
use ratatui::backend::Backend;
|
|
||||||
use ratatui::Terminal;
|
use ratatui::Terminal;
|
||||||
|
use ratatui::backend::Backend;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use tui_input::backend::crossterm::EventHandler;
|
use tui_input::backend::crossterm::EventHandler;
|
||||||
|
|||||||
81
src/ui.rs
81
src/ui.rs
@@ -1,11 +1,11 @@
|
|||||||
use crate::app::{App, Mode};
|
use crate::app::{App, Mode};
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
|
Frame,
|
||||||
layout::{Constraint, Direction, Layout},
|
layout::{Constraint, Direction, Layout},
|
||||||
style::{Modifier, Style},
|
style::{Modifier, Style},
|
||||||
text::{Line, Span},
|
text::{Line, Span},
|
||||||
widgets::{Block, BorderType, Borders, List, ListItem, ListState, Paragraph},
|
widgets::{Block, BorderType, Borders, List, ListItem, ListState, Paragraph},
|
||||||
Frame,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Renders the main application interface using ratatui.
|
/// Renders the main application interface using ratatui.
|
||||||
@@ -43,15 +43,6 @@ pub fn draw(f: &mut Frame, app: &mut App, config: &Config) {
|
|||||||
])
|
])
|
||||||
.split(outer_layout[1]);
|
.split(outer_layout[1]);
|
||||||
|
|
||||||
// Calculate alignment for the key-value separator based on the longest key.
|
|
||||||
let max_key_len = app
|
|
||||||
.vars
|
|
||||||
.iter()
|
|
||||||
.map(|v| v.key.len())
|
|
||||||
.max()
|
|
||||||
.unwrap_or(20)
|
|
||||||
.min(40);
|
|
||||||
|
|
||||||
// Build the interactive list of configuration variables.
|
// Build the interactive list of configuration variables.
|
||||||
let items: Vec<ListItem> = app
|
let items: Vec<ListItem> = app
|
||||||
.vars
|
.vars
|
||||||
@@ -81,14 +72,25 @@ pub fn draw(f: &mut Frame, app: &mut App, config: &Config) {
|
|||||||
Style::default().fg(theme.text())
|
Style::default().fg(theme.text())
|
||||||
};
|
};
|
||||||
|
|
||||||
let line = Line::from(vec![
|
// Path styling for nested keys (e.g., a.b.c)
|
||||||
Span::styled(
|
let mut key_spans = Vec::new();
|
||||||
format!(" {:<width$} ", var.key, width = max_key_len),
|
if let Some(last_dot) = var.key.rfind('.') {
|
||||||
key_style,
|
let path = &var.key[..=last_dot];
|
||||||
),
|
let key = &var.key[last_dot + 1..];
|
||||||
Span::styled("│ ", Style::default().fg(theme.surface1())),
|
|
||||||
Span::styled(format!(" {} ", val), value_style),
|
let path_style = if is_selected {
|
||||||
]);
|
Style::default()
|
||||||
|
.fg(theme.crust())
|
||||||
|
.add_modifier(Modifier::DIM)
|
||||||
|
} else {
|
||||||
|
Style::default().fg(theme.surface1())
|
||||||
|
};
|
||||||
|
|
||||||
|
key_spans.push(Span::styled(path, path_style));
|
||||||
|
key_spans.push(Span::styled(key, key_style));
|
||||||
|
} else {
|
||||||
|
key_spans.push(Span::styled(&var.key, key_style));
|
||||||
|
}
|
||||||
|
|
||||||
let item_style = if is_selected {
|
let item_style = if is_selected {
|
||||||
Style::default().bg(theme.blue())
|
Style::default().bg(theme.blue())
|
||||||
@@ -96,7 +98,25 @@ pub fn draw(f: &mut Frame, app: &mut App, config: &Config) {
|
|||||||
Style::default().fg(theme.text())
|
Style::default().fg(theme.text())
|
||||||
};
|
};
|
||||||
|
|
||||||
ListItem::new(line).style(item_style)
|
// Two-line layout for better readability:
|
||||||
|
// Line 1: Key (path.key)
|
||||||
|
// Line 2: Value
|
||||||
|
let lines = vec![
|
||||||
|
Line::from(key_spans),
|
||||||
|
Line::from(vec![
|
||||||
|
Span::styled(
|
||||||
|
" └─ ",
|
||||||
|
if is_selected {
|
||||||
|
Style::default().fg(theme.crust())
|
||||||
|
} else {
|
||||||
|
Style::default().fg(theme.surface1())
|
||||||
|
},
|
||||||
|
),
|
||||||
|
Span::styled(val, value_style),
|
||||||
|
]),
|
||||||
|
];
|
||||||
|
|
||||||
|
ListItem::new(lines).style(item_style)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@@ -105,7 +125,11 @@ pub fn draw(f: &mut Frame, app: &mut App, config: &Config) {
|
|||||||
.borders(Borders::ALL)
|
.borders(Borders::ALL)
|
||||||
.border_type(BorderType::Rounded)
|
.border_type(BorderType::Rounded)
|
||||||
.title(" Config Variables ")
|
.title(" Config Variables ")
|
||||||
.title_style(Style::default().fg(theme.mauve()).add_modifier(Modifier::BOLD))
|
.title_style(
|
||||||
|
Style::default()
|
||||||
|
.fg(theme.mauve())
|
||||||
|
.add_modifier(Modifier::BOLD),
|
||||||
|
)
|
||||||
.border_style(Style::default().fg(theme.surface1())),
|
.border_style(Style::default().fg(theme.surface1())),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -140,7 +164,11 @@ pub fn draw(f: &mut Frame, app: &mut App, config: &Config) {
|
|||||||
.borders(Borders::ALL)
|
.borders(Borders::ALL)
|
||||||
.border_type(BorderType::Rounded)
|
.border_type(BorderType::Rounded)
|
||||||
.title(input_title)
|
.title(input_title)
|
||||||
.title_style(Style::default().fg(theme.peach()).add_modifier(Modifier::BOLD))
|
.title_style(
|
||||||
|
Style::default()
|
||||||
|
.fg(theme.peach())
|
||||||
|
.add_modifier(Modifier::BOLD),
|
||||||
|
)
|
||||||
.border_style(Style::default().fg(input_border_color)),
|
.border_style(Style::default().fg(input_border_color)),
|
||||||
);
|
);
|
||||||
f.render_widget(input, chunks[2]);
|
f.render_widget(input, chunks[2]);
|
||||||
@@ -171,10 +199,13 @@ pub fn draw(f: &mut Frame, app: &mut App, config: &Config) {
|
|||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
let status_msg = app.status_message.as_deref().unwrap_or_else(|| match app.mode {
|
let status_msg = app
|
||||||
Mode::Normal => " navigation | i: edit | :w: save | :q: quit ",
|
.status_message
|
||||||
Mode::Insert => " Esc: back to normal | Enter: commit ",
|
.as_deref()
|
||||||
});
|
.unwrap_or_else(|| match app.mode {
|
||||||
|
Mode::Normal => " navigation | i: edit | :w: save | :q: quit ",
|
||||||
|
Mode::Insert => " Esc: back to normal | Enter: commit ",
|
||||||
|
});
|
||||||
|
|
||||||
let status_line = Line::from(vec![
|
let status_line = Line::from(vec![
|
||||||
Span::styled(mode_str, mode_style),
|
Span::styled(mode_str, mode_style),
|
||||||
|
|||||||
Reference in New Issue
Block a user