mirror of
https://github.com/aykhans/sarin.git
synced 2026-11-28 20:19:10 +00:00
Merge pull request #237 from aykhans/chore/maintenance
This commit is contained in:
13 files changed
+274
-131
No files matched your search
+13
-14
@@ -4,8 +4,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"charm.land/lipgloss/v2"
|
||||
"go.aykhans.me/sarin/internal/config"
|
||||
@@ -17,19 +15,22 @@ import (
|
||||
func main() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
stopCtrl := sarin.NewStopController(cancel)
|
||||
go listenForTermination(stopCtrl.Stop)
|
||||
go stopCtrl.ListenSignals()
|
||||
|
||||
combinedConfig := config.ReadAllConfigs()
|
||||
combinedConfig := config.ReadAllConfigs(ctx)
|
||||
if ctx.Err() != nil {
|
||||
return
|
||||
}
|
||||
|
||||
combinedConfig.SetDefaults()
|
||||
|
||||
if *combinedConfig.ShowConfig {
|
||||
if !combinedConfig.Print() {
|
||||
if !combinedConfig.Print(ctx, stopCtrl) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
_ = utilsErr.MustHandle(combinedConfig.Validate(),
|
||||
_ = utilsErr.MustHandle(combinedConfig.Validate(ctx),
|
||||
utilsErr.OnType(func(err types.FieldValidationErrors) error {
|
||||
for _, fieldErr := range err.Errors {
|
||||
if fieldErr.Value == "" {
|
||||
@@ -46,6 +47,9 @@ func main() {
|
||||
return nil
|
||||
}),
|
||||
)
|
||||
if ctx.Err() != nil {
|
||||
return
|
||||
}
|
||||
|
||||
srn, err := sarin.NewSarin(
|
||||
ctx,
|
||||
@@ -58,6 +62,9 @@ func main() {
|
||||
*combinedConfig.DryRun, *combinedConfig.LogLevel, *combinedConfig.LogFile,
|
||||
combinedConfig.Lua, combinedConfig.Js,
|
||||
)
|
||||
if ctx.Err() != nil {
|
||||
return
|
||||
}
|
||||
_ = utilsErr.MustHandle(err,
|
||||
utilsErr.OnType(func(err types.ProxyDialError) error {
|
||||
fmt.Fprint(os.Stderr, lipgloss.Sprintln(config.StyleRed.Render("[PROXY] ")+err.Error()))
|
||||
@@ -89,11 +96,3 @@ func main() {
|
||||
srn.GetResponses().PrintTable()
|
||||
}
|
||||
}
|
||||
|
||||
func listenForTermination(stop func()) {
|
||||
sigChan := make(chan os.Signal, 4)
|
||||
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
|
||||
for range sigChan {
|
||||
stop()
|
||||
}
|
||||
}
|
||||
@@ -4,18 +4,19 @@ go 1.27.1
|
||||
|
||||
require (
|
||||
charm.land/bubbles/v2 v2.2.1
|
||||
charm.land/bubbletea/v2 v2.0.10
|
||||
charm.land/bubbletea/v2 v2.1.0
|
||||
charm.land/glamour/v2 v2.0.1
|
||||
charm.land/lipgloss/v2 v2.0.6
|
||||
github.com/brianvoe/gofakeit/v7 v7.17.1
|
||||
github.com/brianvoe/gofakeit/v7 v7.18.0
|
||||
github.com/charmbracelet/x/term v0.2.2
|
||||
github.com/dop251/goja v0.0.0-20261004174310-e21e22eac913
|
||||
github.com/dop251/goja v0.0.0-20261019185110-cf7b1419c9c0
|
||||
github.com/joho/godotenv v1.5.1
|
||||
github.com/valyala/fasthttp v1.75.0
|
||||
github.com/valyala/fasthttp v1.76.0
|
||||
github.com/yuin/gopher-lua v1.1.2
|
||||
go.aykhans.me/utils v1.0.7
|
||||
go.yaml.in/yaml/v4 v4.0.0-rc.6
|
||||
golang.org/x/net v0.59.0
|
||||
golang.org/x/net v0.61.0
|
||||
golang.org/x/sys v0.49.0
|
||||
)
|
||||
|
||||
require (
|
||||
@@ -23,23 +24,23 @@ require (
|
||||
github.com/aymerick/douceur v0.2.0 // indirect
|
||||
github.com/charmbracelet/colorprofile v0.4.3 // indirect
|
||||
github.com/charmbracelet/harmonica v0.2.0 // indirect
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20261001125412-878653296cfd // indirect
|
||||
github.com/charmbracelet/x/ansi v0.11.8 // indirect
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20261008173134-6b8d4baf91b4 // indirect
|
||||
github.com/charmbracelet/x/ansi v0.11.9 // indirect
|
||||
github.com/charmbracelet/x/exp/slice v0.1.0 // indirect
|
||||
github.com/charmbracelet/x/termios v0.1.1 // indirect
|
||||
github.com/charmbracelet/x/windows v0.2.2 // indirect
|
||||
github.com/clipperhouse/displaywidth v0.11.0 // indirect
|
||||
github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||
github.com/dlclark/regexp2/v2 v2.8.2 // indirect
|
||||
github.com/dlclark/regexp2/v2 v2.9.1 // indirect
|
||||
github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect
|
||||
github.com/google/pprof v0.0.0-20261003200830-ebaad5f31b4d // indirect
|
||||
github.com/google/pprof v0.0.0-20261016150608-1facf8f91b50 // indirect
|
||||
github.com/gorilla/css v1.0.1 // indirect
|
||||
github.com/klauspost/compress v1.20.1 // indirect
|
||||
github.com/klauspost/compress v1.20.3 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.4.1 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.30 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.31 // indirect
|
||||
github.com/microcosm-cc/bluemonday v1.0.27 // indirect
|
||||
github.com/molecule-man/go-brrr v1.2.0 // indirect
|
||||
github.com/molecule-man/go-brrr v1.3.0 // indirect
|
||||
github.com/muesli/cancelreader v0.2.2 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
@@ -47,7 +48,6 @@ require (
|
||||
github.com/xo/terminfo v1.2.0 // indirect
|
||||
github.com/yuin/goldmark v1.8.6 // indirect
|
||||
github.com/yuin/goldmark-emoji v1.0.6 // indirect
|
||||
golang.org/x/sync v0.23.0 // indirect
|
||||
golang.org/x/sys v0.48.0 // indirect
|
||||
golang.org/x/text v0.42.0 // indirect
|
||||
golang.org/x/sync v0.24.0 // indirect
|
||||
golang.org/x/text v0.43.0 // indirect
|
||||
)
|
||||
@@ -1,7 +1,7 @@
|
||||
charm.land/bubbles/v2 v2.2.1 h1:Fq1+qm5hV6GkvzLQDhCBpXXE5tLgvh1PRriCLwSvIQU=
|
||||
charm.land/bubbles/v2 v2.2.1/go.mod h1:wdMgn+sje1KNXdwFizIWjbf328fIUBxqEmJ/vYPo8yc=
|
||||
charm.land/bubbletea/v2 v2.0.10 h1:oolvo20VBpI0PfqE7iFjkZ1bx0WpmXGfnKz5Yldjq5o=
|
||||
charm.land/bubbletea/v2 v2.0.10/go.mod h1:QOatcnhOjYIfxzUSTz6raF7Ex4R/rIuHa3SnBdCCpMc=
|
||||
charm.land/bubbletea/v2 v2.1.0 h1:A9fj9h5LFrvQhQHFNggp8K8rvY6CUfgn9dMbb6p2HIw=
|
||||
charm.land/bubbletea/v2 v2.1.0/go.mod h1:xWHeyxIX9/wiFU2kgPW04ojOZyTzrWf+8lGjUCaftiU=
|
||||
charm.land/glamour/v2 v2.0.1 h1:xl+r00A4aJWU0z8fgwKd9fQQ4rsphqGUzuEiXZP5n+c=
|
||||
charm.land/glamour/v2 v2.0.1/go.mod h1:jo9z8XqVKPeEFMVdvCRLGk++RyJ3CdUwgNr7EvXLw3k=
|
||||
charm.land/lipgloss/v2 v2.0.6 h1:EaGKeuA8FvF+v2BT5VmZd2LoYLaMZJXA5n34th8nCIQ=
|
||||
@@ -20,14 +20,16 @@ github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuP
|
||||
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
|
||||
github.com/brianvoe/gofakeit/v7 v7.17.1 h1:50FLBhTGVJQaj6ysRUu0it8wCdYO2uGM9VfuxI+csEc=
|
||||
github.com/brianvoe/gofakeit/v7 v7.17.1/go.mod h1:QXuPeBw164PJCzCUZVmgpgHJ3Llj49jSLVkKPMtxtxA=
|
||||
github.com/brianvoe/gofakeit/v7 v7.18.0 h1:vn3tb6OKRUazCkzhotd8xEwz/mhkLFbDoR8OUREFm80=
|
||||
github.com/brianvoe/gofakeit/v7 v7.18.0/go.mod h1:QXuPeBw164PJCzCUZVmgpgHJ3Llj49jSLVkKPMtxtxA=
|
||||
github.com/charmbracelet/colorprofile v0.4.3 h1:QPa1IWkYI+AOB+fE+mg/5/4HRMZcaXex9t5KX76i20Q=
|
||||
github.com/charmbracelet/colorprofile v0.4.3/go.mod h1:/zT4BhpD5aGFpqQQqw7a+VtHCzu+zrQtt1zhMt9mR4Q=
|
||||
github.com/charmbracelet/harmonica v0.2.0 h1:8NxJWRWg/bzKqqEaaeFNipOu77YR5t8aSwG4pgaUBiQ=
|
||||
github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20261001125412-878653296cfd h1:W0HOPGkwRaAmV20plE/f+Rk6Xn+IdR8G0qHsGXcOnF8=
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20261001125412-878653296cfd/go.mod h1:D9SVXVpAsD1pP6xR6BiERbe4+dUU6EW9US1TFrNutGA=
|
||||
github.com/charmbracelet/x/ansi v0.11.8 h1:JMFwp0CgDC2+jcOB162HH5k7I3FVbgFSMMYg7dSPBQQ=
|
||||
github.com/charmbracelet/x/ansi v0.11.8/go.mod h1:ZNN+3mXny/516oTQPLMPIBeSINvNJJQ8uQXDgbeJxY0=
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20261008173134-6b8d4baf91b4 h1:hISLzUbwcvJbGoNR6A3L/TpguRRnACBmZOee8LcHLJw=
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20261008173134-6b8d4baf91b4/go.mod h1:aJDVk+WOVM1K04rdc/71PMPoUGfjxjhvXfP3Pjz1Zio=
|
||||
github.com/charmbracelet/x/ansi v0.11.9 h1:kIrqLBxtTVbLyyHO2Evoi93EjQo1mylWmpNEsfPxXAM=
|
||||
github.com/charmbracelet/x/ansi v0.11.9/go.mod h1:DG/hpOnaI2QJ/KMMqLL2h0KVhluuJLazf8973P+Vy5w=
|
||||
github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f h1:pk6gmGpCE7F3FcjaOEKYriCvpmIN4+6OS/RD0vm4uIA=
|
||||
github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f/go.mod h1:IfZAMTHB6XkZSeXUqriemErjAWCCzT0LwjKFYCZyw0I=
|
||||
github.com/charmbracelet/x/exp/slice v0.1.0 h1:m46dwuDf3M5SFYMRhxYkLC6z9WnENGVKbcbJlp13/og=
|
||||
@@ -44,16 +46,22 @@ github.com/clipperhouse/uax29/v2 v2.7.0 h1:+gs4oBZ2gPfVrKPthwbMzWZDaAFPGYK72F0NJ
|
||||
github.com/clipperhouse/uax29/v2 v2.7.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dlclark/regexp2/v2 v2.8.2 h1:uTTe+cxADL4be+dv4DZwsBIEPCQ6RHPlnVuKrtLqSx0=
|
||||
github.com/dlclark/regexp2/v2 v2.8.2/go.mod h1:avUrQvPaLz2DrFNHJF0taWAFFX2C1GMSSoeiqFjcBmU=
|
||||
github.com/dop251/goja v0.0.0-20261004174310-e21e22eac913 h1:0haZHQSJqA4qFZvnKIRgekXrPo2sQ2oRvFemiNHhcp0=
|
||||
github.com/dop251/goja v0.0.0-20261004174310-e21e22eac913/go.mod h1:GrCNKUrVplXZj0juFue0Cj2Xt/eL2Nuu2+y3UTanEo8=
|
||||
github.com/dlclark/regexp2/v2 v2.8.4 h1:yfDDXTn4oxyLDC10/ieOBNDCCdIVWS9WbT6ddVXsPKI=
|
||||
github.com/dlclark/regexp2/v2 v2.8.4/go.mod h1:avUrQvPaLz2DrFNHJF0taWAFFX2C1GMSSoeiqFjcBmU=
|
||||
github.com/dlclark/regexp2/v2 v2.9.1 h1:q6bZW/NN9VodqMjYXpuic2lZxdHPfFTzGS+MJxIJmKQ=
|
||||
github.com/dlclark/regexp2/v2 v2.9.1/go.mod h1:avUrQvPaLz2DrFNHJF0taWAFFX2C1GMSSoeiqFjcBmU=
|
||||
github.com/dop251/goja v0.0.0-20261008222547-e9f698900731 h1:j4pHbSFW20XvSKGrXR/m3YbITBSt8S2SvqFc29BXaHo=
|
||||
github.com/dop251/goja v0.0.0-20261008222547-e9f698900731/go.mod h1:GrCNKUrVplXZj0juFue0Cj2Xt/eL2Nuu2+y3UTanEo8=
|
||||
github.com/dop251/goja v0.0.0-20261019185110-cf7b1419c9c0 h1:pWHWMLDIG5IIPDoPqDp2ZxydcMQCvhO8tmfIIEXQqek=
|
||||
github.com/dop251/goja v0.0.0-20261019185110-cf7b1419c9c0/go.mod h1:Cp9NYOLrEKg/ypIRkUWYXWLuKAyyFGkDmGeJ95Sw0zI=
|
||||
github.com/go-sourcemap/sourcemap v2.1.4+incompatible h1:a+iTbH5auLKxaNwQFg0B+TCYl6lbukKPc7b5x0n1s6Q=
|
||||
github.com/go-sourcemap/sourcemap v2.1.4+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg=
|
||||
github.com/goccy/go-yaml v1.19.2 h1:PmFC1S6h8ljIz6gMRBopkjP1TVT7xuwrButHID66PoM=
|
||||
github.com/goccy/go-yaml v1.19.2/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
|
||||
github.com/google/pprof v0.0.0-20261003200830-ebaad5f31b4d h1:kZK3FQM86gr3cgJHMP7rPn8A3Z75mt+ZaVBoqMlpPF0=
|
||||
github.com/google/pprof v0.0.0-20261003200830-ebaad5f31b4d/go.mod h1:jl5iWTm0/hd5PjEYEOuwAJ57L/CibdZfrqZ5XA5GrCk=
|
||||
github.com/google/pprof v0.0.0-20261008003335-7bae8d8c4c9e h1:e+e5v2rfqKrd4lDA2n3azN3ludWyM2p+4MWob4EBlbk=
|
||||
github.com/google/pprof v0.0.0-20261008003335-7bae8d8c4c9e/go.mod h1:yUo1AMMpsPIDFGuwDK8nLcf8+vvAd5l2O6JDZ6hpwrM=
|
||||
github.com/google/pprof v0.0.0-20261016150608-1facf8f91b50 h1:PlNWJRxu5APSV0pWqfIsZ0qt9OOGHSWfZQ4zvx+WgWs=
|
||||
github.com/google/pprof v0.0.0-20261016150608-1facf8f91b50/go.mod h1:yUo1AMMpsPIDFGuwDK8nLcf8+vvAd5l2O6JDZ6hpwrM=
|
||||
github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8=
|
||||
github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0=
|
||||
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
|
||||
@@ -62,14 +70,18 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/klauspost/compress v1.20.1 h1:T7kKElXUMXrUJ2E9QhQhxFtcK5rPyLdsGZvdbLMPdiQ=
|
||||
github.com/klauspost/compress v1.20.1/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI=
|
||||
github.com/klauspost/compress v1.20.3 h1:zWNoFqq/lSuYQRim3dUXlXeA0IqwuZGicdG5ZTfY5j4=
|
||||
github.com/klauspost/compress v1.20.3/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI=
|
||||
github.com/lucasb-eyer/go-colorful v1.4.1 h1:1EO+WB73+EH8EVbzlrG3KLAfEypQWVHIBqlTf+2hNss=
|
||||
github.com/lucasb-eyer/go-colorful v1.4.1/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-runewidth v0.0.30 h1:+KUuiDA4fF0R1p5FeueHefjDm+GIM+kWfFnDjybOPgk=
|
||||
github.com/mattn/go-runewidth v0.0.30/go.mod h1:3qAiGCV4Koz/yuveO58qUefmUTRm8r0IGEXZ9jeHp/8=
|
||||
github.com/mattn/go-runewidth v0.0.31 h1:1oCV4ReTlosDBc6rYRw5cL8S/4y8iv5oRl4SJ5IBgwo=
|
||||
github.com/mattn/go-runewidth v0.0.31/go.mod h1:3qAiGCV4Koz/yuveO58qUefmUTRm8r0IGEXZ9jeHp/8=
|
||||
github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk=
|
||||
github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA=
|
||||
github.com/molecule-man/go-brrr v1.2.0 h1:dOJU45BC3Gc2WXoxAW0rgCAgVuu2gruAOGncfieA0Jw=
|
||||
github.com/molecule-man/go-brrr v1.2.0/go.mod h1:7ybW6/7gA3oKY45jOfVNjSJDtrr6ea4tzbsTkjmQDC4=
|
||||
github.com/molecule-man/go-brrr v1.3.0 h1:KEGPkUk9PYFw5+Sv/evCOSU5OmMDXCGFqQ9YjRB7GeU=
|
||||
github.com/molecule-man/go-brrr v1.3.0/go.mod h1:7ybW6/7gA3oKY45jOfVNjSJDtrr6ea4tzbsTkjmQDC4=
|
||||
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
|
||||
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
||||
@@ -82,6 +94,8 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasthttp v1.75.0 h1:W3xrvNJHG60j2ZCjxpP8kkB+oPG8kh9/g1n4+3xUwNA=
|
||||
github.com/valyala/fasthttp v1.75.0/go.mod h1:JiVkPRZU124PuPsreV/s9dZRgG2lRK7wNEikdQ0Rk4s=
|
||||
github.com/valyala/fasthttp v1.76.0 h1:QitrT4foDQuqvUnr/hzmQUDbYzV12Zz4vkLOlipU4Cw=
|
||||
github.com/valyala/fasthttp v1.76.0/go.mod h1:m8oTPC8riDDky07invpl+Gz3RixnAN5BbwyUuVB5H2o=
|
||||
github.com/xo/terminfo v1.2.0 h1:d0ZTOCpuGE0lwSAOs0zcJjwz3jWQyqcRt9XbGJpCOl4=
|
||||
github.com/xo/terminfo v1.2.0/go.mod h1:lGzkSo8Fe7IRh/w+Gqz7n5mDog4FVXCj3gy/DYTBqio=
|
||||
github.com/yuin/goldmark v1.8.6 h1:d0VcaP1sx9GkFVkoW+KtggpGi2KZ965i14b0+bDQST4=
|
||||
@@ -94,15 +108,20 @@ go.aykhans.me/utils v1.0.7 h1:ClHXHlWmkjfFlD7+w5BQY29lKCEztxY/yCf543x4hZw=
|
||||
go.aykhans.me/utils v1.0.7/go.mod h1:0Jz8GlZLN35cCHLOLx39sazWwEe33bF6SYlSeqzEXoI=
|
||||
go.yaml.in/yaml/v4 v4.0.0-rc.6 h1:1h7H1ohdUh93/FyE4YaDa1Zh64K6VVbjF4K6WUxMtH4=
|
||||
go.yaml.in/yaml/v4 v4.0.0-rc.6/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
|
||||
golang.org/x/net v0.59.0 h1:5zfYln+w5XCxwrnMMJPufRgNoXEaGxl0wo5GqPXyues=
|
||||
golang.org/x/net v0.59.0/go.mod h1:2DA/G1UfVbCpQPeWTmMPGY7Cs2PkBkwu743bVX5PIVg=
|
||||
golang.org/x/sync v0.23.0 h1:KameEIfc1IkluZyXWLn39Wd4tURc6GbCiISGiZm2bQk=
|
||||
golang.org/x/sync v0.23.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0=
|
||||
golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo=
|
||||
golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
|
||||
golang.org/x/net v0.60.0 h1:79p50tfZlm0J9YfoDsSi639qSXNGVwEzOPLCxM2FsYU=
|
||||
golang.org/x/net v0.60.0/go.mod h1:2DA/G1UfVbCpQPeWTmMPGY7Cs2PkBkwu743bVX5PIVg=
|
||||
golang.org/x/net v0.61.0 h1:RR+6j/BTBCrggOLugxa+66R8FvoN6MHlzDlZIbN9YFw=
|
||||
golang.org/x/net v0.61.0/go.mod h1:WgDCOTH8iwtB66T4/GfI94AHo/hhdb7Hah9NDseQfiI=
|
||||
golang.org/x/sync v0.24.0 h1:iqiDrGoDgyuvAKrhLQthUEzU/R378N78gXbBjxed7oA=
|
||||
golang.org/x/sync v0.24.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0=
|
||||
golang.org/x/sys v0.49.0 h1:XbzkgYJHdqh/8m2Uu0W/dQv8nktxx4BFHp1M0gROTXA=
|
||||
golang.org/x/sys v0.49.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
|
||||
golang.org/x/text v0.42.0 h1:JbOZXgfeCPU9gacVtYliJqOhD+zhrEqK4LfdpmlUZqI=
|
||||
golang.org/x/text v0.42.0/go.mod h1:ojzP1Z+2QtioaF8DTtO8K5q7JWVVYwZKenzujK0Zd0E=
|
||||
golang.org/x/text v0.43.0 h1:1QivrlhwAsnMOcqgOdl9my7s9OyZl8O5/UGUTJVXoWc=
|
||||
golang.org/x/text v0.43.0/go.mod h1:hbSIYA/amXcRXTFSZqh8tWHEoqRvvbKPJ2uz/KU+a+s=
|
||||
golang.org/x/tools v0.49.0 h1:3NI7VXzL9+1WZD52Dx2ttoPwD5DWrFGpl9mFZDlmisI=
|
||||
golang.org/x/tools v0.49.0/go.mod h1:SJNXV9DBKT0UbdttsQjbfJlAE/q+y36++zo3uL3N0Oo=
|
||||
golang.org/x/tools v0.51.0 h1:k4Xc/1Om9jwkBJBo4NVLMSARBoWtK10mx+W5BnXCeAI=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
+28
-16
@@ -251,7 +251,8 @@ func (config Config) MarshalYAML() (any, error) {
|
||||
return root, nil
|
||||
}
|
||||
|
||||
func (config Config) Print() bool {
|
||||
// Print shows the final config and reports whether to start the run.
|
||||
func (config Config) Print(ctx context.Context, stopCtrl *sarin.StopController) bool {
|
||||
configYAML, err := yaml.Marshal(config)
|
||||
if err != nil {
|
||||
fmt.Fprint(os.Stderr, lipgloss.Sprintln(StyleRed.Render("Error marshaling config to yaml: "+err.Error())))
|
||||
@@ -284,16 +285,19 @@ func (config Config) Print() bool {
|
||||
}
|
||||
|
||||
p := tea.NewProgram(
|
||||
printConfigModel{content: strings.Trim(content, "\n"), rawContent: configYAML},
|
||||
printConfigModel{content: strings.Trim(content, "\n"), rawContent: configYAML, stop: stopCtrl.Stop},
|
||||
tea.WithoutSignalHandler(),
|
||||
)
|
||||
|
||||
m, err := p.Run()
|
||||
stopQuit := context.AfterFunc(ctx, p.Quit)
|
||||
m, err := stopCtrl.RunProgram(p)
|
||||
stopQuit()
|
||||
if err != nil {
|
||||
fmt.Fprint(os.Stderr, lipgloss.Sprintln(StyleRed.Render(err.Error())))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
return m.(printConfigModel).start //nolint:forcetypeassert // m is guaranteed to be of type printConfigModel as it was the only model passed to tea.NewProgram
|
||||
return m.(printConfigModel).start && ctx.Err() == nil //nolint:forcetypeassert // m is guaranteed to be of type printConfigModel as it was the only model passed to tea.NewProgram
|
||||
}
|
||||
|
||||
func (config *Config) Merge(newConfig *Config) {
|
||||
@@ -426,7 +430,7 @@ func (config *Config) SetDefaults() {
|
||||
// Validate validates the config fields.
|
||||
// It can return the following errors:
|
||||
// - types.FieldValidationErrors
|
||||
func (config Config) Validate() error {
|
||||
func (config Config) Validate(ctx context.Context) error {
|
||||
validationErrors := make([]types.FieldValidationError, 0)
|
||||
|
||||
if len(config.Methods) == 0 {
|
||||
@@ -569,7 +573,7 @@ func (config Config) Validate() error {
|
||||
}
|
||||
|
||||
// Create a context with timeout for script validation (loading from URLs)
|
||||
scriptCtx, scriptCancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
scriptCtx, scriptCancel := context.WithTimeout(ctx, 30*time.Second)
|
||||
defer scriptCancel()
|
||||
|
||||
for i, scriptSrc := range config.Lua {
|
||||
@@ -580,8 +584,8 @@ func (config Config) Validate() error {
|
||||
)
|
||||
continue
|
||||
}
|
||||
// Validate script syntax
|
||||
if err := script.ValidateScript(scriptCtx, scriptSrc, script.EngineTypeLua); err != nil {
|
||||
// Validate script syntax, ignoring fetches aborted by a stop
|
||||
if err := script.ValidateScript(scriptCtx, scriptSrc, script.EngineTypeLua); err != nil && !errors.Is(err, context.Canceled) {
|
||||
validationErrors = append(
|
||||
validationErrors,
|
||||
types.NewFieldValidationError(fmt.Sprintf("Lua[%d]", i), scriptSrc, err),
|
||||
@@ -597,8 +601,8 @@ func (config Config) Validate() error {
|
||||
)
|
||||
continue
|
||||
}
|
||||
// Validate script syntax
|
||||
if err := script.ValidateScript(scriptCtx, scriptSrc, script.EngineTypeJavaScript); err != nil {
|
||||
// Validate script syntax, ignoring fetches aborted by a stop
|
||||
if err := script.ValidateScript(scriptCtx, scriptSrc, script.EngineTypeJavaScript); err != nil && !errors.Is(err, context.Canceled) {
|
||||
validationErrors = append(
|
||||
validationErrors,
|
||||
types.NewFieldValidationError(fmt.Sprintf("Js[%d]", i), scriptSrc, err),
|
||||
@@ -616,7 +620,8 @@ func (config Config) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func ReadAllConfigs() *Config {
|
||||
// ReadAllConfigs reads all config sources and returns early if ctx is cancelled.
|
||||
func ReadAllConfigs(ctx context.Context) *Config {
|
||||
envParser := NewConfigENVParser("SARIN")
|
||||
envConfig, err := envParser.Parse()
|
||||
_ = utilsErr.MustHandle(err,
|
||||
@@ -651,7 +656,10 @@ func ReadAllConfigs() *Config {
|
||||
)
|
||||
|
||||
for _, configFile := range append(envConfig.Files, cliConf.Files...) {
|
||||
fileConfig, err := parseConfigFile(configFile, 10)
|
||||
fileConfig, err := parseConfigFile(ctx, configFile, 10)
|
||||
if err != nil && ctx.Err() != nil {
|
||||
return envConfig
|
||||
}
|
||||
|
||||
// A nested configFile fails under its own name, not the one given on the command line.
|
||||
path := configFile.Path()
|
||||
@@ -700,9 +708,9 @@ func ReadAllConfigs() *Config {
|
||||
// - types.ConfigFileReadError
|
||||
// - types.UnmarshalError
|
||||
// - types.FieldParseErrors
|
||||
func parseConfigFile(configFile types.ConfigFile, maxDepth int) (*Config, error) {
|
||||
func parseConfigFile(ctx context.Context, configFile types.ConfigFile, maxDepth int) (*Config, error) {
|
||||
configFileParser := NewConfigFileParser(configFile)
|
||||
fileConfig, err := configFileParser.Parse()
|
||||
fileConfig, err := configFileParser.ParseContext(ctx)
|
||||
if err != nil {
|
||||
return nil, types.NewConfigFileError(configFile.Path(), err)
|
||||
}
|
||||
@@ -712,7 +720,7 @@ func parseConfigFile(configFile types.ConfigFile, maxDepth int) (*Config, error)
|
||||
}
|
||||
|
||||
for _, c := range fileConfig.Files {
|
||||
innerFileConfig, err := parseConfigFile(c, maxDepth-1)
|
||||
innerFileConfig, err := parseConfigFile(ctx, c, maxDepth-1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -817,6 +825,7 @@ type printConfigModel struct {
|
||||
statusMsg string
|
||||
ready bool
|
||||
start bool
|
||||
stop func()
|
||||
}
|
||||
|
||||
func (m printConfigModel) Init() tea.Cmd { return nil }
|
||||
@@ -827,7 +836,10 @@ func (m printConfigModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case tea.KeyPressMsg:
|
||||
switch msg.String() {
|
||||
case "ctrl+c", "esc":
|
||||
case "ctrl+c":
|
||||
m.stop()
|
||||
return m, tea.Quit
|
||||
case "esc":
|
||||
return m, tea.Quit
|
||||
case "ctrl+s":
|
||||
return m.saveContent()
|
||||
|
||||
@@ -35,7 +35,13 @@ func NewConfigFileParser(configFile types.ConfigFile) *ConfigFileParser {
|
||||
// - types.UnmarshalError
|
||||
// - types.FieldParseErrors
|
||||
func (parser ConfigFileParser) Parse() (*Config, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
|
||||
return parser.ParseContext(context.Background())
|
||||
}
|
||||
|
||||
// ParseContext is Parse with a parent context for remote fetches.
|
||||
// It can return the same errors as Parse.
|
||||
func (parser ConfigFileParser) ParseContext(parent context.Context) (*Config, error) {
|
||||
ctx, cancel := context.WithTimeout(parent, time.Second*30)
|
||||
defer cancel()
|
||||
|
||||
configFileData, err := fetchFile(ctx, parser.configFile.Path())
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
//go:build darwin || dragonfly || freebsd || netbsd || openbsd
|
||||
|
||||
package sarin
|
||||
|
||||
import "golang.org/x/sys/unix"
|
||||
|
||||
// isForeground is the same check as on linux, see foreground_linux.go.
|
||||
func isForeground(fd uintptr) bool {
|
||||
v, err := unix.IoctlGetInt(int(fd), unix.TIOCGPGRP)
|
||||
// The kernel writes a 32 bit pid_t, which lands in the high half of a 64 bit big-endian int.
|
||||
pgrp := int(uint32(int64(v)) | uint32(int64(v)>>32))
|
||||
return err != nil || pgrp == unix.Getpgrp()
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package sarin
|
||||
|
||||
import "golang.org/x/sys/unix"
|
||||
|
||||
// isForeground reports false only for a background job, which raw mode would stop with SIGTTOU.
|
||||
func isForeground(fd uintptr) bool {
|
||||
// pid_t is 32 bits, a 32 bit read keeps big-endian right.
|
||||
pgrp, err := unix.IoctlGetUint32(int(fd), unix.TIOCGPGRP)
|
||||
return err != nil || int(pgrp) == unix.Getpgrp()
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
//go:build !linux && !darwin && !dragonfly && !freebsd && !netbsd && !openbsd
|
||||
|
||||
package sarin
|
||||
|
||||
// isForeground has no background job check on this platform.
|
||||
func isForeground(uintptr) bool {
|
||||
return true
|
||||
}
|
||||
@@ -55,18 +55,22 @@ type BigInt struct {
|
||||
}
|
||||
|
||||
func (b BigInt) MarshalJSON() ([]byte, error) {
|
||||
return []byte(b.Int.String()), nil
|
||||
return []byte(b.String()), nil
|
||||
}
|
||||
|
||||
func (b BigInt) MarshalYAML() (any, error) {
|
||||
return &yaml.Node{
|
||||
Kind: yaml.ScalarNode,
|
||||
Tag: "!!int",
|
||||
Value: b.Int.String(),
|
||||
Value: b.String(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// String renders nil as 0, as in an empty run's stats.
|
||||
func (b BigInt) String() string {
|
||||
if b.Int == nil {
|
||||
return "0"
|
||||
}
|
||||
return b.Int.String()
|
||||
}
|
||||
|
||||
|
||||
@@ -337,7 +337,8 @@ func (s sarin) Start(stopCtrl *StopController) {
|
||||
totalRequests = *s.totalRequests
|
||||
}
|
||||
|
||||
onTerminal := IsInteractiveTerminal(os.Stdout.Fd())
|
||||
// A background job would get SIGTTOU from the TUI, so it runs without one.
|
||||
onTerminal := IsInteractiveTerminal(os.Stdout.Fd()) && isForeground(os.Stdout.Fd()) && isForeground(os.Stdin.Fd())
|
||||
// The progress bar needs an interactive terminal to render.
|
||||
showProgressBar := s.showProgress && onTerminal
|
||||
// The bubbletea TUI hosts the bar and/or the live log box, so it runs whenever
|
||||
|
||||
+99
-25
@@ -3,39 +3,78 @@ package sarin
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
tea "charm.land/bubbletea/v2"
|
||||
"github.com/charmbracelet/x/term"
|
||||
)
|
||||
|
||||
const forceExitCode = 130
|
||||
const (
|
||||
forceExitCode = 130
|
||||
// forceExitWait bounds the wait for the program to restore the terminal.
|
||||
forceExitWait = 2 * time.Second
|
||||
// killingWait bounds the "killing..." write, which a stuck terminal blocks.
|
||||
killingWait = 100 * time.Millisecond
|
||||
)
|
||||
|
||||
// StopController coordinates a two-stage shutdown.
|
||||
//
|
||||
// The first Stop call cancels the supplied context so workers and the job
|
||||
// loop can drain. The second Stop call restores the terminal (if a bubbletea
|
||||
// program has been attached) and calls os.Exit(forceExitCode), bypassing any
|
||||
// in-flight captcha polls, Lua/JS scripts, or HTTP requests that would
|
||||
// otherwise keep the process alive.
|
||||
// StopController is the single place a run is stopped from.
|
||||
// The first Stop drains the run, the second exits at once.
|
||||
type StopController struct {
|
||||
count atomic.Int32
|
||||
cancel func()
|
||||
mu sync.Mutex
|
||||
program *tea.Program
|
||||
count atomic.Int32
|
||||
cancel func()
|
||||
mu sync.Mutex
|
||||
program *tea.Program
|
||||
programDone chan struct{} // closed when Run returns
|
||||
ttyState *term.State // stdin before the program made it raw
|
||||
}
|
||||
|
||||
func NewStopController(cancel func()) *StopController {
|
||||
return &StopController{cancel: cancel}
|
||||
}
|
||||
|
||||
// AttachProgram registers the active bubbletea program so the terminal state
|
||||
// can be restored before os.Exit on the forced shutdown path. Pass nil to
|
||||
// detach once the program has finished.
|
||||
func (s *StopController) AttachProgram(program *tea.Program) {
|
||||
// RunProgram runs p so a forced exit can quit it and wait for it.
|
||||
func (s *StopController) RunProgram(p *tea.Program) (tea.Model, error) {
|
||||
var ttyState *term.State
|
||||
if term.IsTerminal(os.Stdin.Fd()) {
|
||||
ttyState, _ = term.GetState(os.Stdin.Fd())
|
||||
}
|
||||
|
||||
done := make(chan struct{})
|
||||
s.mu.Lock()
|
||||
s.program = program
|
||||
s.program, s.programDone, s.ttyState = p, done, ttyState
|
||||
s.mu.Unlock()
|
||||
|
||||
defer func() {
|
||||
s.mu.Lock()
|
||||
s.program, s.programDone, s.ttyState = nil, nil, nil
|
||||
s.mu.Unlock()
|
||||
close(done)
|
||||
}()
|
||||
|
||||
return p.Run()
|
||||
}
|
||||
|
||||
// ListenSignals routes SIGINT to Stop. SIGTERM comes from programs like timeout,
|
||||
// which may send it twice, so it only ever stops gracefully.
|
||||
func (s *StopController) ListenSignals() {
|
||||
sigChan := make(chan os.Signal, 4)
|
||||
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
|
||||
for sig := range sigChan {
|
||||
if sig == syscall.SIGTERM {
|
||||
s.stopGracefully()
|
||||
continue
|
||||
}
|
||||
s.Stop()
|
||||
}
|
||||
}
|
||||
|
||||
// Stopping reports whether a stop has been requested.
|
||||
func (s *StopController) Stopping() bool {
|
||||
return s.count.Load() > 0
|
||||
}
|
||||
|
||||
func (s *StopController) Stop() {
|
||||
@@ -43,13 +82,48 @@ func (s *StopController) Stop() {
|
||||
case 1:
|
||||
s.cancel()
|
||||
case 2:
|
||||
s.mu.Lock()
|
||||
p := s.program
|
||||
s.mu.Unlock()
|
||||
if p != nil {
|
||||
_ = p.ReleaseTerminal()
|
||||
}
|
||||
fmt.Fprintln(os.Stderr, "killing...")
|
||||
os.Exit(forceExitCode)
|
||||
go s.forceExit()
|
||||
}
|
||||
}
|
||||
|
||||
// stopGracefully starts the graceful stop unless a stop has already started.
|
||||
func (s *StopController) stopGracefully() {
|
||||
if s.count.CompareAndSwap(0, 1) {
|
||||
s.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
// forceExit quits the program, waits up to forceExitWait for it, then exits.
|
||||
func (s *StopController) forceExit() {
|
||||
s.mu.Lock()
|
||||
p, programDone, ttyState := s.program, s.programDone, s.ttyState
|
||||
s.mu.Unlock()
|
||||
|
||||
quit := make(chan struct{})
|
||||
go func() {
|
||||
if p != nil {
|
||||
p.Quit()
|
||||
<-programDone
|
||||
}
|
||||
close(quit)
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-quit:
|
||||
case <-time.After(forceExitWait):
|
||||
if ttyState != nil {
|
||||
_ = term.Restore(os.Stdin.Fd(), ttyState)
|
||||
}
|
||||
}
|
||||
|
||||
printed := make(chan struct{})
|
||||
go func() {
|
||||
fmt.Fprintln(os.Stderr, "killing...")
|
||||
close(printed)
|
||||
}()
|
||||
select {
|
||||
case <-printed:
|
||||
case <-time.After(killingWait):
|
||||
}
|
||||
os.Exit(forceExitCode)
|
||||
}
|
||||
+33
-36
@@ -2,6 +2,8 @@ package sarin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -68,23 +70,22 @@ func renderLogBox(logs []string) string {
|
||||
return logChannelStyle.Render(b.String())
|
||||
}
|
||||
|
||||
func helpLine(cancelling bool) string {
|
||||
if cancelling {
|
||||
func helpLine(stopping bool) string {
|
||||
if stopping {
|
||||
return helpStyle.Render("Stopping... (Ctrl+C again to force)")
|
||||
}
|
||||
return helpStyle.Render("Press Ctrl+C to quit")
|
||||
}
|
||||
|
||||
type progressModel struct {
|
||||
progress progress.Model
|
||||
startTime time.Time
|
||||
logs []string
|
||||
counter *atomic.Uint64
|
||||
maxValue uint64
|
||||
showBar bool
|
||||
ctx context.Context //nolint:containedctx
|
||||
stop func()
|
||||
cancelling bool
|
||||
progress progress.Model
|
||||
startTime time.Time
|
||||
logs []string
|
||||
counter *atomic.Uint64
|
||||
maxValue uint64
|
||||
showBar bool
|
||||
ctx context.Context //nolint:containedctx
|
||||
stopCtrl *StopController
|
||||
}
|
||||
|
||||
func (m progressModel) Init() tea.Cmd {
|
||||
@@ -95,8 +96,7 @@ func (m progressModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case tea.KeyPressMsg:
|
||||
if msg.String() == "ctrl+c" {
|
||||
m.cancelling = true
|
||||
m.stop()
|
||||
m.stopCtrl.Stop()
|
||||
}
|
||||
return m, nil
|
||||
|
||||
@@ -150,7 +150,7 @@ func (m progressModel) View() tea.View {
|
||||
}
|
||||
|
||||
b.WriteString("\n\n ")
|
||||
b.WriteString(helpLine(m.cancelling))
|
||||
b.WriteString(helpLine(m.stopCtrl.Stopping()))
|
||||
return tea.NewView(b.String())
|
||||
}
|
||||
|
||||
@@ -163,15 +163,14 @@ func progressTickCmd() tea.Cmd {
|
||||
var infiniteProgressStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#00D4FF"))
|
||||
|
||||
type infiniteProgressModel struct {
|
||||
spinner spinner.Model
|
||||
startTime time.Time
|
||||
counter *atomic.Uint64
|
||||
logs []string
|
||||
showBar bool
|
||||
ctx context.Context //nolint:containedctx
|
||||
quit bool
|
||||
stop func()
|
||||
cancelling bool
|
||||
spinner spinner.Model
|
||||
startTime time.Time
|
||||
counter *atomic.Uint64
|
||||
logs []string
|
||||
showBar bool
|
||||
ctx context.Context //nolint:containedctx
|
||||
quit bool
|
||||
stopCtrl *StopController
|
||||
}
|
||||
|
||||
func (m infiniteProgressModel) Init() tea.Cmd {
|
||||
@@ -182,8 +181,7 @@ func (m infiniteProgressModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case tea.KeyPressMsg:
|
||||
if msg.String() == "ctrl+c" {
|
||||
m.cancelling = true
|
||||
m.stop()
|
||||
m.stopCtrl.Stop()
|
||||
}
|
||||
return m, nil
|
||||
|
||||
@@ -219,7 +217,7 @@ func (m infiniteProgressModel) View() tea.View {
|
||||
if !m.showBar {
|
||||
if !m.quit {
|
||||
b.WriteString("\n\n ")
|
||||
b.WriteString(helpLine(m.cancelling))
|
||||
b.WriteString(helpLine(m.stopCtrl.Stopping()))
|
||||
}
|
||||
return tea.NewView(b.String())
|
||||
}
|
||||
@@ -240,7 +238,7 @@ func (m infiniteProgressModel) View() tea.View {
|
||||
b.WriteString(" ")
|
||||
b.WriteString(time.Since(m.startTime).Round(time.Second / 10).String())
|
||||
b.WriteString("\n\n ")
|
||||
b.WriteString(helpLine(m.cancelling))
|
||||
b.WriteString(helpLine(m.stopCtrl.Stopping()))
|
||||
}
|
||||
return tea.NewView(b.String())
|
||||
}
|
||||
@@ -267,10 +265,11 @@ func (s sarin) streamProgress(
|
||||
maxValue: total,
|
||||
showBar: showBar,
|
||||
ctx: ctx,
|
||||
stop: stopCtrl.Stop,
|
||||
stopCtrl: stopCtrl,
|
||||
}
|
||||
|
||||
program = tea.NewProgram(model)
|
||||
// Sarin handles SIGINT/SIGTERM itself.
|
||||
program = tea.NewProgram(model, tea.WithoutSignalHandler())
|
||||
} else {
|
||||
model := infiniteProgressModel{
|
||||
spinner: spinner.New(
|
||||
@@ -296,16 +295,14 @@ func (s sarin) streamProgress(
|
||||
logs: make([]string, logBoxLines),
|
||||
showBar: showBar,
|
||||
ctx: ctx,
|
||||
stop: stopCtrl.Stop,
|
||||
stopCtrl: stopCtrl,
|
||||
quit: false,
|
||||
}
|
||||
|
||||
program = tea.NewProgram(model)
|
||||
// Sarin handles SIGINT/SIGTERM itself.
|
||||
program = tea.NewProgram(model, tea.WithoutSignalHandler())
|
||||
}
|
||||
|
||||
stopCtrl.AttachProgram(program)
|
||||
defer stopCtrl.AttachProgram(nil)
|
||||
|
||||
// Bubble Tea repaints once per message, so forwarding every log made the run
|
||||
// wait on the terminal. Send only what the box shows, on a fixed cadence.
|
||||
go func() {
|
||||
@@ -338,8 +335,8 @@ func (s sarin) streamProgress(
|
||||
}
|
||||
}()
|
||||
|
||||
if _, err := program.Run(); err != nil {
|
||||
panic(err)
|
||||
if _, err := stopCtrl.RunProgram(program); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "progress display: "+err.Error())
|
||||
}
|
||||
|
||||
done <- struct{}{}
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
|
||||
src = lib.cleanSource ../.;
|
||||
|
||||
vendorHash = "sha256-IlswpF2Qmgi62timxd/xppg3tAyoQFdzkbda4nBFwE0=";
|
||||
vendorHash = "sha256-aBwlFhNylVAI1iETa1vbNNiUBJVw+brU2+hrzpyhr+4=";
|
||||
|
||||
subPackages = [ "cmd/cli" ];
|
||||
|
||||
|
||||
Reference in new issue
Block a user