mirror of
https://github.com/anotherhadi/spilltea.git
synced 2026-05-20 09:42:34 +02:00
CopyRequest -> Copy & CopyAs
Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/anotherhadi/spilltea/internal/intercept"
|
||||
"github.com/anotherhadi/spilltea/internal/plugins"
|
||||
proxyPkg "github.com/anotherhadi/spilltea/internal/proxy"
|
||||
copyUI "github.com/anotherhadi/spilltea/internal/ui/components/copy"
|
||||
copyasUI "github.com/anotherhadi/spilltea/internal/ui/components/copyas"
|
||||
notificationsUI "github.com/anotherhadi/spilltea/internal/ui/components/notifications"
|
||||
diffUI "github.com/anotherhadi/spilltea/internal/ui/diff"
|
||||
@@ -66,6 +67,7 @@ type Model struct {
|
||||
pluginsPage pluginsUI.Model
|
||||
findingsPage findingsUI.Model
|
||||
copyAs copyasUI.Model
|
||||
copy copyUI.Model
|
||||
notifications notificationsUI.Model
|
||||
}
|
||||
|
||||
@@ -87,6 +89,7 @@ func New(broker *intercept.Broker, name, path string) Model {
|
||||
pluginsPage: pluginsUI.New(mgr),
|
||||
findingsPage: findingsUI.New(),
|
||||
copyAs: copyasUI.New(),
|
||||
copy: copyUI.New(),
|
||||
notifications: notificationsUI.New(),
|
||||
sidebarState: sidebarState(cfg.TUI.DefaultSidebarState),
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/anotherhadi/spilltea/internal/keys"
|
||||
"github.com/anotherhadi/spilltea/internal/plugins"
|
||||
proxyPkg "github.com/anotherhadi/spilltea/internal/proxy"
|
||||
copyUI "github.com/anotherhadi/spilltea/internal/ui/components/copy"
|
||||
copyasUI "github.com/anotherhadi/spilltea/internal/ui/components/copyas"
|
||||
notificationsUI "github.com/anotherhadi/spilltea/internal/ui/components/notifications"
|
||||
diffUI "github.com/anotherhadi/spilltea/internal/ui/diff"
|
||||
@@ -81,6 +82,19 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return m, cmd
|
||||
}
|
||||
|
||||
if m.copy.IsOpen() {
|
||||
if ws, ok := msg.(tea.WindowSizeMsg); ok {
|
||||
m.width = ws.Width
|
||||
m.height = ws.Height
|
||||
m.copy.SetSize(ws.Width, ws.Height)
|
||||
m.resizeChildren()
|
||||
return m, nil
|
||||
}
|
||||
var cmd tea.Cmd
|
||||
m.copy, cmd = m.copy.Update(msg)
|
||||
return m, cmd
|
||||
}
|
||||
|
||||
switch msg := msg.(type) {
|
||||
case tea.WindowSizeMsg:
|
||||
m.width = msg.Width
|
||||
@@ -161,7 +175,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
|
||||
if !m.activeIsEditing() {
|
||||
switch {
|
||||
case key.Matches(msg, keys.Keys.Global.CopyRequest):
|
||||
case key.Matches(msg, keys.Keys.Global.CopyAs):
|
||||
if m.page == pageDiff {
|
||||
if raw := m.diff.CurrentRaw(); raw != "" {
|
||||
m.copyAs.SetSize(m.width, m.height)
|
||||
@@ -181,6 +195,28 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
return m, nil
|
||||
|
||||
case key.Matches(msg, keys.Keys.Global.Copy):
|
||||
var raw, scheme string
|
||||
switch m.page {
|
||||
case pageIntercept:
|
||||
raw = m.intercept.CurrentRaw()
|
||||
scheme = m.intercept.CurrentScheme()
|
||||
case pageDiff:
|
||||
raw = m.diff.CurrentRaw()
|
||||
scheme = "https"
|
||||
case pageHistory:
|
||||
raw = m.history.CurrentRaw()
|
||||
scheme = m.history.CurrentScheme()
|
||||
case pageReplay:
|
||||
raw = m.replay.CurrentRaw()
|
||||
scheme = m.replay.CurrentScheme()
|
||||
}
|
||||
if raw != "" {
|
||||
m.copy.SetSize(m.width, m.height)
|
||||
m.copy.Open(copyUI.OpenMsg{RawRequest: raw, Scheme: scheme})
|
||||
}
|
||||
return m, nil
|
||||
|
||||
case key.Matches(msg, keys.Keys.Global.ToggleSidebar):
|
||||
m.cycleSidebarState()
|
||||
m.resizeChildren()
|
||||
|
||||
@@ -22,6 +22,13 @@ func (m Model) View() tea.View {
|
||||
return v
|
||||
}
|
||||
|
||||
if m.copy.IsOpen() {
|
||||
v := tea.NewView(m.copy.View(normal))
|
||||
v.AltScreen = true
|
||||
v.MouseMode = tea.MouseModeCellMotion
|
||||
return v
|
||||
}
|
||||
|
||||
rendered := normal
|
||||
if m.notifications.HasNotifications() {
|
||||
rendered = m.notifications.View(normal)
|
||||
|
||||
Reference in New Issue
Block a user