Skip to content

Commit

Permalink
docs: story for theming
Browse files Browse the repository at this point in the history
  • Loading branch information
cfoust committed Sep 22, 2024
1 parent 4ff2f84 commit 73b3fa0
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

- [Parameters](./parameters.md)

- [Themes](./parameters/themes.md)

- [Replay mode](./replay-mode.md)

- [Modes](./replay-mode/modes.md)
Expand Down
2 changes: 2 additions & 0 deletions docs/src/notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ For example:
(msg/toast :error "this shows up in red")
```

You can configure the colors used for toasts with the [`color-*`](/default-parameters.md#color-error) family of parameters.

This code would show toasts that look like this:

{{story static toasts --width 60 --height 15}}
Expand Down
24 changes: 24 additions & 0 deletions docs/src/parameters/themes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Themes

You can configure almost anything about `cy`'s appearance by changing [default parameters](/default-parameters.md) to your liking. This includes colors, border styles, and UI copy (such as for localization.)

For example:

{{story static theme}}

This theme was created with the following Janet code:

```janet
(param/set-many :root
:replay-text-copy-mode "копировка"
:replay-status-bar-bg "#6699cc"
:replay-copy-bg "#99cc99"
:replay-copy-fg "#2d2d2d"
:input-prompt-bg "#f2777a"
:color-error "#f2777a"
:color-warning "#ffcc66"
:color-info "#6699cc"
:timestamp-format "начало революции: 2006-01-02 15:04:05")
```

Theme parameters work exactly like any other parameter. If you set a parameter with a target of `:client`, it overrides any other parameter. Parameters set on [tree nodes](/groups-and-panes.md#groups) override the parameter values of their ancestor nodes.
2 changes: 2 additions & 0 deletions pkg/cy/stories.go
Original file line number Diff line number Diff line change
Expand Up @@ -916,4 +916,6 @@ func init() {
`)
return screen, err
}, stories.Config{})

stories.Register("theme", initTheme, stories.Config{})
}
104 changes: 104 additions & 0 deletions pkg/cy/theme_story.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package cy

import (
"context"
_ "embed"

"github.com/cfoust/cy/pkg/layout"
"github.com/cfoust/cy/pkg/layout/prop"
"github.com/cfoust/cy/pkg/mux"
"github.com/cfoust/cy/pkg/replay"
"github.com/cfoust/cy/pkg/replay/player"
"github.com/cfoust/cy/pkg/sessions"
"github.com/cfoust/cy/pkg/stories"
"github.com/cfoust/cy/pkg/style"
)

//go:embed theme_story.janet
var THEME_STORY_SETUP string

var initTheme stories.InitFunc = func(ctx context.Context) (mux.Screen, error) {
server, client, screen, err := createStory(ctx)
if err != nil {
return nil, err
}

err = client.execute(THEME_STORY_SETUP)
if err != nil {
return nil, err
}

rootParams := server.tree.Root().Params()
s := sessions.NewSimulator().
Defaults().
Add(
"This sense of wandering in a space which is at once informational and uses the open Internet as a guiding principle for navigation is something that builds on a series of \"Net Nomad\" projects developed by the artist in the 1990s. Here, Cheang launches herself into the space of the nets, roaming the world and documenting her travels, finding routes and the means to travel via blagged and hustled connections, throwing life through the window onto the screen.\n\n",
"3x3x6, shu lea chang",
)

var replayTop int32
{
r := replay.New(
ctx,
player.FromEvents(s.Events()),
server.timeBinds,
server.copyBinds,
replay.WithParams(rootParams),
replay.WithCopyMode,
)
if err != nil {
return nil, err
}
p := server.tree.Root().NewPane(ctx, r)
replayTop = p.Id()
}

var replayBottom int32
{
r := replay.New(
ctx,
player.FromEvents(s.Events()),
server.timeBinds,
server.copyBinds,
replay.WithParams(rootParams),
)
if err != nil {
return nil, err
}
p := server.tree.Root().NewPane(ctx, r)
replayBottom = p.Id()
}

err = client.SetLayout(layout.New(layout.SplitType{
Vertical: true,
Border: prop.NewStatic(&style.DefaultBorder),
A: layout.PaneType{
ID: &replayTop,
},
B: layout.PaneType{
ID: &replayBottom,
Attached: true,
},
}))
if err != nil {
return nil, err
}

err = client.execute(`
(msg/toast :info "this shows up in blue")
(msg/toast :warn "this shows up in yellow")
(msg/toast :error "this shows up in red")
`)
if err != nil {
return nil, err
}

go func() {
client.execute(`
(input/find @["У лукоморья дуб зелёный" "Златая цепь на дубе том" "И днём и ночью кот учёный"]
:prompt "выбор строчки"
:animated false)`)
}()

return screen, err
}
10 changes: 10 additions & 0 deletions pkg/cy/theme_story.janet
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(param/set-many :root
:replay-text-copy-mode "копировка"
:replay-status-bar-bg "#6699cc"
:replay-copy-bg "#99cc99"
:replay-copy-fg "#2d2d2d"
:input-prompt-bg "#f2777a"
:color-error "#f2777a"
:color-warning "#ffcc66"
:color-info "#6699cc"
:timestamp-format "начало революции: 2006-01-02 15:04:05")

0 comments on commit 73b3fa0

Please sign in to comment.