7 Commits

5 changed files with 45 additions and 3 deletions

5
.dockerignore Normal file
View File

@@ -0,0 +1,5 @@
target
.git
.gameplay
*.md
screenshot.png

View File

@@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[[bin]] [[bin]]
name = "go" name = "yamlabyrinth"
path = "src/bin/go.rs" path = "src/bin/go.rs"
[lib] [lib]

11
Containerfile Normal file
View File

@@ -0,0 +1,11 @@
FROM docker.io/library/rust:1-slim AS builder
WORKDIR /src
COPY Cargo.toml Cargo.lock ./
COPY src ./src
RUN cargo build --release --bin yamlabyrinth
FROM quay.io/centos/centos:stream10-minimal
COPY --from=builder /src/target/release/yamlabyrinth /usr/local/bin/yamlabyrinth
USER nobody
WORKDIR /tmp
ENTRYPOINT ["yamlabyrinth"]

View File

@@ -11,6 +11,17 @@ There are 11 levels in the game, so if you're on level 12, you won the game!
## How to start: ## How to start:
cargo run cargo run --release
## Dependencies ## How to start (container):
docker run -it --rm quay.io/kareiva/yamlabyrinth:latest
## LLM Notice
This was a fun project to do while learning Rust syntax and pecularities. I
have mostly used Opus 4.7 with 1M context to assist me with coding.
## Author
Simonas Kareiva <skareiva@redhat.com>, <simonas@5grupe.lt>

View File

@@ -191,6 +191,19 @@ impl Editor {
} }
} }
fn delete_line(&mut self) {
let (r, _) = self.cursor;
if self.buffer.len() == 1 {
self.buffer[0].clear();
self.cursor = (0, 0);
} else {
self.buffer.remove(r);
let new_r = r.min(self.buffer.len() - 1);
let new_col = self.cursor.1.min(self.buffer[new_r].len());
self.cursor = (new_r, new_col);
}
}
fn newline(&mut self) { fn newline(&mut self) {
let (r, col) = self.cursor; let (r, col) = self.cursor;
let col = col.min(self.buffer[r].len()); let col = col.min(self.buffer[r].len());
@@ -488,6 +501,7 @@ fn step(
// Editor focus inside Game: dispatch editing keys. // Editor focus inside Game: dispatch editing keys.
if *focus == Focus::Editor && matches!(screen, Screen::Game) { if *focus == Focus::Editor && matches!(screen, Screen::Game) {
match key.code { match key.code {
KeyCode::Char('k') if ctrl => editor.delete_line(),
KeyCode::Char(c) if !ctrl => editor.insert_char(c), KeyCode::Char(c) if !ctrl => editor.insert_char(c),
KeyCode::Backspace => editor.backspace(), KeyCode::Backspace => editor.backspace(),
KeyCode::Delete => editor.delete(), KeyCode::Delete => editor.delete(),
@@ -707,6 +721,7 @@ fn help_widget<'a>() -> Paragraph<'a> {
\n\ \n\
[Tab] swap focus between log and editor\n\ [Tab] swap focus between log and editor\n\
[Ctrl-X] grade your YAML\n\ [Ctrl-X] grade your YAML\n\
[Ctrl-K] delete current line (in editor)\n\
[Ctrl-H] open this help\n\ [Ctrl-H] open this help\n\
[Esc] close help · or focus log when editing\n\ [Esc] close help · or focus log when editing\n\
[↑/↓] scroll the log (when log is focused)\n\ [↑/↓] scroll the log (when log is focused)\n\