generated from GarandPLG/rust-flake-template
init
This commit is contained in:
Generated
+1826
-1
File diff suppressed because it is too large
Load Diff
+4
-1
@@ -1,6 +1,9 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rust-flake-template" # change the default name to your project name
|
name = "war_in_tunnels"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
clap = { version = "4.5.53", features = ["derive"] }
|
||||||
|
crossterm = "0.29.0"
|
||||||
|
ratatui = "0.30.0"
|
||||||
|
|||||||
+16
-6
@@ -1,14 +1,24 @@
|
|||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
rustPlatform,
|
rustPlatform,
|
||||||
packageName,
|
|
||||||
pkg-config,
|
pkg-config,
|
||||||
# add nixpkgs if your dependencies requires system libraries
|
|
||||||
}:
|
}:
|
||||||
rustPlatform.buildRustPackage {
|
rustPlatform.buildRustPackage {
|
||||||
name = "${packageName}";
|
name = "war-in-tunnels";
|
||||||
|
pname = "war-in-tunnels";
|
||||||
|
version = "0.1.0";
|
||||||
|
|
||||||
src = ./.;
|
src = ./.;
|
||||||
# buildInputs = [ ]; <-- add nixpkgs if your dependencies requires system libraries
|
# buildInputs = [ ];
|
||||||
nativeBuildInputs = [ pkg-config ];
|
nativeBuildInputs = [pkg-config];
|
||||||
cargoHash = lib.fakeHash; # <-- Put your real hash here after failed nix build
|
cargoHash = lib.fakeHash;
|
||||||
|
|
||||||
|
meta = {
|
||||||
|
description = "TUI underground game";
|
||||||
|
homepage = "https://gitea.garandplg.com/GarandPLG/war-in-tunnels";
|
||||||
|
license = lib.licenses.mit;
|
||||||
|
maintainers = [
|
||||||
|
"Garand_PLG"
|
||||||
|
];
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
description = "Basic rust flake for development and production";
|
description = "TUI underground game";
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
||||||
@@ -18,14 +18,12 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs =
|
outputs = {
|
||||||
{
|
|
||||||
self,
|
self,
|
||||||
nixpkgs,
|
nixpkgs,
|
||||||
naersk,
|
naersk,
|
||||||
fenix,
|
fenix,
|
||||||
}:
|
}: let
|
||||||
let
|
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
|
||||||
@@ -36,23 +34,16 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
|
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
|
||||||
packageName = cargoToml.package.name;
|
|
||||||
packageVersion = cargoToml.package.version;
|
packageVersion = cargoToml.package.version;
|
||||||
# you can list your other dependencies
|
in {
|
||||||
# [dependency_name]Version = cargoToml.dependencies.[dependency_name];
|
|
||||||
# ...
|
|
||||||
in
|
|
||||||
{
|
|
||||||
packages.${system} = {
|
packages.${system} = {
|
||||||
default = pkgs.callPackage ./default.nix {
|
default = pkgs.callPackage ./default.nix {};
|
||||||
packageName = packageName;
|
|
||||||
};
|
|
||||||
|
|
||||||
develop = naerskLib.buildPackage {
|
develop = naerskLib.buildPackage {
|
||||||
name = "${packageName}";
|
name = "war-in-tunnels";
|
||||||
src = ./.;
|
src = ./.;
|
||||||
# buildInputs = with pkgs; []; <-- add nixpkgs if your dependencies requires system libraries
|
# buildInputs = with pkgs; [];
|
||||||
nativeBuildInputs = with pkgs; [ pkg-config ];
|
nativeBuildInputs = with pkgs; [pkg-config];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -60,12 +51,11 @@
|
|||||||
env.RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
|
env.RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
rustToolchain
|
rustToolchain
|
||||||
# pkgs. ... <-- add nixpkgs if your dependencies requires system libraries
|
|
||||||
];
|
];
|
||||||
nativeBuildInputs = with pkgs; [ pkg-config ];
|
nativeBuildInputs = with pkgs; [pkg-config];
|
||||||
|
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
echo "${packageName} v${packageVersion}"
|
echo "War in Tunnels v${packageVersion}"
|
||||||
echo "[you can list your other dependencies here]"
|
echo "[you can list your other dependencies here]"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Commands:"
|
echo "Commands:"
|
||||||
|
|||||||
+69
@@ -0,0 +1,69 @@
|
|||||||
|
use crossterm::event::{self, KeyCode, KeyEvent, KeyEventKind};
|
||||||
|
use ratatui::{DefaultTerminal, Frame, buffer::Buffer, layout::Rect, widgets::Widget};
|
||||||
|
use std::{
|
||||||
|
io::Result,
|
||||||
|
sync::mpsc::{self, Receiver},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub struct App {
|
||||||
|
pub exit: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum Event {
|
||||||
|
Input(KeyEvent),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl App {
|
||||||
|
pub fn run(&mut self, terminal: &mut DefaultTerminal, rx: Receiver<Event>) -> Result<()> {
|
||||||
|
while !self.exit {
|
||||||
|
terminal.draw(|frame: &mut Frame<'_>| self.draw(frame))?;
|
||||||
|
|
||||||
|
let event: Event = match rx.recv() {
|
||||||
|
Ok(ev) => ev,
|
||||||
|
Err(_) => break,
|
||||||
|
};
|
||||||
|
match event {
|
||||||
|
Event::Input(key_event) => self.handle_key_event(key_event)?,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw(&self, frame: &mut Frame<'_>) {
|
||||||
|
frame.render_widget(self, frame.area());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_key_event(&mut self, key_event: KeyEvent) -> Result<()> {
|
||||||
|
if key_event.kind == KeyEventKind::Press && key_event.code == KeyCode::Char('q') {
|
||||||
|
self.exit = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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() {
|
||||||
|
Ok(ev) => {
|
||||||
|
if let event::Event::Key(key_event) = ev {
|
||||||
|
if tx.send(Event::Input(key_event)).is_err() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
use clap::Parser;
|
||||||
|
|
||||||
|
#[derive(Parser, Debug)]
|
||||||
|
#[command(version, about = "War in Tunnels", long_about = "War in Tunnels")]
|
||||||
|
pub struct Cli {}
|
||||||
|
|
||||||
|
pub fn get_args() -> Cli {
|
||||||
|
Cli::parse()
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
pub mod app;
|
||||||
|
// pub mod cli;
|
||||||
+26
-2
@@ -1,3 +1,27 @@
|
|||||||
fn main() {
|
use ratatui::{Terminal, prelude::CrosstermBackend};
|
||||||
println!("Hello, world!");
|
use std::{
|
||||||
|
io::{Result, Stdout},
|
||||||
|
sync::mpsc::{self, Sender},
|
||||||
|
thread,
|
||||||
|
};
|
||||||
|
use war_in_tunnels::{
|
||||||
|
app::{App, Event, handle_input_events},
|
||||||
|
// cli::{Cli, get_args},
|
||||||
|
};
|
||||||
|
|
||||||
|
fn main() -> Result<()> {
|
||||||
|
// let args: Cli = get_args();
|
||||||
|
let mut terminal: Terminal<CrosstermBackend<Stdout>> = ratatui::init();
|
||||||
|
let mut app: App = App { exit: false };
|
||||||
|
|
||||||
|
let (event_tx, event_rx) = mpsc::channel::<Event>();
|
||||||
|
|
||||||
|
let tx_to_input_events: Sender<Event> = event_tx.clone();
|
||||||
|
thread::spawn(move || {
|
||||||
|
handle_input_events(tx_to_input_events);
|
||||||
|
});
|
||||||
|
|
||||||
|
let app_result: Result<()> = app.run(&mut terminal, event_rx);
|
||||||
|
ratatui::restore();
|
||||||
|
app_result
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user