release/0.2.0 #4

Merged
nvrl merged 3 commits from release/0.2.0 into main 2026-03-16 17:46:58 +01:00
8 changed files with 131 additions and 90 deletions
Showing only changes of commit a274938368 - Show all commits

View File

@@ -36,10 +36,6 @@ jobs:
id: check_release id: check_release
shell: bash shell: bash
run: | run: |
# Use curl to check if a release for the current TAG already exists on Gitea
# This prevents the workflow from failing if a push to main doesn't update the version
# Assuming standard Gitea API (e.g., https://gitea.example.com/api/v1/repos/{owner}/{repo}/releases/tags/{tag})
# github.repository is usually 'owner/repo'
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \ HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/tags/${{ steps.get_version.outputs.TAG }}") "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/tags/${{ steps.get_version.outputs.TAG }}")
@@ -55,7 +51,7 @@ jobs:
if: steps.check_release.outputs.EXISTS == 'false' if: steps.check_release.outputs.EXISTS == 'false'
run: | run: |
cargo build --release cargo build --release
mv target/release/cenv target/release/cenv-${{ steps.get_version.outputs.TAG }}-linux-amd64 mv target/release/mould target/release/mould-${{ steps.get_version.outputs.TAG }}-linux-amd64
- name: Create Release and Upload Asset - name: Create Release and Upload Asset
if: steps.check_release.outputs.EXISTS == 'false' if: steps.check_release.outputs.EXISTS == 'false'
@@ -67,7 +63,7 @@ jobs:
Automated release for version ${{ steps.get_version.outputs.VERSION }} Automated release for version ${{ steps.get_version.outputs.VERSION }}
Commit: ${{ github.sha }} Commit: ${{ github.sha }}
Branch: ${{ github.ref_name }} Branch: ${{ github.ref_name }}
files: target/release/cenv-${{ steps.get_version.outputs.TAG }}-linux-amd64 files: target/release/mould-${{ steps.get_version.outputs.TAG }}-linux-amd64
draft: false draft: false
prerelease: false prerelease: false
env: env:

32
Cargo.lock generated
View File

@@ -151,22 +151,6 @@ dependencies = [
"rustversion", "rustversion",
] ]
[[package]]
name = "cenv-rs"
version = "0.2.0"
dependencies = [
"clap",
"crossterm",
"dirs",
"ratatui",
"serde",
"serde_json",
"serde_yaml",
"tempfile",
"toml",
"tui-input",
]
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
version = "1.0.4" version = "1.0.4"
@@ -796,6 +780,22 @@ dependencies = [
"windows-sys", "windows-sys",
] ]
[[package]]
name = "mould"
version = "0.2.0"
dependencies = [
"clap",
"crossterm",
"dirs",
"ratatui",
"serde",
"serde_json",
"serde_yaml",
"tempfile",
"toml",
"tui-input",
]
[[package]] [[package]]
name = "nix" name = "nix"
version = "0.29.0" version = "0.29.0"

View File

@@ -1,11 +1,11 @@
[package] [package]
name = "cenv-rs" name = "mould"
version = "0.2.0" version = "0.2.0"
edition = "2024" edition = "2024"
authors = ["Nils Pukropp <nils@narl.io>"] authors = ["Nils Pukropp <nils@narl.io>"]
[[bin]] [[bin]]
name = "cenv" name = "mould"
path = "src/main.rs" path = "src/main.rs"
[dependencies] [dependencies]

View File

@@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2026 The cenv-rs Contributors Copyright (c) 2026 The mould Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@@ -1,13 +1,16 @@
# cenv-rs # mould
cenv-rs is a Rust-based Terminal User Interface (TUI) tool designed to help developers interactively generate `.env` files from `.env.example` templates. With a focus on speed and usability, it features Vim-like keybindings and out-of-the-box support for theming, defaulting to the Catppuccin Mocha palette. mould is a modern Terminal User Interface (TUI) tool designed for interactively generating and editing configuration files from templates. Whether you are setting up a `.env` file from an example, creating a `docker-compose.override.yml`, or editing nested `JSON`, `YAML`, or `TOML` configurations, mould provides a fast, Vim-inspired workflow to get your environment ready.
## Features ## Features
- Parse `.env.example` files to extract keys, default values, and comments. - **Universal Format Support**: Handle `.env`, `JSON`, `YAML`, and `TOML` seamlessly.
- Vim-like keybindings for quick navigation and editing. - **Hierarchical Flattening**: Edit nested data structures (JSON, YAML, TOML) in a flat, searchable list.
- Built-in theming support with Catppuccin Mocha as the default. - **Docker Compose Integration**: Automatically generate `docker-compose.override.yml` from `docker-compose.yml`.
- Configurable through a standard TOML file. - **Vim-inspired Workflow**: Navigate with `j`/`k`, edit with `i`, and save with `:w`.
- **Modern UI**: A polished, rounded interface featuring the Catppuccin Mocha palette.
- **Highly Configurable**: Customize keybindings and themes via a simple TOML configuration.
- **Dynamic Alignment**: Automatically aligns keys and values for perfect vertical readability.
## Installation ## Installation
@@ -21,41 +24,54 @@ Alternatively, you can build from source:
```sh ```sh
git clone <repository_url> git clone <repository_url>
cd cenv-rs cd mould
cargo build --release cargo build --release
``` ```
The binary will be installed as `mould`.
## Usage ## Usage
Navigate to a directory containing a `.env.example` file and run: Provide an input template file to start editing:
```sh ```sh
cenv-rs mould .env.example
mould docker-compose.yml
mould config.template.json -o config.json
``` ```
### Keybindings ### Keybindings (Default)
- **Normal Mode** - **Normal Mode**
- `j` / `Down`: Move selection down - `j` / `Down`: Move selection down
- `k` / `Up`: Move selection up - `k` / `Up`: Move selection up
- `i`: Edit the value of the currently selected key (Enter Insert Mode) - `i`: Edit the value of the currently selected key (Enter Insert Mode)
- `:w` or `Enter`: Save the current configuration to `.env` - `:w` or `Enter`: Save the current configuration to the output file
- `q` or `:q`: Quit the application without saving - `:q` or `q`: Quit the application
- `Esc`: Clear current prompt or return from actions - `:wq`: Save and quit
- `Esc`: Clear current command prompt
- **Insert Mode** - **Insert Mode**
- Type your value for the selected key. - Type your value for the selected key.
- `Esc`: Return to Normal Mode - Arrow keys: Navigate within the input field
- `Enter` / `Esc`: Commit the value and return to Normal Mode
## Configuration ## Configuration
cenv-rs can be configured using a `config.toml` file located in your user configuration directory (e.g., `~/.config/cenv-rs/config.toml` on Linux/macOS). mould can be configured using a `config.toml` file located in your user configuration directory (e.g., `~/.config/mould/config.toml` on Linux/macOS).
Example configuration: Example configuration:
```toml ```toml
[keybinds]
down = "j"
up = "k"
edit = "i"
save = ":w"
quit = ":q"
normal_mode = "Esc"
[theme] [theme]
# Default theme is "catppuccin_mocha"
name = "catppuccin_mocha" name = "catppuccin_mocha"
``` ```

View File

@@ -2,7 +2,7 @@ use clap::Parser;
use std::path::PathBuf; use std::path::PathBuf;
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command(author, version, about = "TUI tool to generate and edit configuration files (.env, json, yaml, toml)")] #[command(author, version, about = "mould: A TUI tool to generate and edit configuration files (.env, json, yaml, toml)")]
pub struct Cli { pub struct Cli {
/// The input template file (e.g., .env.example, config.json.template, docker-compose.yml) /// The input template file (e.g., .env.example, config.json.template, docker-compose.yml)
pub input: PathBuf, pub input: PathBuf,

View File

@@ -47,7 +47,7 @@ pub struct Config {
pub fn load_config() -> Config { pub fn load_config() -> Config {
if let Some(mut config_dir) = dirs::config_dir() { if let Some(mut config_dir) = dirs::config_dir() {
config_dir.push("cenv-rs"); config_dir.push("mould");
config_dir.push("config.toml"); config_dir.push("config.toml");
if config_dir.exists() { if config_dir.exists() {

123
src/ui.rs
View File

@@ -4,39 +4,55 @@ use ratatui::{
layout::{Constraint, Direction, Layout}, layout::{Constraint, Direction, Layout},
style::{Color, Modifier, Style}, style::{Color, Modifier, Style},
text::{Line, Span}, text::{Line, Span},
widgets::{Block, Borders, List, ListItem, ListState, Paragraph}, widgets::{Block, BorderType, Borders, List, ListItem, ListState, Paragraph},
Frame, Frame,
}; };
// Catppuccin Mocha Palette // Catppuccin Mocha Palette
const MANTLE: Color = Color::Rgb(24, 24, 37); const CRUST: Color = Color::Rgb(17, 17, 27);
const BASE: Color = Color::Rgb(30, 30, 46); const SURFACE0: Color = Color::Rgb(49, 50, 68);
const SURFACE1: Color = Color::Rgb(69, 71, 90);
const TEXT: Color = Color::Rgb(205, 214, 244); const TEXT: Color = Color::Rgb(205, 214, 244);
const BLUE: Color = Color::Rgb(137, 180, 250); const BLUE: Color = Color::Rgb(137, 180, 250);
const GREEN: Color = Color::Rgb(166, 227, 161); const GREEN: Color = Color::Rgb(166, 227, 161);
const SURFACE1: Color = Color::Rgb(69, 71, 90); const LAVENDER: Color = Color::Rgb(180, 190, 254);
const MAUVE: Color = Color::Rgb(203, 166, 247);
const PEACH: Color = Color::Rgb(250, 179, 135);
pub fn draw(f: &mut Frame, app: &mut App, _config: &Config) { pub fn draw(f: &mut Frame, app: &mut App, _config: &Config) {
let size = f.area(); let size = f.area();
// Theming
let bg_color = BASE;
let fg_color = TEXT;
let highlight_color = BLUE;
let insert_color = GREEN;
// Background // Background
let block = Block::default().style(Style::default().bg(bg_color).fg(fg_color)); f.render_widget(Block::default().style(Style::default().bg(CRUST)), size);
f.render_widget(block, size);
// Main layout with horizontal padding
let outer_layout = Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Length(1), // Left padding
Constraint::Min(0), // Content
Constraint::Length(1), // Right padding
])
.split(size);
let chunks = Layout::default() let chunks = Layout::default()
.direction(Direction::Vertical) .direction(Direction::Vertical)
.constraints([ .constraints([
Constraint::Length(1), // Top padding
Constraint::Min(3), // List Constraint::Min(3), // List
Constraint::Length(3), // Input area Constraint::Length(3), // Input area
Constraint::Length(1), // Bottom padding
Constraint::Length(1), // Status bar Constraint::Length(1), // Status bar
]) ])
.split(size); .split(outer_layout[1]);
let max_key_len = app
.vars
.iter()
.map(|v| v.key.len())
.max()
.unwrap_or(20)
.min(40); // Cap at 40 to prevent long keys from hiding values
// List // List
let items: Vec<ListItem> = app let items: Vec<ListItem> = app
@@ -44,23 +60,39 @@ pub fn draw(f: &mut Frame, app: &mut App, _config: &Config) {
.iter() .iter()
.enumerate() .enumerate()
.map(|(i, var)| { .map(|(i, var)| {
let style = if i == app.selected { let is_selected = i == app.selected;
Style::default()
.fg(bg_color) let val = if is_selected && matches!(app.mode, Mode::Insert) {
.bg(highlight_color)
.add_modifier(Modifier::BOLD)
} else {
Style::default().fg(fg_color)
};
let val = if i == app.selected && matches!(app.mode, Mode::Insert) {
app.input.value() app.input.value()
} else { } else {
&var.value &var.value
}; };
let content = format!(" {} = {} ", var.key, val); let key_style = if is_selected {
ListItem::new(Line::from(content)).style(style) Style::default().fg(CRUST).add_modifier(Modifier::BOLD)
} else {
Style::default().fg(LAVENDER)
};
let value_style = if is_selected {
Style::default().fg(CRUST)
} else {
Style::default().fg(TEXT)
};
let line = Line::from(vec![
Span::styled(format!(" {:<width$} ", var.key, width = max_key_len), key_style),
Span::styled("", Style::default().fg(SURFACE1)),
Span::styled(format!(" {} ", val), value_style),
]);
let item_style = if is_selected {
Style::default().bg(BLUE)
} else {
Style::default().fg(TEXT)
};
ListItem::new(line).style(item_style)
}) })
.collect(); .collect();
@@ -68,19 +100,15 @@ pub fn draw(f: &mut Frame, app: &mut App, _config: &Config) {
.block( .block(
Block::default() Block::default()
.borders(Borders::ALL) .borders(Borders::ALL)
.title(" Environment Variables ") .border_type(BorderType::Rounded)
.title(" Config Variables ")
.title_style(Style::default().fg(MAUVE).add_modifier(Modifier::BOLD))
.border_style(Style::default().fg(SURFACE1)), .border_style(Style::default().fg(SURFACE1)),
)
.highlight_style(
Style::default()
.fg(bg_color)
.bg(highlight_color)
.add_modifier(Modifier::BOLD),
); );
let mut state = ListState::default(); let mut state = ListState::default();
state.select(Some(app.selected)); state.select(Some(app.selected));
f.render_stateful_widget(list, chunks[0], &mut state); f.render_stateful_widget(list, chunks[1], &mut state);
// Input Area // Input Area
let current_var = app.vars.get(app.selected); let current_var = app.vars.get(app.selected);
@@ -94,8 +122,8 @@ pub fn draw(f: &mut Frame, app: &mut App, _config: &Config) {
" Input ".to_string() " Input ".to_string()
}; };
let input_color = match app.mode { let input_border_color = match app.mode {
Mode::Insert => insert_color, Mode::Insert => GREEN,
Mode::Normal => SURFACE1, Mode::Normal => SURFACE1,
}; };
@@ -103,37 +131,38 @@ pub fn draw(f: &mut Frame, app: &mut App, _config: &Config) {
let cursor_pos = app.input.visual_cursor(); let cursor_pos = app.input.visual_cursor();
let input = Paragraph::new(input_text) let input = Paragraph::new(input_text)
.style(Style::default().fg(fg_color)) .style(Style::default().fg(TEXT))
.block( .block(
Block::default() Block::default()
.borders(Borders::ALL) .borders(Borders::ALL)
.border_type(BorderType::Rounded)
.title(input_title) .title(input_title)
.border_style(Style::default().fg(input_color)), .title_style(Style::default().fg(PEACH).add_modifier(Modifier::BOLD))
.border_style(Style::default().fg(input_border_color)),
); );
f.render_widget(input, chunks[1]); f.render_widget(input, chunks[2]);
if let Mode::Insert = app.mode { if let Mode::Insert = app.mode {
f.set_cursor_position(ratatui::layout::Position::new( f.set_cursor_position(ratatui::layout::Position::new(
chunks[1].x + 1 + cursor_pos as u16, chunks[2].x + 1 + cursor_pos as u16,
chunks[1].y + 1, chunks[2].y + 1,
)); ));
} }
// Status bar // Status bar (modern pill style at the bottom)
let status_style = Style::default().bg(MANTLE).fg(fg_color);
let (mode_str, mode_style) = match app.mode { let (mode_str, mode_style) = match app.mode {
Mode::Normal => ( Mode::Normal => (
" NORMAL ", " NORMAL ",
Style::default() Style::default()
.bg(BLUE) .bg(BLUE)
.fg(bg_color) .fg(CRUST)
.add_modifier(Modifier::BOLD), .add_modifier(Modifier::BOLD),
), ),
Mode::Insert => ( Mode::Insert => (
" INSERT ", " INSERT ",
Style::default() Style::default()
.bg(GREEN) .bg(GREEN)
.fg(bg_color) .fg(CRUST)
.add_modifier(Modifier::BOLD), .add_modifier(Modifier::BOLD),
), ),
}; };
@@ -147,9 +176,9 @@ pub fn draw(f: &mut Frame, app: &mut App, _config: &Config) {
let status_line = Line::from(vec![ let status_line = Line::from(vec![
Span::styled(mode_str, mode_style), Span::styled(mode_str, mode_style),
Span::styled(format!(" {} ", status_msg), status_style), Span::styled(format!(" {} ", status_msg), Style::default().bg(SURFACE0).fg(TEXT)),
]); ]);
let status = Paragraph::new(status_line).style(status_style); let status = Paragraph::new(status_line).style(Style::default().bg(SURFACE0));
f.render_widget(status, chunks[2]); f.render_widget(status, chunks[4]);
} }