1
0
Fork 0
forked from fun/fun

Added base64 example. Lot of refactoring. (0.37.49)

This commit is contained in:
Johannes Findeisen 2026-01-14 01:57:57 +01:00
commit 75538e6142
17 changed files with 439 additions and 45 deletions

View file

@ -0,0 +1,24 @@
#!/usr/bin/env fun
/*
* This file is part of the Fun programming language.
* https://fun-lang.xyz/
*
* Copyright 2025 Johannes Findeisen <you@hanez.org>
* Licensed under the terms of the Apache-2.0 license.
* https://opensource.org/license/apache-2-0
*
* Added: 2026-01-12
*/
// Demonstrates the the console prompt.
include <io/console.fun>
input = Console().prompt("fun> ")
print("You entered: " + input)
/* Possible output:
fun> Fun!
You entered: Fun!
*/

View file

@ -0,0 +1,47 @@
#!/usr/bin/env fun
/*
* This file is part of the Fun programming language.
* https://fun-lang.xyz/
*
* Copyright 2025 Johannes Findeisen <you@hanez.org>
* Licensed under the terms of the Apache-2.0 license.
* https://opensource.org/license/apache-2-0
*
* Added: 2025-10-02
*/
/*
* Interactive input example using input() and Console wrapper.
*/
#include <io/console.fun>
print("=== input() builtin ===")
name = input("Enter your name: ")
print(join(["Hello, ", name, "!"], ""))
print("=== Console class ===")
c = Console()
city = c.ask("Your city")
print(join(["Nice to meet you from ", city], ""))
yn = c.ask_yes_no("Do you like Fun?")
if yn
print("Great! 🎉")
else
print("Give it a try, it grows on you.")
/* Input given:
Enter your name: Hanez
Your city: Universe
Do you like Fun? [y/n]: y
*/
/* Expected output:
=== input() builtin ===
Hello, Hanez!
=== Console class ===
Nice to meet you from Universe
Great! 🎉
*/

View file

@ -0,0 +1,29 @@
#!/usr/bin/env fun
/*
* This file is part of the Fun programming language.
* https://fun-lang.xyz/
*
* Example: Demonstrate hidden input (no echo) for passwords.
*
* Added: 2026-01-02
*/
#include <io/console.fun>
print("=== input_hidden() example ===")
c = Console()
username = c.ask("Username")
password = c.ask_hidden("Password")
// Do not print the password; just show the username
print(join(["Hello, ", username, "!"], ""))
/* Expected output:
Username: hanez
Password:
=== input_hidden() example ===
Hello, hanez!
*/

View file

@ -0,0 +1,45 @@
#!/usr/bin/env fun
/*
* This file is part of the Fun programming language.
* https://fun-lang.xyz/
*
* Example: Demonstrate hidden input (no echo) for passwords using
* /usr/bin/chkpwd from https://git.xw3.org/hanez/chkusr for PAM authetication.
*
* Added: 2026-01-02
*/
#include <io/console.fun>
print("=== input_hidden() example with PAM authentication ===")
c = Console()
username = c.ask("Username")
password = c.ask_hidden("Password")
// Do not print the password; just show the username
print(join(["Hello, ", username, "!"], ""))
res = proc_run("chkpwd -u " + username + " -p " + password)
content = res["out"]
if (res["code"] == 0)
print("Login success!")
else
print("Login failed!")
/* Possible output:
Username: hanez
Password:
=== input_hidden() example with PAM authentication ===
Hello, hanez!
Login success!
Or:
Username: hanez
Password:
=== input_hidden() example with PAM authentication ===
Hello, hanez!
Login failed!
*/