diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index 2d144dbb..a48b833f 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -36,6 +36,8 @@ - [Parameters](./parameters.md) + - [Themes](./parameters/themes.md) + - [Replay mode](./replay-mode.md) - [Modes](./replay-mode/modes.md) diff --git a/docs/src/notifications.md b/docs/src/notifications.md index ef217753..f97dd43d 100644 --- a/docs/src/notifications.md +++ b/docs/src/notifications.md @@ -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}} diff --git a/docs/src/parameters/themes.md b/docs/src/parameters/themes.md new file mode 100644 index 00000000..e8929012 --- /dev/null +++ b/docs/src/parameters/themes.md @@ -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. diff --git a/pkg/cy/stories.go b/pkg/cy/stories.go index 1f4a16a1..43e40f8e 100644 --- a/pkg/cy/stories.go +++ b/pkg/cy/stories.go @@ -916,4 +916,6 @@ func init() { `) return screen, err }, stories.Config{}) + + stories.Register("theme", initTheme, stories.Config{}) } diff --git a/pkg/cy/theme_story.go b/pkg/cy/theme_story.go new file mode 100644 index 00000000..779a81c2 --- /dev/null +++ b/pkg/cy/theme_story.go @@ -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 +} diff --git a/pkg/cy/theme_story.janet b/pkg/cy/theme_story.janet new file mode 100644 index 00000000..d0aa7b3b --- /dev/null +++ b/pkg/cy/theme_story.janet @@ -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")