14 Commits

21 changed files with 152 additions and 100 deletions

View File

@@ -128,8 +128,9 @@ func (role ApplicationRole) Icon () tomo.Icon {
} }
} }
// RunApplication is like tomo.Run, but runs an application. If something fails // RunApplication is like tomo.Run, but runs an application. It automatically
// to initialize, an error is written to the standard logger. // sets up a backend. If something fails to initialize, an error is written to
// the standard logger.
func RunApplication (application Application) { func RunApplication (application Application) {
// TODO: see #4 // TODO: see #4
@@ -138,20 +139,22 @@ func RunApplication (application Application) {
} }
flag.Parse() flag.Parse()
err := registrar.RegisterBackend() reg := new(registrar.Registrar)
backend, err := reg.SetBackend()
if err != nil { log.Fatalln("nasin: could not register backend:", err) } if err != nil { log.Fatalln("nasin: could not register backend:", err) }
err = tomo.Run(func () { err = reg.SetTheme()
err := registrar.SetTheme()
if err != nil { log.Fatalln("nasin: could not set theme:", err) } if err != nil { log.Fatalln("nasin: could not set theme:", err) }
err = registrar.SetIconSet() err = reg.SetIconSet()
if err != nil { log.Fatalln("nasin: could not set icon set:", err) } if err != nil { log.Fatalln("nasin: could not set icon set:", err) }
err = reg.SetFaceSet()
if err != nil { log.Fatalln("nasin: could not set face set:", err) }
err = application.Init() err = application.Init()
if err != nil { log.Fatalln("nasin: could not run application:", err) } if err != nil { log.Fatalln("nasin: could not run application:", err) }
// open URLs // open URLs
args := flag.Args() args := flag.Args()
applicationOpenUrls(application, args...) applicationOpenUrls(application, args...)
}) err = backend.Run()
if err != nil { log.Fatalln("nasin: could not run application:", err) } if err != nil { log.Fatalln("nasin: could not run application:", err) }
} }

10
go.mod
View File

@@ -4,16 +4,13 @@ go 1.22.2
require ( require (
git.tebibyte.media/sashakoshka/goparse v0.2.0 git.tebibyte.media/sashakoshka/goparse v0.2.0
git.tebibyte.media/tomo/backend v0.5.1 git.tebibyte.media/tomo/backend v0.6.1
git.tebibyte.media/tomo/objects v0.20.1 git.tebibyte.media/tomo/objects v0.21.0
git.tebibyte.media/tomo/tomo v0.41.1 git.tebibyte.media/tomo/tomo v0.45.0
git.tebibyte.media/tomo/xdg v0.1.0 git.tebibyte.media/tomo/xdg v0.1.0
github.com/flopp/go-findfont v0.1.0
golang.org/x/image v0.11.0 golang.org/x/image v0.11.0
) )
replace git.tebibyte.media/tomo/tomo => /home/sashakoshka/Repos/tebibyte/tomo/tomo
require ( require (
git.tebibyte.media/tomo/typeset v0.7.1 // indirect git.tebibyte.media/tomo/typeset v0.7.1 // indirect
git.tebibyte.media/tomo/xgbkb v1.0.1 // indirect git.tebibyte.media/tomo/xgbkb v1.0.1 // indirect
@@ -21,5 +18,4 @@ require (
github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 // indirect github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 // indirect
github.com/jezek/xgb v1.1.1 // indirect github.com/jezek/xgb v1.1.1 // indirect
github.com/jezek/xgbutil v0.0.0-20231116234834-47f30c120111 // indirect github.com/jezek/xgbutil v0.0.0-20231116234834-47f30c120111 // indirect
golang.org/x/text v0.12.0 // indirect
) )

13
go.sum
View File

@@ -1,10 +1,12 @@
git.tebibyte.media/sashakoshka/goparse v0.2.0 h1:uQmKvOCV2AOlCHEDjg9uclZCXQZzq2PxaXfZ1aIMiQI= git.tebibyte.media/sashakoshka/goparse v0.2.0 h1:uQmKvOCV2AOlCHEDjg9uclZCXQZzq2PxaXfZ1aIMiQI=
git.tebibyte.media/sashakoshka/goparse v0.2.0/go.mod h1:tSQwfuD+EujRoKr6Y1oaRy74ZynatzkRLxjE3sbpCmk= git.tebibyte.media/sashakoshka/goparse v0.2.0/go.mod h1:tSQwfuD+EujRoKr6Y1oaRy74ZynatzkRLxjE3sbpCmk=
git.tebibyte.media/sashakoshka/xgbkb v1.0.0/go.mod h1:pNcE6TRO93vHd6q42SdwLSTTj25L0Yzggz7yLe0JV6Q= git.tebibyte.media/sashakoshka/xgbkb v1.0.0/go.mod h1:pNcE6TRO93vHd6q42SdwLSTTj25L0Yzggz7yLe0JV6Q=
git.tebibyte.media/tomo/backend v0.5.1 h1:u3DLVcNWNdQsIxAEGcZ+kGG7zuew8tpPbyEFBx8ehjM= git.tebibyte.media/tomo/backend v0.6.1 h1:TVbvfbcMrF8YAVGsXPQNQLCam3xuOWJmZA0B+op0ig0=
git.tebibyte.media/tomo/backend v0.5.1/go.mod h1:urnfu+D56Q9AOCZ/qp5YqkmlRRTIB5p9RbzBN7yIibQ= git.tebibyte.media/tomo/backend v0.6.1/go.mod h1:7gl0Z1V8Vcns41pXIpQt1FYlANrQf5bCboxMjTCCrgc=
git.tebibyte.media/tomo/objects v0.20.1 h1:dCMMzaHmj7w016XtTb8QWvKMHVK2Fru/2a70NqApzHQ= git.tebibyte.media/tomo/objects v0.21.0 h1:exFbzQPQhGIVQK5BCDg69ZV96zMamV50G4GRsnK+yfA=
git.tebibyte.media/tomo/objects v0.20.1/go.mod h1:hbBlQem9cNOt/G2rBvH/C94FT1oWgbtEftwg6ield9U= git.tebibyte.media/tomo/objects v0.21.0/go.mod h1:ljnNcCuNfvcYLHmQrEU7LuG0OvQiAVDCXU+ajspq+TI=
git.tebibyte.media/tomo/tomo v0.45.0 h1:fQH0WIPidW275hOq9dE6R7p064xG1RGx2QU68Avlr84=
git.tebibyte.media/tomo/tomo v0.45.0/go.mod h1:WrtilgKB1y8O2Yu7X4mYcRiqOlPR8NuUnoA/ynkQWrs=
git.tebibyte.media/tomo/typeset v0.7.1 h1:aZrsHwCG5ZB4f5CruRFsxLv5ezJUCFUFsQJJso2sXQ8= git.tebibyte.media/tomo/typeset v0.7.1 h1:aZrsHwCG5ZB4f5CruRFsxLv5ezJUCFUFsQJJso2sXQ8=
git.tebibyte.media/tomo/typeset v0.7.1/go.mod h1:PwDpSdBF3l/EzoIsa2ME7QffVVajnTHZN6l3MHEGe1g= git.tebibyte.media/tomo/typeset v0.7.1/go.mod h1:PwDpSdBF3l/EzoIsa2ME7QffVVajnTHZN6l3MHEGe1g=
git.tebibyte.media/tomo/xdg v0.1.0 h1:6G2WYPPiM2IXleCpKKHuJA34BxumwNWuLsUoX3yu5zA= git.tebibyte.media/tomo/xdg v0.1.0 h1:6G2WYPPiM2IXleCpKKHuJA34BxumwNWuLsUoX3yu5zA=
@@ -15,8 +17,6 @@ github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298 h1:1qlsVAQJ
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298/go.mod h1:D+QujdIlUNfa0igpNMk6UIvlb6C252URs4yupRUV4lQ= github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298/go.mod h1:D+QujdIlUNfa0igpNMk6UIvlb6C252URs4yupRUV4lQ=
github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 h1:lTG4HQym5oPKjL7nGs+csTgiDna685ZXjxijkne828g= github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966 h1:lTG4HQym5oPKjL7nGs+csTgiDna685ZXjxijkne828g=
github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966/go.mod h1:Mid70uvE93zn9wgF92A/r5ixgnvX8Lh68fxp9KQBaI0= github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966/go.mod h1:Mid70uvE93zn9wgF92A/r5ixgnvX8Lh68fxp9KQBaI0=
github.com/flopp/go-findfont v0.1.0 h1:lPn0BymDUtJo+ZkV01VS3661HL6F4qFlkhcJN55u6mU=
github.com/flopp/go-findfont v0.1.0/go.mod h1:wKKxRDjD024Rh7VMwoU90i6ikQRCr+JTHB5n4Ejkqvw=
github.com/jezek/xgb v1.1.0/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk= github.com/jezek/xgb v1.1.0/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
github.com/jezek/xgb v1.1.1 h1:bE/r8ZZtSv7l9gk6nU0mYx51aXrvnyb44892TwSaqS4= github.com/jezek/xgb v1.1.1 h1:bE/r8ZZtSv7l9gk6nU0mYx51aXrvnyb44892TwSaqS4=
github.com/jezek/xgb v1.1.1/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk= github.com/jezek/xgb v1.1.1/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
@@ -50,7 +50,6 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=

View File

@@ -7,23 +7,29 @@ import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/backend/x" import "git.tebibyte.media/tomo/backend/x"
import "git.tebibyte.media/sashakoshka/goparse" import "git.tebibyte.media/sashakoshka/goparse"
import "git.tebibyte.media/tomo/nasin/internal/icons/xdg" import "git.tebibyte.media/tomo/nasin/internal/icons/xdg"
import "git.tebibyte.media/tomo/nasin/internal/style/tss" import "git.tebibyte.media/tomo/nasin/internal/styles/tss"
import "git.tebibyte.media/tomo/nasin/internal/icons/fallback" import "git.tebibyte.media/tomo/nasin/internal/icons/fallback"
import "git.tebibyte.media/tomo/nasin/internal/style/fallback" import "git.tebibyte.media/tomo/nasin/internal/styles/fallback"
import "git.tebibyte.media/tomo/nasin/internal/faces/fallback"
func RegisterBackend () error { type Registrar struct {
tomo.Register(1, x.New) backend *x.Backend
return nil
} }
func SetTheme () error { func (this *Registrar) SetBackend () (tomo.Backend, error) {
// TODO eventually get rid of this when we make a file format for backend, err := x.New()
// storing visual styles if err != nil { return nil, err }
this.backend = backend.(*x.Backend)
tomo.SetBackend(backend)
return backend, nil
}
func (this *Registrar) SetTheme () error {
styleSheetName := os.Getenv("TOMO_STYLE_SHEET") styleSheetName := os.Getenv("TOMO_STYLE_SHEET")
if styleSheetName != "" { if styleSheetName != "" {
styl, _, err := tss.LoadFile(styleSheetName) styl, _, err := tss.LoadFile(styleSheetName)
if err == nil { if err == nil {
tomo.SetStyle(styl) this.backend.SetStyle(styl)
return nil return nil
} else { } else {
log.Printf ( log.Printf (
@@ -33,11 +39,11 @@ func SetTheme () error {
} }
styl, _ := fallbackStyle.New() styl, _ := fallbackStyle.New()
tomo.SetStyle(styl) this.backend.SetStyle(styl)
return nil return nil
} }
func SetIconSet () error { func (this *Registrar) SetIconSet () error {
iconSet := fallbackIcons.New() iconSet := fallbackIcons.New()
iconSetName := os.Getenv("TOMO_XDG_ICON_THEME") iconSetName := os.Getenv("TOMO_XDG_ICON_THEME")
if iconSetName != "" { if iconSetName != "" {
@@ -49,6 +55,14 @@ func SetIconSet () error {
} }
} }
tomo.SetIconSet(iconSet) this.backend.SetIconSet(iconSet)
return nil
}
func (this *Registrar) SetFaceSet () error {
// TODO replace this with something that uses findfont, and caches and
// refcounts the faces
faceSet := fallbackFaces.New()
this.backend.SetFaceSet(faceSet)
return nil return nil
} }

View File

@@ -1,5 +1,5 @@
// Colors // Colors
$ColorDot = #7391c0; $ColorDot = #7391c080;
$ColorAccent = #5f8bc4; $ColorAccent = #5f8bc4;
$ColorHighlight = #5f8bc4; $ColorHighlight = #5f8bc4;
$ColorBackground = #d4d4d4; $ColorBackground = #d4d4d4;
@@ -36,7 +36,6 @@ $BorderOuterShadow = #a4afc0 / 0 1 1 0;
TextColor: $ColorForeground; TextColor: $ColorForeground;
DotColor: $ColorDot; DotColor: $ColorDot;
Gap: 8; Gap: 8;
Face: "DMMono-Regular.ttf" 11;
} }
*.Button { *.Button {
@@ -150,6 +149,11 @@ $BorderOuterShadow = #a4afc0 / 0 1 1 0;
Padding: 0; Padding: 0;
} }
*.Checkbox[checked] {
Texture: "assets/checkbox-checked.png";
TextureMode: center;
}
*.MenuItem { *.MenuItem {
Padding: 4; Padding: 4;
Gap: 4; Gap: 4;

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

View File

Before

Width:  |  Height:  |  Size: 409 B

After

Width:  |  Height:  |  Size: 409 B

View File

@@ -1,39 +1,36 @@
package tss package tss
import "os" import "os"
import "io"
import "fmt" import "fmt"
import "image" import "image"
import "errors" import "errors"
import "image/color" import "image/color"
import "golang.org/x/image/font" import _ "image/png"
import "github.com/flopp/go-findfont" import "path/filepath"
import "git.tebibyte.media/tomo/tomo" import "git.tebibyte.media/tomo/tomo"
import "golang.org/x/image/font/opentype"
import "git.tebibyte.media/tomo/tomo/event" import "git.tebibyte.media/tomo/tomo/event"
import "git.tebibyte.media/tomo/tomo/canvas"
import "git.tebibyte.media/tomo/backend/style"
type styleBuilder struct { type styleBuilder struct {
sheet Sheet sheet Sheet
fonts map[string] *opentype.Font workingDir string
faces map[faceKey] font.Face textures map[string] canvas.TextureCloser
}
type faceKey struct {
name string
size int
} }
// BuildStyle builds a Tomo style from the specified sheet. Resources associated // BuildStyle builds a Tomo style from the specified sheet. Resources associated
// with it (such as textures) can be freed by closing the returned cookie. // with it (such as textures) can be freed by closing the returned cookie.
func BuildStyle (sheet Sheet) (*tomo.Style, event.Cookie, error) { func BuildStyle (sheet Sheet) (*style.Style, event.Cookie, error) {
builder := &styleBuilder { builder := &styleBuilder {
sheet: sheet, sheet: sheet,
fonts: make(map[string] *opentype.Font), workingDir: filepath.Dir(sheet.Path),
faces: make(map[faceKey] font.Face),
} }
return builder.build() return builder.build()
} }
func (this *styleBuilder) build () (*tomo.Style, event.Cookie, error) { func (this *styleBuilder) build () (*style.Style, event.Cookie, error) {
// ensure the sheet is flattened (all vars are resolved)
err := this.sheet.Flatten() err := this.sheet.Flatten()
if err != nil { return nil, nil, err } if err != nil { return nil, nil, err }
@@ -48,9 +45,10 @@ func (this *styleBuilder) build () (*tomo.Style, event.Cookie, error) {
return color.RGBA { R: 255, B: 255, A: 255 } return color.RGBA { R: 255, B: 255, A: 255 }
} }
// construct style and get colors
cookies := []event.Cookie { } cookies := []event.Cookie { }
style := &tomo.Style { sty := &style.Style {
Rules: make([]tomo.Rule, len(this.sheet.Rules)), Rules: make([]style.Rule, len(this.sheet.Rules)),
Colors: map[tomo.Color] color.Color { Colors: map[tomo.Color] color.Color {
tomo.ColorBackground: getColor("ColorBackground"), tomo.ColorBackground: getColor("ColorBackground"),
tomo.ColorForeground: getColor("ColorForeground"), tomo.ColorForeground: getColor("ColorForeground"),
@@ -60,14 +58,15 @@ func (this *styleBuilder) build () (*tomo.Style, event.Cookie, error) {
}, },
} }
// build style rules from the sheet's rule slice
for index, rule := range this.sheet.Rules { for index, rule := range this.sheet.Rules {
styleRule := tomo.Rule { styleRule := style.Rule {
Role: tomo.Role { Role: tomo.Role {
Package: rule.Selector.Package, Package: rule.Selector.Package,
Object: rule.Selector.Object, Object: rule.Selector.Object,
}, },
Tags: rule.Selector.Tags, Tags: rule.Selector.Tags,
Set: make(tomo.AttrSet), Set: make(style.AttrSet),
} }
for name, attr := range rule.Attrs { for name, attr := range rule.Attrs {
styleAttr, cookie, err := this.buildAttr(name, attr) styleAttr, cookie, err := this.buildAttr(name, attr)
@@ -77,13 +76,15 @@ func (this *styleBuilder) build () (*tomo.Style, event.Cookie, error) {
cookies = append(cookies, cookie) cookies = append(cookies, cookie)
} }
} }
style.Rules[index] = styleRule sty.Rules[index] = styleRule
} }
// TODO include all the faces in this.faces (ONCE EACH) in the // add each texture to the cookies list
// multicookie for _, texture := range this.textures {
cookies = append(cookies, closerCookie { Closer: texture })
}
return style, event.MultiCookie(cookies...), nil return sty, event.MultiCookie(cookies...), nil
} }
func (this *styleBuilder) buildAttr (name string, attr []ValueList) (tomo.Attr, event.Cookie, error) { func (this *styleBuilder) buildAttr (name string, attr []ValueList) (tomo.Attr, event.Cookie, error) {
@@ -173,7 +174,14 @@ func (this *styleBuilder) buildAttr (name string, attr []ValueList) (tomo.Attr,
return nil, nil, errWrongType() return nil, nil, errWrongType()
case "Texture": case "Texture":
// TODO load image from file err := expectSingleSingle()
if err != nil { return nil, nil, err }
if name, ok := attr[0][0].(ValueString); ok {
texture, err := this.texture(string(name))
if err != nil { return nil, nil, err }
return tomo.ATexture(texture), nil, nil
}
return nil, nil, errWrongType()
case "TextureMode": case "TextureMode":
err := expectSingleSingle() err := expectSingleSingle()
@@ -238,6 +246,7 @@ func (this *styleBuilder) buildAttr (name string, attr []ValueList) (tomo.Attr,
return nil, nil, errWrongType() return nil, nil, errWrongType()
case "Face": case "Face":
// TODO support weight, italic, slant
err := expectSingle() err := expectSingle()
if err != nil { return nil, nil, err } if err != nil { return nil, nil, err }
list := attr[0] list := attr[0]
@@ -250,9 +259,10 @@ func (this *styleBuilder) buildAttr (name string, attr []ValueList) (tomo.Attr,
if !ok { return nil, nil, errWrongType() } if !ok { return nil, nil, errWrongType() }
size, ok := list[1].(ValueNumber) size, ok := list[1].(ValueNumber)
if !ok { return nil, nil, errWrongType() } if !ok { return nil, nil, errWrongType() }
face, err := this.face(string(name), int(size)) return tomo.AFace(tomo.Face {
if err != nil { return nil, nil, err } Font: string(name),
return tomo.AFace(face), nil, nil Size: float64(size),
}), nil, nil
case "Wrap": case "Wrap":
err := expectSingleSingle() err := expectSingleSingle()
@@ -311,34 +321,17 @@ func (this *styleBuilder) buildAttr (name string, attr []ValueList) (tomo.Attr,
return nil, nil, errors.New(fmt.Sprintf("unimplemented attribute name %s", name)) return nil, nil, errors.New(fmt.Sprintf("unimplemented attribute name %s", name))
} }
func (this *styleBuilder) face (name string, size int) (font.Face, error) { func (this *styleBuilder) texture (path string) (canvas.TextureCloser, error) {
key := faceKey { name: name, size: size } path = filepath.Join(this.workingDir, path)
face, ok := this.faces[key] if texture, ok := this.textures[path]; ok {
if ok { return face, nil } return texture, nil
}
font, ok := this.fonts[name]
if !ok {
path, err := findfont.Find(name)
if err != nil { return nil, err }
file, err := os.Open(path) file, err := os.Open(path)
if err != nil { return nil, err } if err != nil { return nil, err }
defer file.Close() defer file.Close()
fnt, err := opentype.ParseReaderAt(file) rawImage, _, err := image.Decode(file)
if err != nil {
return nil, errors.New(fmt.Sprintf (
"could not load font %s: %v", path, err))
}
font = fnt
this.fonts[name] = font
}
face, err := opentype.NewFace(font, &opentype.FaceOptions {
Size: float64(size),
DPI: 96, // TODO: replace this with the actual DPI
})
if err != nil { return nil, err } if err != nil { return nil, err }
this.faces[key] = face return tomo.NewTexture(rawImage), nil
return face, nil
} }
func buildAttrBorder (attr []ValueList) (tomo.Attr, error) { func buildAttrBorder (attr []ValueList) (tomo.Attr, error) {
@@ -406,3 +399,9 @@ func copyBorderValue[T any, U ~[]T] (destination, source U) bool {
} }
} }
type closerCookie struct {
io.Closer
}
func (cookie closerCookie) Close () {
cookie.Closer.Close()
}

View File

@@ -1,10 +1,11 @@
package tss package tss
import "os" import "os"
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/event" import "git.tebibyte.media/tomo/tomo/event"
import "git.tebibyte.media/tomo/backend/style"
type Sheet struct { type Sheet struct {
Path string
Variables map[string] ValueList Variables map[string] ValueList
Rules []Rule Rules []Rule
flat bool flat bool
@@ -65,7 +66,7 @@ func (ValueCut) value () { }
// LoadFile loads the stylesheet from the specified file. This may return a // LoadFile loads the stylesheet from the specified file. This may return a
// parse.Error, so use parse.Format to print it. // parse.Error, so use parse.Format to print it.
func LoadFile (name string) (*tomo.Style, event.Cookie, error) { func LoadFile (name string) (*style.Style, event.Cookie, error) {
// TODO check cache for gobbed sheet. if the cache is nonexistent or // TODO check cache for gobbed sheet. if the cache is nonexistent or
// invalid, then open/load/cache. // invalid, then open/load/cache.
@@ -75,5 +76,6 @@ func LoadFile (name string) (*tomo.Style, event.Cookie, error) {
sheet, err := Parse(Lex(name, file)) sheet, err := Parse(Lex(name, file))
if err != nil { return nil, nil, err } if err != nil { return nil, nil, err }
sheet.Path = name
return BuildStyle(sheet) return BuildStyle(sheet)
} }

View File

@@ -0,0 +1,35 @@
# Happen to use Micro to edit text?
# Drop this in ~/.config/micro/syntax and get syntax highlighting for TSS files!
filetype: tss
detect:
filename: "\\.tss$"
rules:
- type: "\\b([A-Z][a-zA-Z0-9]*).*:"
- identifier.var: "\\$[a-zA-Z0-9]*\\b"
- identifier.class: "(\\*|[a-z][a-zA-Z0-9]*)\\.(\\*|[A-Z][a-zA-Z0-9]*)"
- constant: "\\b(tile|center)\\b"
- constant: "\\b(start|middle|end|even)\\b"
- constant.bool: "\\b(true|false)\\b"
- special: "(\\/|,|\\;|:|\\.)"
- symbol.operator: "(=|\\*)"
- symbol.brackets: "(\\{\\[|\\}\\])"
- comment:
start: "//"
end: "$"
rules:
- todo: "(TODO|XXX|FIXME|BUG):?"
- constant.string:
start: "\""
end: "\""
skip: "\\\\."
rules:
- constant.specialChar: "\\\\[abfnrtv'\\\"\\\\]"
- constant.specialChar: "\\\\([0-7]{3})"
- constant.number: "\\b[0-9][0-9.]*\\b"
- constant.string: "\\B#[0-9a-fA-F]*"