Skip to content

Commit

Permalink
update progress
Browse files Browse the repository at this point in the history
  • Loading branch information
zan8in committed Feb 27, 2024
1 parent dee73c9 commit 8c0d3f0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
5 changes: 3 additions & 2 deletions cmd/afrog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ func main() {
if !options.Silent {
// 花里胡哨的进度条,看起来炫,实际并没什么卵用! @edit 2024/01/03
pgress := int(options.CurrentCount) * 100 / options.Count
bar := progress.CreateProgressBar(pgress, 50, '|', '=')
// bar := progress.CreateProgressBar(pgress, 50, '|', '=')
// bar := progress.CreateProgressBar(pgress, 50, '▉', '░') 操蛋的 windows cmd 不兼容漂亮的进度条
fmt.Printf("\r%s %d%% (%d/%d), %s", bar, pgress, options.CurrentCount, options.Count, strings.Split(time.Since(starttime).String(), ".")[0]+"s")
// fmt.Printf("\r%s %d%% (%d/%d), %s", bar, pgress, options.CurrentCount, options.Count, strings.Split(time.Since(starttime).String(), ".")[0]+"s")
// fmt.Printf("\r%d%% (%d/%d), %s", int(options.CurrentCount)*100/int(options.Count), options.CurrentCount, options.Count, strings.Split(time.Since(starttime).String(), ".")[0]+"s")
// fmt.Printf("\r%d/%d/%d%%/%s", options.CurrentCount, options.Count, int(options.CurrentCount)*100/int(options.Count), strings.Split(time.Since(starttime).String(), ".")[0]+"s")
fmt.Printf("\r[%s] %d%% (%d/%d), %s", progress.GetProgressBar(pgress, 0), pgress, options.CurrentCount, options.Count, strings.Split(time.Since(starttime).String(), ".")[0]+"s")
}
}()
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/config/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ func BannerAnimate(u *AfrogUpdate) {
}

func ShowVersion() {
InitBanner()
fmt.Printf("%s\n\n", Version)
fmt.Printf("\r\nafrog Version %s\n\n", Version)
}

func EngineV(u *AfrogUpdate) string {
Expand Down
27 changes: 14 additions & 13 deletions pkg/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func NewOptions() (*Options, error) {

flagSet.CreateGroup("debug", "Debug",
flagSet.BoolVar(&options.Debug, "debug", false, "show all requests and responses"),
flagSet.BoolVar(&options.Version, "version", false, "show afrog version"),
flagSet.BoolVarP(&options.Version, "version", "v", false, "show afrog version"),
)

flagSet.CreateGroup("server", "Server",
Expand Down Expand Up @@ -287,6 +287,19 @@ func (opt *Options) VerifyOptions() error {
}
opt.Config = config

// update afrog-pocs
au, err := NewAfrogUpdate(true)
if err != nil {
return err
}

if !opt.DisableUpdateCheck {
info, _ := au.AfrogUpdatePocs()
if len(info) > 0 && opt.UpdatePocs {
gologger.Info().Msg(info)
}
}

if opt.Dingtalk {
if dingtalk.IsTokensEmpty(opt.Config.Webhook.Dingtalk.Tokens) {
return fmt.Errorf("Dingtalk webhook token is required")
Expand Down Expand Up @@ -347,18 +360,6 @@ func (opt *Options) VerifyOptions() error {
os.Exit(0)
}

au, err := NewAfrogUpdate(true)
if err != nil {
return err
}

if !opt.DisableUpdateCheck {
info, _ := au.AfrogUpdatePocs()
if len(info) > 0 && opt.UpdatePocs {
gologger.Info().Msg(info)
}
}

if len(opt.Target) > 0 || len(opt.TargetsFile) > 0 || (len(opt.Cyberspace) > 0 && len(opt.Query) > 0) {

ShowBanner(au)
Expand Down
12 changes: 12 additions & 0 deletions pkg/progress/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,15 @@ func CreateProgressBar(progress, length int, filled, empty rune) string {
bar := strings.Repeat(string(filled), filledCount) + strings.Repeat(string(empty), emptyCount)
return bar
}

// 进度条2
func GetProgressBar(progress, width int) string {
if width == 0 {
width = 50
}
barLength := progress * width / 100
progressBar := strings.Repeat("=", barLength)
progressBar += ">"
progressBar += strings.Repeat("-", width-barLength)
return progressBar
}

0 comments on commit 8c0d3f0

Please sign in to comment.