Skip to content

Instantly share code, notes, and snippets.

@jkone27
Created January 22, 2024 11:52
Show Gist options
  • Save jkone27/1e3c7cb763517fd69be6384d4efa7494 to your computer and use it in GitHub Desktop.
Save jkone27/1e3c7cb763517fd69be6384d4efa7494 to your computer and use it in GitHub Desktop.
playing around with spectre console and images on console with F# fsharp and dotnet
//#r "nuget: Spectre.Console"
// https://mdbouk.com/how-to-create-beautiful-console-applications-with-spectre-console/
// https://www.asciiart.eu/animals/bears
//
#r "nuget: EluciusFTW.SpectreCoff"
#r "nuget: FSharp.Data"
#r "nuget: AlienFruit.FluentConsole.AsciiArt"
#r "nuget: FsHttp"
open AlienFruit.FluentConsole
open AlienFruit.FluentConsole.AsciiArt
open SpectreCoff
open FSharp.Data
open System
open FsHttp
type AnsiConsole = Spectre.Console.AnsiConsole
type CanvasImage = Spectre.Console.CanvasImage
type EmojiProvider = JsonProvider<"https://raw.githubusercontent.com/github/gemoji/master/db/emoji.json">
let getEmoji s =
let result = EmojiProvider.GetSamples()
let emojiOpt = result |> Seq.tryFind (fun e -> e.Aliases.Strings |> Seq.contains s)
emojiOpt |> Option.map (fun e -> e.Emoji)
type Color = Spectre.Console.Color
// nice default to left align all
defaultAlignment <- Left
"Hello Sexyland World" |> figlet |> toConsole
let getMenu () =
Many
[ MarkupC(Color.Green, "Hello friends,") // Use any available color
BlankLine
Pumped "Welcome to Code, Connect, Reboot!" // Use the Pumped convenience style
BL // short for BlankLine
C "Please bring ... " // short for Calm
BI
[ // short for BulletItems
C "laptop :laptop,"
P "some games," // short for Pumped
E "and some creepy stories!" ] // short for Edgy
C "See you "
P "later ... "
NL // Mixing list separators to indicate the line is also possible
Emoji "alien_monster" ]
|> toConsole
let r: string = SpectreCoff.Prompt.ask "what [red]game[/] do you want to play?"
customFiglet Left Color.Red r |> toConsole
P "is my favourite game, LOL!" |> toConsole
C "Great, now pick a character..." |> toConsole
type CharacterType =
| Hero of OutputPayload
| Wolf of OutputPayload
| Witch of OutputPayload
static member Parse(str) =
match str with
| "hero" -> Hero(Emoji "Superhero")
| "wolf" -> Wolf(Emoji "Wolf")
| "witch" -> Witch(Emoji "Mage")
| _ -> failwith "unknown"
member this.Print() =
match this with
| Hero(emoji)
| Wolf(emoji)
| Witch(emoji) -> emoji |> toConsole
Emoji "fire" |> toConsole
let character =
chooseFrom [ "hero"; "witch"; "wolf" ] "who are you going to be?"
|> CharacterType.Parse
C $"Great, your story begins {character}..."
character.Print()
P "Let the story begin."
System.Threading.Thread.Sleep(1000)
P "Let the story begin.."
System.Threading.Thread.Sleep(1000)
P "Let the story begin..."
System.Threading.Thread.Sleep(1000)
// TODO: show spinner
// let _ =
// start (fun ctx -> )
let showFish () =
let imgUrl =
"https://t4.ftcdn.net/jpg/03/14/68/67/360_F_314686744_dvRiiXuRg6b9EIA1a4wzadc8xEwFYi82.jpg"
let str = http { GET imgUrl } |> Request.send |> Response.toStream
let image =
let i = new CanvasImage(data = str)
i.MaxWidth <- 64
i
AnsiConsole.Write(image)
let showMonster () =
let i = FConsole.GetInstance()
//i.Draw
i.DrawDemo(DemoPicture.DarthVader)
showFish ()
System.Threading.Thread.Sleep(1000)
showMonster ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment