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]
|
||||
name = "rust-flake-template" # change the default name to your project name
|
||||
name = "war_in_tunnels"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.5.53", features = ["derive"] }
|
||||
crossterm = "0.29.0"
|
||||
ratatui = "0.30.0"
|
||||
|
||||
+16
-6
@@ -1,14 +1,24 @@
|
||||
{
|
||||
lib,
|
||||
rustPlatform,
|
||||
packageName,
|
||||
pkg-config,
|
||||
# add nixpkgs if your dependencies requires system libraries
|
||||
}:
|
||||
rustPlatform.buildRustPackage {
|
||||
name = "${packageName}";
|
||||
name = "war-in-tunnels";
|
||||
pname = "war-in-tunnels";
|
||||
version = "0.1.0";
|
||||
|
||||
src = ./.;
|
||||
# buildInputs = [ ]; <-- add nixpkgs if your dependencies requires system libraries
|
||||
nativeBuildInputs = [ pkg-config ];
|
||||
cargoHash = lib.fakeHash; # <-- Put your real hash here after failed nix build
|
||||
# buildInputs = [ ];
|
||||
nativeBuildInputs = [pkg-config];
|
||||
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 = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
||||
@@ -18,62 +18,52 @@
|
||||
};
|
||||
};
|
||||
|
||||
outputs =
|
||||
{
|
||||
self,
|
||||
nixpkgs,
|
||||
naersk,
|
||||
fenix,
|
||||
}:
|
||||
let
|
||||
system = "x86_64-linux";
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
naersk,
|
||||
fenix,
|
||||
}: let
|
||||
system = "x86_64-linux";
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
|
||||
rustToolchain = fenix.packages.${system}.stable.toolchain;
|
||||
naerskLib = pkgs.callPackage naersk {
|
||||
cargo = rustToolchain;
|
||||
rustc = rustToolchain;
|
||||
};
|
||||
rustToolchain = fenix.packages.${system}.stable.toolchain;
|
||||
naerskLib = pkgs.callPackage naersk {
|
||||
cargo = rustToolchain;
|
||||
rustc = rustToolchain;
|
||||
};
|
||||
|
||||
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
|
||||
packageName = cargoToml.package.name;
|
||||
packageVersion = cargoToml.package.version;
|
||||
# you can list your other dependencies
|
||||
# [dependency_name]Version = cargoToml.dependencies.[dependency_name];
|
||||
# ...
|
||||
in
|
||||
{
|
||||
packages.${system} = {
|
||||
default = pkgs.callPackage ./default.nix {
|
||||
packageName = packageName;
|
||||
};
|
||||
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
|
||||
packageVersion = cargoToml.package.version;
|
||||
in {
|
||||
packages.${system} = {
|
||||
default = pkgs.callPackage ./default.nix {};
|
||||
|
||||
develop = naerskLib.buildPackage {
|
||||
name = "${packageName}";
|
||||
src = ./.;
|
||||
# buildInputs = with pkgs; []; <-- add nixpkgs if your dependencies requires system libraries
|
||||
nativeBuildInputs = with pkgs; [ pkg-config ];
|
||||
};
|
||||
};
|
||||
|
||||
devShells.${system}.default = pkgs.mkShell {
|
||||
env.RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
|
||||
buildInputs = [
|
||||
rustToolchain
|
||||
# pkgs. ... <-- add nixpkgs if your dependencies requires system libraries
|
||||
];
|
||||
nativeBuildInputs = with pkgs; [ pkg-config ];
|
||||
|
||||
shellHook = ''
|
||||
echo "${packageName} v${packageVersion}"
|
||||
echo "[you can list your other dependencies here]"
|
||||
echo ""
|
||||
echo "Commands:"
|
||||
echo " nix build - Build production version"
|
||||
echo " nix run - Run production version"
|
||||
echo " nix build .#develop - Build development version"
|
||||
echo " nix run .#develop - Run development version"
|
||||
'';
|
||||
develop = naerskLib.buildPackage {
|
||||
name = "war-in-tunnels";
|
||||
src = ./.;
|
||||
# buildInputs = with pkgs; [];
|
||||
nativeBuildInputs = with pkgs; [pkg-config];
|
||||
};
|
||||
};
|
||||
|
||||
devShells.${system}.default = pkgs.mkShell {
|
||||
env.RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
|
||||
buildInputs = [
|
||||
rustToolchain
|
||||
];
|
||||
nativeBuildInputs = with pkgs; [pkg-config];
|
||||
|
||||
shellHook = ''
|
||||
echo "War in Tunnels v${packageVersion}"
|
||||
echo "[you can list your other dependencies here]"
|
||||
echo ""
|
||||
echo "Commands:"
|
||||
echo " nix build - Build production version"
|
||||
echo " nix run - Run production version"
|
||||
echo " nix build .#develop - Build development version"
|
||||
echo " nix run .#develop - Run development version"
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
+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() {
|
||||
println!("Hello, world!");
|
||||
use ratatui::{Terminal, prelude::CrosstermBackend};
|
||||
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