2022-02-20 12:27:30 +03: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 19:03:54 +05:00
|
|
|
package shroom
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/bouncepaw/mycorrhiza/hyphae"
|
2021-02-20 20:48:51 +05:00
|
|
|
"github.com/bouncepaw/mycorrhiza/views"
|
2021-05-12 18:34:24 +05:00
|
|
|
|
2021-10-05 23:10:28 +03:00
|
|
|
"github.com/bouncepaw/mycomarkup/v3/globals"
|
2021-02-20 19:03:54 +05:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2022-02-19 11:26:38 +03:00
|
|
|
// TODO: clean this complete and utter mess
|
2021-05-13 23:13:11 +05:00
|
|
|
globals.HyphaExists = func(hyphaName string) bool {
|
2022-02-04 19:56:28 +05:00
|
|
|
switch hyphae.ByName(hyphaName).(type) {
|
|
|
|
case *hyphae.EmptyHypha:
|
|
|
|
return false
|
|
|
|
default:
|
|
|
|
return true
|
|
|
|
}
|
2021-02-20 19:03:54 +05:00
|
|
|
}
|
2021-05-13 23:13:11 +05:00
|
|
|
globals.HyphaAccess = func(hyphaName string) (rawText, binaryBlock string, err error) {
|
2022-02-04 19:56:28 +05:00
|
|
|
switch h := hyphae.ByName(hyphaName).(type) {
|
|
|
|
case *hyphae.EmptyHypha:
|
|
|
|
err = errors.New("Hypha " + hyphaName + " does not exist")
|
2022-02-19 11:26:38 +03:00
|
|
|
case *hyphae.TextualHypha:
|
|
|
|
rawText, err = FetchTextFile(h)
|
|
|
|
case *hyphae.MediaHypha:
|
|
|
|
rawText, err = FetchTextFile(h)
|
2022-03-21 00:24:40 +03:00
|
|
|
binaryBlock = views.MediaRaw(h)
|
2021-02-20 19:03:54 +05:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2021-05-13 23:13:11 +05:00
|
|
|
globals.HyphaIterate = func(λ func(string)) {
|
2021-02-20 19:03:54 +05:00
|
|
|
for h := range hyphae.YieldExistingHyphae() {
|
2022-02-04 02:47:36 +05:00
|
|
|
λ(h.CanonicalName())
|
2021-02-20 19:03:54 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|