mirror of
https://github.com/sst/opencode.git
synced 2025-08-31 02:07:24 +00:00
wip: refactoring tui
This commit is contained in:
parent
6759674c0f
commit
fce9e79d38
5 changed files with 12 additions and 13 deletions
|
@ -25,7 +25,7 @@ type App struct {
|
||||||
Events *client.Client
|
Events *client.Client
|
||||||
State map[string]any
|
State map[string]any
|
||||||
Session *client.SessionInfo
|
Session *client.SessionInfo
|
||||||
Messages []client.SessionMessage
|
Messages []client.MessageInfo
|
||||||
|
|
||||||
CurrentSessionOLD *session.Session
|
CurrentSessionOLD *session.Session
|
||||||
SessionsOLD SessionService
|
SessionsOLD SessionService
|
||||||
|
@ -133,12 +133,12 @@ func (a *App) SendChatMessage(ctx context.Context, text string, attachments []me
|
||||||
// return "", fmt.Errorf("attachments not supported yet")
|
// return "", fmt.Errorf("attachments not supported yet")
|
||||||
}
|
}
|
||||||
|
|
||||||
part := client.SessionMessagePart{}
|
part := client.MessagePart{}
|
||||||
part.FromSessionMessagePartText(client.SessionMessagePartText{
|
part.FromMessagePartText(client.MessagePartText{
|
||||||
Type: "text",
|
Type: "text",
|
||||||
Text: text,
|
Text: text,
|
||||||
})
|
})
|
||||||
parts := []client.SessionMessagePart{part}
|
parts := []client.MessagePart{part}
|
||||||
|
|
||||||
go a.Client.PostSessionChatWithResponse(ctx, client.PostSessionChatJSONRequestBody{
|
go a.Client.PostSessionChatWithResponse(ctx, client.PostSessionChatJSONRequestBody{
|
||||||
SessionID: a.Session.Id,
|
SessionID: a.Session.Id,
|
||||||
|
|
|
@ -70,12 +70,12 @@ func (a *AgentServiceBridge) Run(ctx context.Context, sessionID string, text str
|
||||||
// return "", fmt.Errorf("attachments not supported yet")
|
// return "", fmt.Errorf("attachments not supported yet")
|
||||||
}
|
}
|
||||||
|
|
||||||
part := client.SessionMessagePart{}
|
part := client.MessagePart{}
|
||||||
part.FromSessionMessagePartText(client.SessionMessagePartText{
|
part.FromMessagePartText(client.MessagePartText{
|
||||||
Type: "text",
|
Type: "text",
|
||||||
Text: text,
|
Text: text,
|
||||||
})
|
})
|
||||||
parts := []client.SessionMessagePart{part}
|
parts := []client.MessagePart{part}
|
||||||
|
|
||||||
go a.client.PostSessionChatWithResponse(ctx, client.PostSessionChatJSONRequestBody{
|
go a.client.PostSessionChatWithResponse(ctx, client.PostSessionChatJSONRequestBody{
|
||||||
SessionID: sessionID,
|
SessionID: sessionID,
|
||||||
|
|
|
@ -76,7 +76,7 @@ func renderMessage(msg string, isUser bool, isFocused bool, width int, info ...s
|
||||||
return rendered
|
return rendered
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderUserMessage(msg client.SessionMessage, isFocused bool, width int, position int) uiMessage {
|
func renderUserMessage(msg client.MessageInfo, isFocused bool, width int) uiMessage {
|
||||||
// var styledAttachments []string
|
// var styledAttachments []string
|
||||||
t := theme.CurrentTheme()
|
t := theme.CurrentTheme()
|
||||||
baseStyle := styles.BaseStyle()
|
baseStyle := styles.BaseStyle()
|
||||||
|
@ -118,8 +118,8 @@ func renderUserMessage(msg client.SessionMessage, isFocused bool, width int, pos
|
||||||
}
|
}
|
||||||
|
|
||||||
switch part.(type) {
|
switch part.(type) {
|
||||||
case client.SessionMessagePartText:
|
case client.MessagePartText:
|
||||||
textPart := part.(client.SessionMessagePartText)
|
textPart := part.(client.MessagePartText)
|
||||||
content = renderMessage(textPart.Text, true, isFocused, width, info...)
|
content = renderMessage(textPart.Text, true, isFocused, width, info...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,12 +185,12 @@ func formatTimeDifference(unixTime1, unixTime2 int64) string {
|
||||||
|
|
||||||
func (m *messagesCmp) renderView() {
|
func (m *messagesCmp) renderView() {
|
||||||
m.uiMessages = make([]uiMessage, 0)
|
m.uiMessages = make([]uiMessage, 0)
|
||||||
pos := 0
|
|
||||||
baseStyle := styles.BaseStyle()
|
baseStyle := styles.BaseStyle()
|
||||||
|
|
||||||
if m.width == 0 {
|
if m.width == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, msg := range m.app.Messages {
|
for _, msg := range m.app.Messages {
|
||||||
switch msg.Role {
|
switch msg.Role {
|
||||||
case client.User:
|
case client.User:
|
||||||
|
@ -202,7 +202,6 @@ func (m *messagesCmp) renderView() {
|
||||||
msg,
|
msg,
|
||||||
msg.Id == m.currentMsgID,
|
msg.Id == m.currentMsgID,
|
||||||
m.width,
|
m.width,
|
||||||
pos,
|
|
||||||
)
|
)
|
||||||
m.uiMessages = append(m.uiMessages, userMsg)
|
m.uiMessages = append(m.uiMessages, userMsg)
|
||||||
m.cachedContent[msg.Id] = cacheItem{
|
m.cachedContent[msg.Id] = cacheItem{
|
||||||
|
|
|
@ -292,7 +292,7 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
sessionId := parts[2]
|
sessionId := parts[2]
|
||||||
if sessionId == a.app.Session.Id {
|
if sessionId == a.app.Session.Id {
|
||||||
messageId := parts[3]
|
messageId := parts[3]
|
||||||
var message client.SessionMessage
|
var message client.MessageInfo
|
||||||
bytes, _ := json.Marshal(msg.Content)
|
bytes, _ := json.Marshal(msg.Content)
|
||||||
if err := json.Unmarshal(bytes, &message); err != nil {
|
if err := json.Unmarshal(bytes, &message); err != nil {
|
||||||
status.Error(err.Error())
|
status.Error(err.Error())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue