1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-01-24 00:46:51 +00:00
mycorrhiza/shroom/shroom.go

43 lines
1.1 KiB
Go
Raw Normal View History

2022-02-20 09:27:30 +00:00
// Package shroom provides utilities for hypha manipulation.
//
// Some of them are wrappers around functions provided by package hyphae. They manage history for you.
2021-02-20 14:03:54 +00:00
package shroom
import (
"errors"
"github.com/bouncepaw/mycorrhiza/hyphae"
"github.com/bouncepaw/mycorrhiza/views"
"github.com/bouncepaw/mycomarkup/v3/globals"
2021-02-20 14:03:54 +00:00
)
func init() {
2022-02-19 08:26:38 +00:00
// TODO: clean this complete and utter mess
2021-05-13 18:13:11 +00:00
globals.HyphaExists = func(hyphaName string) bool {
switch hyphae.ByName(hyphaName).(type) {
case *hyphae.EmptyHypha:
return false
default:
return true
}
2021-02-20 14:03:54 +00:00
}
2021-05-13 18:13:11 +00:00
globals.HyphaAccess = func(hyphaName string) (rawText, binaryBlock string, err error) {
switch h := hyphae.ByName(hyphaName).(type) {
case *hyphae.EmptyHypha:
err = errors.New("Hypha " + hyphaName + " does not exist")
2022-02-19 08:26:38 +00:00
case *hyphae.TextualHypha:
rawText, err = FetchTextFile(h)
case *hyphae.MediaHypha:
rawText, err = FetchTextFile(h)
2022-03-20 21:24:40 +00:00
binaryBlock = views.MediaRaw(h)
2021-02-20 14:03:54 +00:00
}
return
}
2021-05-13 18:13:11 +00:00
globals.HyphaIterate = func(λ func(string)) {
2021-02-20 14:03:54 +00:00
for h := range hyphae.YieldExistingHyphae() {
λ(h.CanonicalName())
2021-02-20 14:03:54 +00:00
}
}
}