runTUIWrapped is runTUI with an optional model wrapper, used by --record to interpose the input recorder between the terminal and the real model.
(ctx context.Context, rt runtime.Runtime, sess *session.Session, spawner tui.SessionSpawner, cleanup func(), tuiOpts []tui.Option, wrap func(tea.Model) tea.Model, opts ...app.Opt)
| 97 | // runTUIWrapped is runTUI with an optional model wrapper, used by --record to |
| 98 | // interpose the input recorder between the terminal and the real model. |
| 99 | func runTUIWrapped(ctx context.Context, rt runtime.Runtime, sess *session.Session, spawner tui.SessionSpawner, cleanup func(), tuiOpts []tui.Option, wrap func(tea.Model) tea.Model, opts ...app.Opt) error { |
| 100 | if gen := rt.TitleGenerator(ctx); gen != nil { |
| 101 | opts = append(opts, app.WithTitleGenerator(gen)) |
| 102 | } |
| 103 | |
| 104 | a := app.New(ctx, rt, sess, opts...) |
| 105 | |
| 106 | coalescer := tuiinput.NewWheelCoalescer() |
| 107 | filter := func(model tea.Model, msg tea.Msg) tea.Msg { |
| 108 | wheelMsg, ok := msg.(tea.MouseWheelMsg) |
| 109 | if !ok { |
| 110 | return msg |
| 111 | } |
| 112 | if coalescer.Handle(wheelMsg) { |
| 113 | return nil |
| 114 | } |
| 115 | return msg |
| 116 | } |
| 117 | |
| 118 | if cleanup == nil { |
| 119 | cleanup = func() {} |
| 120 | } |
| 121 | // Prefer the session's working directory so the TUI (and features keyed |
| 122 | // off it, like /shell) operate where the tools do — e.g. the worktree |
| 123 | // created by --worktree, not the process CWD it was launched from. |
| 124 | wd := sess.WorkingDir |
| 125 | if wd == "" { |
| 126 | wd, _ = os.Getwd() |
| 127 | } |
| 128 | model := tui.New(ctx, spawner, a, wd, cleanup, tuiOpts...) |
| 129 | if wrap != nil { |
| 130 | model = wrap(model) |
| 131 | } |
| 132 | |
| 133 | p := tea.NewProgram(model, tea.WithContext(ctx), tea.WithFilter(filter)) |
| 134 | coalescer.SetSender(p.Send) |
| 135 | |
| 136 | if m, ok := model.(interface{ SetProgram(p *tea.Program) }); ok { |
| 137 | m.SetProgram(p) |
| 138 | } |
| 139 | |
| 140 | _, err := p.Run() |
| 141 | return err |
| 142 | } |
no test coverage detected