diff --git a/cmd/cy/stories.go b/cmd/cy/stories.go index 57167dd7..76688abc 100644 --- a/cmd/cy/stories.go +++ b/cmd/cy/stories.go @@ -29,7 +29,7 @@ func startStories() { log.Logger = log.Output(logs) ctx := context.Background() - screen, err := stories.Initialize(ctx, "smoke") + screen, err := stories.Initialize(ctx, "search-time-forward") if err != nil { panic(err) } diff --git a/pkg/mux/screen/replay/replay_stories.go b/pkg/mux/screen/replay/replay_stories.go index cdadda24..bbea6e85 100644 --- a/pkg/mux/screen/replay/replay_stories.go +++ b/pkg/mux/screen/replay/replay_stories.go @@ -11,24 +11,52 @@ import ( "github.com/cfoust/cy/pkg/mux" "github.com/cfoust/cy/pkg/sessions" "github.com/cfoust/cy/pkg/stories" + "github.com/cfoust/cy/pkg/taro" + + tea "github.com/charmbracelet/bubbletea" "github.com/xo/terminfo" ) -var Smoke stories.Story = func(ctx context.Context) mux.Screen { - replay := New( +func createTestSession() []sessions.Event { + return sessions.NewSimulator(). + Add( + "\033[20h", // CRLF -- why is this everywhere? + geom.DEFAULT_SIZE, + "test string please ignore", + ). + Term(terminfo.ClearScreen). + Add("take two"). + Term(terminfo.ClearScreen). + Add("test"). + Events() +} + +func createStory(ctx context.Context, events []sessions.Event, msgs ...interface{}) mux.Screen { + replay := New(ctx, events, bind.NewBindScope()) + + var realMsg tea.Msg + for _, msg := range msgs { + realMsg = msg + switch msg := msg.(type) { + case ActionType: + realMsg = ActionEvent{Type: msg} + case string: + keyMsgs := taro.KeysToMsg(msg) + if len(keyMsgs) == 1 { + realMsg = keyMsgs[0] + } + } + replay.Send(realMsg) + } + + return replay +} + +var SearchTimeForward stories.Story = func(ctx context.Context) mux.Screen { + replay := createStory( ctx, - sessions.NewSimulator(). - Add( - "\033[20h", // CRLF -- why is this everywhere? - geom.DEFAULT_SIZE, - "test string please ignore", - ). - Term(terminfo.ClearScreen). - Add("take two"). - Term(terminfo.ClearScreen). - Add("test"). - Events(), - bind.NewBindScope(), + createTestSession(), + ActionSearchForward, ) return replay @@ -38,5 +66,5 @@ func init() { config := stories.Config{ Size: geom.DEFAULT_SIZE, } - stories.Register("smoke", Smoke, config) + stories.Register("search-time-forward", SearchTimeForward, config) } diff --git a/pkg/sessions/simulator.go b/pkg/sessions/simulator.go index 0f2d1c6a..f2a71c40 100644 --- a/pkg/sessions/simulator.go +++ b/pkg/sessions/simulator.go @@ -18,7 +18,6 @@ type Simulator struct { func (s *Simulator) store(delta time.Duration, data P.Message) { event := Event{ - Stamp: time.Now(), Message: data, } diff --git a/pkg/stories/viewer.go b/pkg/stories/viewer.go index 2f915e2f..37fd2542 100644 --- a/pkg/stories/viewer.go +++ b/pkg/stories/viewer.go @@ -54,6 +54,7 @@ func (s *StoryViewer) View(state *tty.State) { W: storySize.C, }) tty.Copy(storyPos, state, contents) + state.CursorVisible = contents.CursorVisible } func (s *StoryViewer) Update(msg tea.Msg) (taro.Model, tea.Cmd) {