@@ -14,7 +14,6 @@ import (
1414 "github.com/kujtimiihoxha/opencode/internal/message"
1515 "github.com/kujtimiihoxha/opencode/internal/pubsub"
1616 "github.com/kujtimiihoxha/opencode/internal/session"
17- "github.com/kujtimiihoxha/opencode/internal/tui/layout"
1817 "github.com/kujtimiihoxha/opencode/internal/tui/styles"
1918 "github.com/kujtimiihoxha/opencode/internal/tui/util"
2019)
@@ -26,7 +25,6 @@ type cacheItem struct {
2625type messagesCmp struct {
2726 app * app.App
2827 width , height int
29- writingMode bool
3028 viewport viewport.Model
3129 session session.Session
3230 messages []message.Message
@@ -38,15 +36,40 @@ type messagesCmp struct {
3836}
3937type renderFinishedMsg struct {}
4038
39+ type MessageKeys struct {
40+ PageDown key.Binding
41+ PageUp key.Binding
42+ HalfPageUp key.Binding
43+ HalfPageDown key.Binding
44+ }
45+
46+ var messageKeys = MessageKeys {
47+ PageDown : key .NewBinding (
48+ key .WithKeys ("pgdown" ),
49+ key .WithHelp ("f/pgdn" , "page down" ),
50+ ),
51+ PageUp : key .NewBinding (
52+ key .WithKeys ("pgup" ),
53+ key .WithHelp ("b/pgup" , "page up" ),
54+ ),
55+ HalfPageUp : key .NewBinding (
56+ key .WithKeys ("ctrl+u" ),
57+ key .WithHelp ("ctrl+u" , "½ page up" ),
58+ ),
59+ HalfPageDown : key .NewBinding (
60+ key .WithKeys ("ctrl+d" , "ctrl+d" ),
61+ key .WithHelp ("ctrl+d" , "½ page down" ),
62+ ),
63+ }
64+
4165func (m * messagesCmp ) Init () tea.Cmd {
4266 return tea .Batch (m .viewport .Init (), m .spinner .Tick )
4367}
4468
4569func (m * messagesCmp ) Update (msg tea.Msg ) (tea.Model , tea.Cmd ) {
4670 var cmds []tea.Cmd
4771 switch msg := msg .(type ) {
48- case EditorFocusMsg :
49- m .writingMode = bool (msg )
72+
5073 case SessionSelectedMsg :
5174 if msg .ID != m .session .ID {
5275 cmd := m .SetSession (msg )
@@ -63,10 +86,6 @@ func (m *messagesCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
6386 case renderFinishedMsg :
6487 m .rendering = false
6588 m .viewport .GotoBottom ()
66- case tea.KeyMsg :
67- if m .writingMode {
68- return m , nil
69- }
7089 case pubsub.Event [message.Message ]:
7190 needsRerender := false
7291 if msg .Type == pubsub .CreatedEvent {
@@ -326,22 +345,14 @@ func (m *messagesCmp) working() string {
326345func (m * messagesCmp ) help () string {
327346 text := ""
328347
329- if m .writingMode {
348+ if m .app . CoderAgent . IsBusy () {
330349 text += lipgloss .JoinHorizontal (
331350 lipgloss .Left ,
332351 styles .BaseStyle .Foreground (styles .ForgroundDim ).Bold (true ).Render ("press " ),
333352 styles .BaseStyle .Foreground (styles .Forground ).Bold (true ).Render ("esc" ),
334- styles .BaseStyle .Foreground (styles .ForgroundDim ).Bold (true ).Render (" to exit writing mode" ),
335- )
336- } else {
337- text += lipgloss .JoinHorizontal (
338- lipgloss .Left ,
339- styles .BaseStyle .Foreground (styles .ForgroundDim ).Bold (true ).Render ("press " ),
340- styles .BaseStyle .Foreground (styles .Forground ).Bold (true ).Render ("i" ),
341- styles .BaseStyle .Foreground (styles .ForgroundDim ).Bold (true ).Render (" to start writing" ),
353+ styles .BaseStyle .Foreground (styles .ForgroundDim ).Bold (true ).Render (" to exit cancel" ),
342354 )
343355 }
344-
345356 return styles .BaseStyle .
346357 Width (m .width ).
347358 Render (text )
@@ -398,18 +409,26 @@ func (m *messagesCmp) SetSession(session session.Session) tea.Cmd {
398409}
399410
400411func (m * messagesCmp ) BindingKeys () []key.Binding {
401- bindings := layout .KeyMapToSlice (m .viewport .KeyMap )
402- return bindings
412+ return []key.Binding {
413+ m .viewport .KeyMap .PageDown ,
414+ m .viewport .KeyMap .PageUp ,
415+ m .viewport .KeyMap .HalfPageUp ,
416+ m .viewport .KeyMap .HalfPageDown ,
417+ }
403418}
404419
405420func NewMessagesCmp (app * app.App ) tea.Model {
406421 s := spinner .New ()
407422 s .Spinner = spinner .Pulse
423+ vp := viewport .New (0 , 0 )
424+ vp .KeyMap .PageUp = messageKeys .PageUp
425+ vp .KeyMap .PageDown = messageKeys .PageDown
426+ vp .KeyMap .HalfPageUp = messageKeys .HalfPageUp
427+ vp .KeyMap .HalfPageDown = messageKeys .HalfPageDown
408428 return & messagesCmp {
409429 app : app ,
410- writingMode : true ,
411430 cachedContent : make (map [string ]cacheItem ),
412- viewport : viewport . New ( 0 , 0 ) ,
431+ viewport : vp ,
413432 spinner : s ,
414433 }
415434}
0 commit comments