summaryrefslogtreecommitdiff
path: root/gopher/gophermap/extended.go
diff options
context:
space:
mode:
Diffstat (limited to 'gopher/gophermap/extended.go')
-rw-r--r--gopher/gophermap/extended.go47
1 files changed, 41 insertions, 6 deletions
diff --git a/gopher/gophermap/extended.go b/gopher/gophermap/extended.go
index d9fedd0..a0360fc 100644
--- a/gopher/gophermap/extended.go
+++ b/gopher/gophermap/extended.go
@@ -7,10 +7,12 @@ import (
"net/url"
"os"
"path/filepath"
+ "sort"
"strconv"
"strings"
"tildegit.org/tjp/sliderule/gopher"
+ "tildegit.org/tjp/sliderule/internal"
"tildegit.org/tjp/sliderule/internal/types"
)
@@ -139,6 +141,8 @@ const (
UserListType types.Status = '~'
// VHostListType generates a listing of virtual hosts.
+ //
+ // It is not supported in sliderule.
VHostListType types.Status = '%'
// InclusionType causes another gophermap to be included at this location.
@@ -151,8 +155,16 @@ const (
EndDocType types.Status = '.'
)
+type FileSystemSettings struct {
+ ParseExtended bool
+ Exec bool
+ ListUsers bool
+ DirMaps []string
+ DirTag string
+}
+
// Compatible builds a standards-compliant gophermap from the current extended menu.
-func (edoc ExtendedMapDocument) Compatible(cwd string) (gopher.MapDocument, string, error) {
+func (edoc ExtendedMapDocument) Compatible(cwd string, settings FileSystemSettings) (gopher.MapDocument, string, error) {
doc := gopher.MapDocument{}
title := ""
@@ -172,9 +184,32 @@ func (edoc ExtendedMapDocument) Compatible(cwd string) (gopher.MapDocument, stri
return nil, "", InvalidLine(num)
}
extensions[from] = types.Status(to[0])
- case UserListType: //TODO
- return nil, "", errors.New("User listings '~' are not supported")
- case VHostListType: //TODO
+ case UserListType:
+ if !settings.ListUsers {
+ doc = append(doc, gopher.MapItem{
+ Type: gopher.InfoMessageType,
+ Display: "~",
+ Selector: edoc.Location.Path,
+ Hostname: edoc.Location.Hostname(),
+ Port: edoc.Location.Port(),
+ })
+ }
+
+ users, err := internal.ListUsersWithHomeSubdir("public_gopher", 4)
+ if err != nil {
+ return nil, "", err
+ }
+ sort.Strings(users)
+ for _, user := range users {
+ doc = append(doc, gopher.MapItem{
+ Type: gopher.MenuType,
+ Display: "~" + user,
+ Selector: "/~" + user,
+ Hostname: edoc.Location.Hostname(),
+ Port: edoc.Location.Port(),
+ })
+ }
+ case VHostListType:
return nil, "", errors.New("Virtual host listings '%' are not supported")
case InclusionType:
location := filepath.Join(cwd, item.Selector)
@@ -183,13 +218,13 @@ func (edoc ExtendedMapDocument) Compatible(cwd string) (gopher.MapDocument, stri
return nil, "", err
}
- lines, _, err := subEdoc.Compatible(filepath.Dir(location))
+ lines, _, err := subEdoc.Compatible(filepath.Dir(location), settings)
if err != nil {
return nil, "", err
}
doc = append(doc, lines...)
case DirListType:
- dirlist, err := listDir(cwd, edoc.Location, hidden, extensions)
+ dirlist, err := listDir(cwd, edoc.Location, settings, hidden, extensions)
if err != nil {
return nil, "", err
}