Show the terminal immediately when opening the Terminal tab
This commit is contained in:
+21
-16
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/coder/websocket"
|
||||
|
||||
"g.fc.run/ai/byre/internal/api"
|
||||
"g.fc.run/ai/byre/internal/store"
|
||||
"g.fc.run/ai/byre/internal/terminal"
|
||||
)
|
||||
|
||||
@@ -21,23 +22,27 @@ const (
|
||||
var newTerminalSize = api.TerminalSize{Cols: 80, Rows: 24}
|
||||
|
||||
func (s *Server) terminalsChanged(taskID string) {
|
||||
s.store.Broadcast(api.Event{Kind: "terminals.changed", TaskId: &taskID, Actor: "byre", Payload: map[string]any{}})
|
||||
}
|
||||
|
||||
func taskTerminal(term *terminal.Terminal) api.TaskTerminal {
|
||||
return api.TaskTerminal{Id: term.ID, Name: term.Name, StartedAt: term.Started().UTC()}
|
||||
}
|
||||
|
||||
func (s *Server) ListTaskTerminals(w http.ResponseWriter, r *http.Request, taskID string) {
|
||||
_, ok := s.activeTask(w, r, taskID)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
out := []api.TaskTerminal{}
|
||||
s.terminalsMu.Lock()
|
||||
defer s.terminalsMu.Unlock()
|
||||
list := api.TerminalList{Terminals: []api.TaskTerminal{}}
|
||||
for _, term := range s.terminals.List(taskID) {
|
||||
out = append(out, taskTerminal(term))
|
||||
list.Terminals = append(list.Terminals, taskTerminal(taskID, term))
|
||||
}
|
||||
writeJSON(w, http.StatusOK, out)
|
||||
s.store.Broadcast(api.Event{Kind: "terminals.changed", TaskId: &taskID, Actor: "byre", Payload: store.ToPayload(list)})
|
||||
}
|
||||
|
||||
func taskTerminal(taskID string, term *terminal.Terminal) api.TaskTerminal {
|
||||
return api.TaskTerminal{Id: term.ID, TaskId: taskID, Name: term.Name, StartedAt: term.Started().UTC()}
|
||||
}
|
||||
|
||||
func (s *Server) ListTerminals(w http.ResponseWriter, r *http.Request) {
|
||||
list := api.TerminalList{Terminals: []api.TaskTerminal{}}
|
||||
for taskID, terms := range s.terminals.All() {
|
||||
for _, term := range terms {
|
||||
list.Terminals = append(list.Terminals, taskTerminal(taskID, term))
|
||||
}
|
||||
}
|
||||
writeJSON(w, http.StatusOK, list)
|
||||
}
|
||||
|
||||
func (s *Server) StartTaskTerminal(w http.ResponseWriter, r *http.Request, taskID string) {
|
||||
@@ -64,7 +69,7 @@ func (s *Server) StartTaskTerminal(w http.ResponseWriter, r *http.Request, taskI
|
||||
writeError(w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusCreated, taskTerminal(term))
|
||||
writeJSON(w, http.StatusCreated, taskTerminal(taskID, term))
|
||||
}
|
||||
|
||||
func (s *Server) CloseTaskTerminal(w http.ResponseWriter, r *http.Request, taskID, terminalID string) {
|
||||
|
||||
Reference in New Issue
Block a user