generated from GarandPLG/rust-flake-template
Drop crossterm delete App add CLI defaults
Remove the crossterm dependency and its input handling, delete the now‑unused App module, and provide default values for all command‑line options.
This commit is contained in:
Generated
-1
@@ -1521,7 +1521,6 @@ name = "war_in_tunnels"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"crossterm",
|
||||
"ratatui",
|
||||
]
|
||||
|
||||
|
||||
@@ -5,5 +5,4 @@ edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.5.53", features = ["derive"] }
|
||||
crossterm = "0.29.0"
|
||||
ratatui = "0.30.0"
|
||||
|
||||
+15
-20
@@ -1,5 +1,7 @@
|
||||
use crossterm::event::{self, KeyCode, KeyEvent, KeyEventKind};
|
||||
use ratatui::{DefaultTerminal, Frame, buffer::Buffer, layout::Rect, widgets::Widget};
|
||||
use ratatui::{
|
||||
DefaultTerminal, Frame,
|
||||
crossterm::event::{self, KeyCode, KeyEvent, KeyEventKind},
|
||||
};
|
||||
use std::{
|
||||
io::Result,
|
||||
sync::mpsc::{self, Receiver},
|
||||
@@ -7,16 +9,17 @@ use std::{
|
||||
|
||||
pub struct App {
|
||||
pub exit: bool,
|
||||
// pub username: String,
|
||||
// pub game_mode: String,
|
||||
// pub map_width: u8,
|
||||
// pub map_height: u8,
|
||||
// pub perk_deck: String,
|
||||
// pub starting_wood: u8,
|
||||
// pub starting_iron: u8,
|
||||
// pub supply_limit: u8,
|
||||
// pub xp_modifier: f32,
|
||||
// pub skill_points_limit: u16,
|
||||
pub default_window: String,
|
||||
pub username: String,
|
||||
pub game_mode: String,
|
||||
pub map_width: u8,
|
||||
pub map_height: u8,
|
||||
pub perk_deck: String,
|
||||
pub starting_wood: u8,
|
||||
pub starting_iron: u8,
|
||||
pub supply_limit: u8,
|
||||
pub xp_modifier: f32,
|
||||
pub skill_points_limit: u16,
|
||||
}
|
||||
|
||||
pub enum Event {
|
||||
@@ -53,14 +56,6 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
impl Widget for &App {
|
||||
fn render(self, area: Rect, buf: &mut Buffer)
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_input_events(tx: mpsc::Sender<Event>) {
|
||||
loop {
|
||||
match event::read() {
|
||||
@@ -0,0 +1,5 @@
|
||||
pub mod app;
|
||||
pub mod widget;
|
||||
pub mod widgets;
|
||||
|
||||
pub use app::{App, Event, handle_input_events};
|
||||
@@ -0,0 +1,14 @@
|
||||
use ratatui::{buffer::Buffer, layout::Rect, widgets::Widget};
|
||||
|
||||
use crate::app::{App, widgets::main_menu_widget};
|
||||
|
||||
impl Widget for &App {
|
||||
fn render(self, area: Rect, buf: &mut Buffer)
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
if self.default_window == "main_menu" {
|
||||
main_menu_widget(area, buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
use ratatui::{
|
||||
buffer::Buffer,
|
||||
layout::{Alignment, Constraint, Layout, Rect},
|
||||
style::{Color, Stylize},
|
||||
text::Line,
|
||||
widgets::{Block, Borders, Paragraph, Widget},
|
||||
};
|
||||
|
||||
pub fn main_menu_widget(area: Rect, buf: &mut Buffer) {
|
||||
let vertical_layout: Layout =
|
||||
Layout::vertical([Constraint::Percentage(90), Constraint::Percentage(10)]);
|
||||
|
||||
let [main_menu_area, keybindings_area] = vertical_layout.areas(area);
|
||||
|
||||
let title_text: String = vec![
|
||||
r" __ __ _ _____ _ ",
|
||||
r"/ / /\ \ \__ _ _ __ (_)_ __ /__ \_ _ _ __ _ __ ___| |___",
|
||||
r"\ \/ \/ / _` | '__| | | '_ \ / /\/ | | | '_ \| '_ \ / _ \ / __|",
|
||||
r" \ /\ / (_| | | | | | | | / / | |_| | | | | | | | __/ \__ \",
|
||||
r" \/ \/ \__,_|_| |_|_| |_| \/ \__,_|_| |_|_| |_|\___|_|___/",
|
||||
]
|
||||
.join("\n");
|
||||
|
||||
let title: Paragraph<'_> = Paragraph::new(title_text)
|
||||
.alignment(Alignment::Center)
|
||||
.style(Color::Yellow)
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::LEFT | Borders::RIGHT | Borders::TOP)
|
||||
.style(Color::Gray),
|
||||
);
|
||||
|
||||
title.render(main_menu_area, buf);
|
||||
|
||||
let keybindings_text: Vec<Line<'_>> =
|
||||
vec![Line::from_iter(["q".bold().red(), "\t - Quit".into()])];
|
||||
|
||||
let keybindings: Paragraph<'_> = Paragraph::new(keybindings_text)
|
||||
.alignment(Alignment::Left)
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.title("[ Keybinding ]"),
|
||||
);
|
||||
|
||||
keybindings.render(keybindings_area, buf);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
pub mod main_menu;
|
||||
|
||||
pub use main_menu::main_menu_widget;
|
||||
+64
-10
@@ -3,37 +3,91 @@ use clap::Parser;
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about = "War in Tunnels", long_about = "War in Tunnels")]
|
||||
pub struct Cli {
|
||||
#[arg(long, help = "Username", value_name = "String")]
|
||||
#[arg(
|
||||
long,
|
||||
help = "Default window",
|
||||
value_name = "main_menu | skirmish | skills_config | perk_decks | settings",
|
||||
default_value = "main_menu"
|
||||
)]
|
||||
pub default_window: String,
|
||||
|
||||
#[arg(
|
||||
long,
|
||||
help = "Username",
|
||||
value_name = "String",
|
||||
default_value = "Player"
|
||||
)]
|
||||
pub username: String,
|
||||
|
||||
#[arg(long, help = "Game mode", value_name = "LastManStanding or FrontLines")]
|
||||
#[arg(
|
||||
long,
|
||||
help = "Game mode",
|
||||
value_name = "LastManStanding or FrontLines",
|
||||
default_value = "LastManStanding"
|
||||
)]
|
||||
pub game_mode: String,
|
||||
|
||||
#[arg(long, help = "Map width", value_name = "Positive integer [20; 100]")]
|
||||
#[arg(
|
||||
long,
|
||||
help = "Map width",
|
||||
value_name = "Positive integer [20; 100]",
|
||||
default_value = "50"
|
||||
)]
|
||||
pub map_width: u8,
|
||||
|
||||
#[arg(long, help = "Map height", value_name = "Positive integer [11; 50]")]
|
||||
#[arg(
|
||||
long,
|
||||
help = "Map height",
|
||||
value_name = "Positive integer [11; 50]",
|
||||
default_value = "25"
|
||||
)]
|
||||
pub map_height: u8,
|
||||
|
||||
#[arg(long, help = "Perk Deck", value_name = "String (check Perk Deck tab)")]
|
||||
#[arg(
|
||||
long,
|
||||
help = "Perk Deck",
|
||||
value_name = "String (check Perk Deck tab)",
|
||||
default_value = "Silesian"
|
||||
)]
|
||||
pub perk_deck: String,
|
||||
|
||||
#[arg(long, help = "Starting wood", value_name = "Positive integer")]
|
||||
#[arg(
|
||||
long,
|
||||
help = "Starting wood",
|
||||
value_name = "Positive integer",
|
||||
default_value = "50"
|
||||
)]
|
||||
pub starting_wood: u8,
|
||||
|
||||
#[arg(long, help = "Starting iron", value_name = "Positive integer")]
|
||||
#[arg(
|
||||
long,
|
||||
help = "Starting iron",
|
||||
value_name = "Positive integer",
|
||||
default_value = "25"
|
||||
)]
|
||||
pub starting_iron: u8,
|
||||
|
||||
#[arg(long, help = "Supply limit", value_name = "Positive integer")]
|
||||
#[arg(
|
||||
long,
|
||||
help = "Supply limit",
|
||||
value_name = "Positive integer",
|
||||
default_value = "99"
|
||||
)]
|
||||
pub supply_limit: u8,
|
||||
|
||||
#[arg(long, help = "XP modifier", value_name = "Float [0.5; 2.0]")]
|
||||
#[arg(
|
||||
long,
|
||||
help = "XP modifier",
|
||||
value_name = "Float [0.5; 2.0]",
|
||||
default_value = "1.0"
|
||||
)]
|
||||
pub xp_modifier: f32,
|
||||
|
||||
#[arg(
|
||||
long,
|
||||
help = "Skill points limit",
|
||||
value_name = "Positive integer [120; 690]"
|
||||
value_name = "Positive integer [120; 690]",
|
||||
default_value = "120"
|
||||
)]
|
||||
pub skill_points_limit: u16,
|
||||
}
|
||||
|
||||
+15
-1
@@ -12,7 +12,20 @@ use war_in_tunnels::{
|
||||
fn main() -> Result<()> {
|
||||
let args: Cli = get_args();
|
||||
let mut terminal: Terminal<CrosstermBackend<Stdout>> = ratatui::init();
|
||||
let mut app: App = App { exit: false };
|
||||
let mut app: App = App {
|
||||
exit: false,
|
||||
default_window: args.default_window,
|
||||
username: args.username,
|
||||
game_mode: args.game_mode,
|
||||
map_width: args.map_width,
|
||||
map_height: args.map_height,
|
||||
perk_deck: args.perk_deck,
|
||||
starting_wood: args.starting_wood,
|
||||
starting_iron: args.starting_iron,
|
||||
supply_limit: args.supply_limit,
|
||||
xp_modifier: args.xp_modifier,
|
||||
skill_points_limit: args.skill_points_limit,
|
||||
};
|
||||
|
||||
let (event_tx, event_rx) = mpsc::channel::<Event>();
|
||||
|
||||
@@ -23,5 +36,6 @@ fn main() -> Result<()> {
|
||||
|
||||
let app_result: Result<()> = app.run(&mut terminal, event_rx);
|
||||
ratatui::restore();
|
||||
|
||||
app_result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user