mirror of
https://github.com/usestrix/strix.git
synced 2026-10-08 03:08:08 +00:00
feat(tui): set the terminal title to the scan target
This commit is contained in:
parent
f1386cad37
commit
6f2803295f
2 changed files with 28 additions and 0 deletions
|
|
@ -90,6 +90,7 @@ type Model struct {
|
|||
client *Client
|
||||
width, height int
|
||||
snapshot protocol.Snapshot
|
||||
windowTitle string
|
||||
input textarea.Model
|
||||
viewport viewport.Model
|
||||
viewportContent string
|
||||
|
|
|
|||
|
|
@ -2,10 +2,13 @@ package app
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/x/ansi"
|
||||
"github.com/usestrix/strix/tui/internal/protocol"
|
||||
"github.com/usestrix/strix/tui/internal/render"
|
||||
)
|
||||
|
|
@ -56,6 +59,10 @@ func (m *Model) handleEnvelope(envelope protocol.Envelope) tea.Cmd {
|
|||
// resize (not just refresh): status-row visibility changes the chat height.
|
||||
m.resizeViewport()
|
||||
m.resizeVulnerabilityViewport()
|
||||
if title := windowTitle(m.snapshot.Targets); title != m.windowTitle {
|
||||
m.windowTitle = title
|
||||
return setTerminalTitle(title)
|
||||
}
|
||||
case "collection_bootstrap":
|
||||
return m.handleCollectionBootstrap(envelope.Payload)
|
||||
case "collection_delta":
|
||||
|
|
@ -118,6 +125,26 @@ func (m *Model) handleEnvelope(envelope protocol.Envelope) tea.Cmd {
|
|||
return nil
|
||||
}
|
||||
|
||||
// tea.SetWindowTitle only sends OSC 2 (window title); iTerm tabs show the OSC 1
|
||||
// icon name, which shells usually set, so send OSC 0 to set both.
|
||||
func setTerminalTitle(title string) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
_, _ = os.Stdout.WriteString(ansi.SetIconNameWindowTitle(title))
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func windowTitle(targets []string) string {
|
||||
switch len(targets) {
|
||||
case 0:
|
||||
return "strix"
|
||||
case 1:
|
||||
return targets[0]
|
||||
default:
|
||||
return fmt.Sprintf("%s +%d", targets[0], len(targets)-1)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Model) consumeMessages(messages []protocol.Message, setupMode bool) {
|
||||
if m.seenMessages == nil {
|
||||
m.seenMessages = map[string]bool{}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue