1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-01 06:37:46 +00:00

refactor: (#418)

* refactor:  move in one commit

Eveything in modules should probably be changed to `exported` defs.
The idea is to move everything first to keep proper history.

* refactor: 📝 add modules readme (wip)

* refactor:  small move

* refactor: 📝 changed nestring, updated modules readme

* refactor: 📝 to document or not to document

* fix: 🐛 themes

replaced the template to use `main` and regenerated them
from lemnos themes.

* Revert "fix: 🐛 themes"

This reverts commit 4918d3633c8d2d81950a0ed0cfd9eb84241bc886.

* refactor:  introduce sourced

- Created a source `root` in which sourcable demos are stored.
  Some might get converted to modules later on.
- Moved some files to bin too.

* fix: 🐛 fehbg.nu

* fix: 🐛 modules/after.nu

* moved some other stuff around

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
This commit is contained in:
Mel Massadian 2023-04-26 00:56:25 +02:00 committed by GitHub
parent 382696cd21
commit c47ccd42b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
128 changed files with 185 additions and 12 deletions

55
modules/fun/wordle.nu Normal file
View file

@ -0,0 +1,55 @@
# A Terminal Wordle game.
# The code is based on https://gist.github.com/huytd/6a1a6a7b34a0d0abcac00b47e3d01513 ,but slightly personalized.
# a simple termninal Wordle game!
export def main [
--unlimited(-u) # Play the game in unlimited mode.
--max_count(-M) : int = 6 # Give yourself more chances than default
--alternative_source(-a) : string = "https://raw.githubusercontent.com/charlesreid1/five-letter-words/master/sgb-words.txt" # Alternative link to provide as a word source
] {
let words = (if ($alternative_source | str substring 0..4 | str contains "http") {http get $alternative_source} else {open $alternative_source} | from ssv -n)
let word = ($words | get (random integer 0..($words | length)) | get column1)
if ((($words | each {|it| ($it.column1 | str length)}) | where $it != 5 | length) != 0 ) {
echo $"(ansi rb)Warning:(ansi reset) The words list contains words that are not length 5"
}
mut end = false
mut guess_count = 0
mut avail = "abcdefghijklmnopqrstuvyxwz"
while (not ($end)) {
$guess_count += 1
if ($guess_count <= $max_count or $unlimited) {
echo $"(ansi xterm_aquamarine1a)Enter your guess (ansi reset)\((ansi green)($guess_count)(ansi reset)/(ansi yellow)(if ($unlimited) {inf} else {$max_count})(ansi reset)\)"
mut guess = (input | str downcase )
if (((($words | where column1 =~ $guess) | length) >= 1) and ($guess | str length) == 5) {
mut out = ""
mut checked = $word
for i in ($guess | split chars) -n {
if ($i.item == ($word | str substring ($i.index)..($i.index + 1)) ) {
$out += $"(ansi green_reverse)($i.item)(ansi reset)"
$avail = ($avail | str replace $i.item $"(ansi green_reverse)($i.item)(ansi white_reverse)")
$checked = ($checked | str replace $i.item "")
} else if ( $i.item in $checked) {
$out += $"(ansi yellow_reverse)($i.item)(ansi reset)"
$avail = ($avail | str replace $i.item $"(ansi yellow_reverse)($i.item)(ansi white_reverse)")
$checked = ($checked | str replace $i.item "")
} else {
$out += $"(ansi white_reverse)($i.item)(ansi reset)"
$avail = ($avail | str replace $i.item "")
}
}
$avail = $"(ansi white_reverse)($avail)(ansi reset)"
echo $"($out) possible -> ($avail)"
if ($guess == $word) {
$end = true
echo $"(ansi xterm_green1 )You guessed right!(ansi reset)"
}
} else {
echo "please enter a valid [5 letter] word!"
$guess_count -= 1
}
} else {
echo $"(ansi yellow )You loose, the word was: (ansi red)($word)(ansi reset)"
$end = true
}
}
}