-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.go
More file actions
3710 lines (3272 loc) · 123 KB
/
main.go
File metadata and controls
3710 lines (3272 loc) · 123 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package main
import (
"crypto/md5"
"crypto/tls"
"encoding/csv"
"encoding/json"
"flag"
"fmt"
"io"
"math"
"math/rand"
"net"
"net/http"
"net/url"
"os"
"os/exec"
"regexp"
"runtime"
"sort"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/gdamore/tcell/v2"
)
// getClipboard returns the clipboard content (cross-platform)
func getClipboard() string {
var cmd *exec.Cmd
switch runtime.GOOS {
case "windows":
cmd = exec.Command("powershell", "-command", "Get-Clipboard")
case "darwin":
cmd = exec.Command("pbpaste")
default: // linux
cmd = exec.Command("xclip", "-selection", "clipboard", "-o")
}
out, err := cmd.Output()
if err != nil {
return ""
}
// Trim whitespace and newlines
return strings.TrimSpace(string(out))
}
const (
Version = "1.0.1"
UserAgent = "PathFinder/1.0 (Security Research)"
DefaultConcurrency = 50
DefaultTimeout = 10
MinRedirectCount = 3
MaxRedirects = 10
)
// ===========================================================================
// THEME SYSTEM
// ===========================================================================
type Theme struct {
Name string
Background tcell.Color
Text tcell.Color
Primary tcell.Color
Success tcell.Color
Warning tcell.Color
Danger tcell.Color
Info tcell.Color
Border tcell.Color
Globe tcell.Color
}
var (
ThemeMatrix = Theme{
Name: "MATRIX",
Background: tcell.ColorBlack,
Text: tcell.ColorWhite,
Primary: tcell.NewRGBColor(0, 255, 0),
Success: tcell.NewRGBColor(0, 255, 0),
Warning: tcell.ColorYellow,
Danger: tcell.NewRGBColor(255, 0, 0),
Info: tcell.NewRGBColor(0, 255, 255),
Border: tcell.NewRGBColor(0, 180, 0),
Globe: tcell.NewRGBColor(0, 255, 0),
}
ThemeRainbow = Theme{
Name: "RAINBOW",
Background: tcell.ColorBlack,
Text: tcell.ColorWhite,
Primary: tcell.NewRGBColor(255, 0, 255),
Success: tcell.NewRGBColor(0, 255, 0),
Warning: tcell.NewRGBColor(255, 255, 0),
Danger: tcell.NewRGBColor(255, 0, 0),
Info: tcell.NewRGBColor(0, 255, 255),
Border: tcell.NewRGBColor(255, 0, 255),
Globe: tcell.NewRGBColor(255, 0, 255),
}
ThemeCyber = Theme{
Name: "CYBER",
Background: tcell.ColorBlack,
Text: tcell.ColorWhite,
Primary: tcell.NewRGBColor(0, 255, 255),
Success: tcell.NewRGBColor(0, 255, 0),
Warning: tcell.NewRGBColor(255, 255, 0),
Danger: tcell.NewRGBColor(255, 0, 0),
Info: tcell.NewRGBColor(0, 255, 255),
Border: tcell.NewRGBColor(0, 200, 255),
Globe: tcell.NewRGBColor(0, 255, 255),
}
ThemeBlood = Theme{
Name: "BLOOD",
Background: tcell.ColorBlack,
Text: tcell.ColorWhite,
Primary: tcell.NewRGBColor(255, 0, 0),
Success: tcell.NewRGBColor(0, 255, 0),
Warning: tcell.NewRGBColor(255, 255, 0),
Danger: tcell.NewRGBColor(255, 0, 0),
Info: tcell.NewRGBColor(255, 100, 100),
Border: tcell.NewRGBColor(200, 0, 0),
Globe: tcell.NewRGBColor(255, 0, 0),
}
ThemeSkittles = Theme{
Name: "SKITTLES",
Background: tcell.ColorBlack,
Text: tcell.NewRGBColor(255, 255, 255),
Primary: tcell.NewRGBColor(255, 0, 255),
Success: tcell.NewRGBColor(0, 255, 0),
Warning: tcell.NewRGBColor(255, 255, 0),
Danger: tcell.NewRGBColor(255, 0, 0),
Info: tcell.NewRGBColor(0, 255, 255),
Border: tcell.NewRGBColor(255, 105, 180),
Globe: tcell.NewRGBColor(255, 0, 255),
}
ThemeDark = Theme{
Name: "DARK",
Background: tcell.ColorBlack,
Text: tcell.NewRGBColor(200, 200, 200),
Primary: tcell.NewRGBColor(100, 150, 255),
Success: tcell.NewRGBColor(100, 200, 150),
Warning: tcell.NewRGBColor(255, 200, 100),
Danger: tcell.NewRGBColor(255, 100, 100),
Info: tcell.NewRGBColor(150, 180, 255),
Border: tcell.NewRGBColor(120, 120, 150),
Globe: tcell.NewRGBColor(100, 150, 255),
}
ThemePurple = Theme{
Name: "PURPLE",
Background: tcell.ColorBlack,
Text: tcell.NewRGBColor(220, 180, 255),
Primary: tcell.NewRGBColor(180, 100, 255),
Success: tcell.NewRGBColor(150, 255, 150),
Warning: tcell.NewRGBColor(255, 180, 100),
Danger: tcell.NewRGBColor(255, 100, 150),
Info: tcell.NewRGBColor(200, 150, 255),
Border: tcell.NewRGBColor(150, 80, 200),
Globe: tcell.NewRGBColor(180, 100, 255),
}
ThemeAmber = Theme{
Name: "AMBER",
Background: tcell.ColorBlack,
Text: tcell.NewRGBColor(255, 180, 0),
Primary: tcell.NewRGBColor(255, 200, 50),
Success: tcell.NewRGBColor(255, 220, 100),
Warning: tcell.NewRGBColor(255, 150, 0),
Danger: tcell.NewRGBColor(200, 100, 0),
Info: tcell.NewRGBColor(255, 190, 70),
Border: tcell.NewRGBColor(200, 140, 0),
Globe: tcell.NewRGBColor(255, 180, 0),
}
ThemeWhite = Theme{
Name: "WHITE",
Background: tcell.ColorBlack,
Text: tcell.ColorWhite,
Primary: tcell.NewRGBColor(255, 255, 255),
Success: tcell.NewRGBColor(0, 255, 0),
Warning: tcell.NewRGBColor(255, 255, 0),
Danger: tcell.NewRGBColor(255, 255, 255),
Info: tcell.NewRGBColor(200, 200, 200),
Border: tcell.NewRGBColor(180, 180, 180),
Globe: tcell.NewRGBColor(255, 255, 255),
}
ThemeNeon = Theme{
Name: "NEON",
Background: tcell.ColorBlack,
Text: tcell.NewRGBColor(0, 255, 200),
Primary: tcell.NewRGBColor(255, 0, 255),
Success: tcell.NewRGBColor(0, 255, 100),
Warning: tcell.NewRGBColor(255, 255, 0),
Danger: tcell.NewRGBColor(255, 0, 100),
Info: tcell.NewRGBColor(0, 200, 255),
Border: tcell.NewRGBColor(255, 0, 200),
Globe: tcell.NewRGBColor(0, 255, 255),
}
CurrentTheme = ThemeSkittles
)
// ===========================================================================
// DATA STRUCTURES
// ===========================================================================
type RedirectStep struct {
URL string
Status int
}
type ScanResult struct {
OriginalPath string
OriginalURL string
FinalStatus int
FinalURL string
RedirectChain []RedirectStep
ContentLength int
ContentHash string
IsDirect200 bool
ResponseTime time.Duration
Timestamp time.Time
}
type LiveStats struct {
mu sync.RWMutex
TotalRequests int64
CompletedRequests int64
Direct200s int64
Redirect200s int64 // 200 responses after redirect
Redirects int64
Errors int64
Protected int64
CurrentSpeed float64
StartTime time.Time
EndTime time.Time // Track when scan completes
LastUpdate time.Time
}
type Statistics struct {
mu sync.Mutex
TotalScanned int
Direct200s []*ScanResult
Redirect200s []*ScanResult // 200 responses after redirect (HITS)
Redirects []*ScanResult
RedirectTargets map[string]int
ContentHashes map[string][]*ScanResult
OtherCodes []*ScanResult
}
type WildcardBaseline struct {
Hash string
Length int
Status int
}
type Config struct {
StatusCodes []int
FilterStatuses []int
FilterSizes []int
MatchRegex *regexp.Regexp
Extensions []string
CustomHeaders map[string]string
Cookie string
Method string
RateLimit int
Delay time.Duration
Recursive bool
RecursionDepth int
OutputFile string
OutputFormat string
Theme string
}
type Scanner struct {
BaseURL string
Concurrency int
Timeout time.Duration
Verbose bool
Client *http.Client
Stats *Statistics
LiveStats *LiveStats
WildcardBaseline *WildcardBaseline
Config *Config
visitedPaths map[string]bool
pathMutex sync.Mutex
recursionQueue chan string
recursionWg sync.WaitGroup
rateLimiter <-chan time.Time
lastResults []*ScanResult
resultsMutex sync.Mutex
cancelScan bool // Flag to cancel active scan
cancelMutex sync.Mutex // Mutex for cancel flag
}
// ===========================================================================
// GLOBE RENDERING
// ===========================================================================
type Globe struct {
Width int
Height int
Rotation float64
AspectRatio float64
Radius float64
EarthMap []string
MapWidth int
MapHeight int
}
func getEarthBitmap() []string {
return []string{
" ",
" ",
" ",
" # ####### ################# # ",
" # # ### ################# ### ",
" ### ## #### ############ # ## ######## ##### ",
" ## ### # ### ## ########### # #### ################ ### ",
" ######## ###### #### # # # ### ######### ####### # ## ##################################",
" ### ########################### #### ##### # ####### ###############################################",
" ######################## ## #### #### ####################################################",
" ### # ################# ## # ##### # ########################################## ## ",
" ############## ##### # # ####################################### ## ",
" ################ ####### # # ########################################### ## ",
" ######################## ################################################ ",
" ################### ## ################################################ ",
" ################### # ########## #### ############################ ",
" ################## ##### ## ### ### ########################## ",
" ################# ### # ######## ###################### # # ",
" ############### # ### ############################## # # ",
" ############# ###### ############################# ",
" ######## # ############################################ ",
" # #### # ##################### ####################### ",
" # ### # ################# ###### ################# ",
" ### # # ################## ###### #### ##### ",
" ##### # # ################## ##### ### #### ",
" #### ################### ### ## #### # ",
" # # #################### # # ## ",
" # ##### ##################### # # # ## ",
" ###### #### ############### # # # ",
" ######## ############ ## ## ",
" ######### ########### # #### ",
" ############# ########## ##### # ## ",
" ################ ######## ## # ",
" ############### ######### ## # # # ",
" ############# ######### ",
" ############ ######### # # ## # ",
" ########## ######### ## ######## ",
" ########## ####### ## ########### # ",
" ######## ####### # ############# ",
" ####### ###### ############## ",
" ####### ##### ############# ",
" ###### #### ### ###### ",
" ##### #### # ",
" ##### #",
" ### # # ",
" ### ## ",
" ## ",
" ## ",
" ## ",
" ",
" ",
" ",
" # ",
" # # ########## ######################## ",
" ##### ########################## ################################# ",
" # ## # ############# ############################################################# ",
" ## ######################### ################################################################## ",
" ######################## # # ## ################################################################# ",
" ################################################################################################################## ",
"########################################################################################################################",
}
}
func NewGlobe(width, height int) *Globe {
earthMap := getEarthBitmap()
effectiveHeight := float64(height) * 2.0
radius := math.Min(float64(width)/2.5, effectiveHeight/2.5)
return &Globe{
Width: width,
Height: height,
Rotation: 0,
AspectRatio: 2.0,
Radius: radius,
EarthMap: earthMap,
MapWidth: len(earthMap[0]),
MapHeight: len(earthMap),
}
}
func (g *Globe) sampleEarthAt(lat, lon float64) rune {
latNorm := (lat + 90) / 180
lonNorm := (lon + 180) / 360
y := int(latNorm * float64(g.MapHeight-1))
x := int(lonNorm * float64(g.MapWidth-1))
if y < 0 {
y = 0
}
if y >= g.MapHeight {
y = g.MapHeight - 1
}
if x < 0 {
x = 0
}
if x >= g.MapWidth {
x = g.MapWidth - 1
}
return rune(g.EarthMap[y][x])
}
func densityToASCII(density float64) rune {
if density > 1.0 {
return '@'
} else if density > 0.8 {
return '#'
} else if density > 0.6 {
return '%'
} else if density > 0.4 {
return 'o'
} else if density > 0.3 {
return '='
} else if density > 0.2 {
return '+'
} else if density > 0.15 {
return '-'
} else if density > 0.1 {
return '.'
} else if density > 0.05 {
return '`'
}
return ' '
}
func (g *Globe) Render() [][]rune {
if g.Width <= 0 || g.Height <= 0 {
return [][]rune{[]rune{' '}}
}
screen := make([][]rune, g.Height)
for i := range screen {
screen[i] = make([]rune, g.Width)
for j := range screen[i] {
screen[i][j] = ' '
}
}
density := make([][]float64, g.Height)
for i := range density {
density[i] = make([]float64, g.Width)
}
centerX, centerY := g.Width/2, g.Height/2
effectiveRadius := g.Radius
// Forward rendering: for each screen pixel, calculate what earth coordinate it represents
for y := 0; y < g.Height; y++ {
for x := 0; x < g.Width; x++ {
dx := float64(x - centerX)
dy := float64(y-centerY) * g.AspectRatio
distance := math.Sqrt(dx*dx + dy*dy)
if distance <= effectiveRadius {
// Normalize to unit sphere
nx := dx / effectiveRadius
ny := dy / effectiveRadius
// Calculate z coordinate (depth into sphere)
nz_squared := 1 - nx*nx - ny*ny
if nz_squared >= 0 {
nz := math.Sqrt(nz_squared)
// Convert to latitude/longitude
lat := math.Asin(ny) * 180 / math.Pi
lon := math.Atan2(nx, nz)*180/math.Pi + g.Rotation*180/math.Pi
// Normalize longitude to -180 to 180
for lon < -180 {
lon += 360
}
for lon > 180 {
lon -= 360
}
// Sample earth bitmap
earthChar := g.sampleEarthAt(lat, lon)
if earthChar != ' ' {
baseDensity := 1.0
switch earthChar {
case '#':
baseDensity = 1.0
case '.':
baseDensity = 0.6
default:
baseDensity = 0.8
}
density[y][x] += baseDensity
// Anti-aliasing: slightly brighten neighboring pixels
for dy := -1; dy <= 1; dy++ {
for dx := -1; dx <= 1; dx++ {
nx2, ny2 := x+dx, y+dy
if nx2 >= 0 && nx2 < g.Width && ny2 >= 0 && ny2 < g.Height {
density[ny2][nx2] += 0.05
}
}
}
}
}
}
// Draw edge/outline of sphere
if distance > effectiveRadius-0.5 && distance < effectiveRadius+0.5 {
density[y][x] += 0.2
}
}
}
// Convert density to characters
for y := 0; y < g.Height; y++ {
for x := 0; x < g.Width; x++ {
screen[y][x] = densityToASCII(density[y][x])
}
}
return screen
}
// ===========================================================================
// TUI DASHBOARD
// ===========================================================================
type TUI struct {
screen tcell.Screen
width int
height int
scanner *Scanner
globe *Globe
showGlobe bool
running bool
mutex sync.RWMutex
skittlesBoxColors [6]tcell.Color // Store random colors for Skittles theme
skittlesGlobeColors [16]tcell.Color // 16 random colors for Skittles globe
skittlesGlobePos [16][2]int // Random positions for colored globe chars
lastTheme string
showSplash bool
splashProgress float64 // 0.0 to 1.0 for animation
progressBarFrame int // Animation frame for progress bar
inputText string // User input text for URLs/domains
inputActive bool // Whether input field is active
showConfigMenu bool // Whether config menu is visible
configMenuSelected int // Currently selected menu item
configEditMode bool // Whether editing a config value
configEditText string // Temporary text while editing
showHelpScreen bool // Whether help screen is visible
resultsScrollOffset int // Scroll offset for live results
helpScrollOffset int // Scroll offset for help screen
// Pathfinding maze animation
mazeWidth int
mazeHeight int
maze [][]rune
mazeVisited [][]bool
mazeStart Point
mazeEnd Point
mazeAnimating bool
mazeComplete bool
lastScanActive bool // Track if scan was active in previous frame
mazeSyncMode bool // Whether maze is syncing with active scan
lastScanCompleted int64 // Last scan request count for delta calculation
lastTotalRequests int64 // Track when new scans start (TotalRequests increases)
mazeAnimationSequence []func() // Pre-calculated animation sequence
mazeCurrentStep int // Current step in animation sequence
mazeTotalSolutionSteps int // Total steps in complete solution
scanHasEverRun bool // Track if any scan has ever been run
hideNetworkInfo bool // Toggle to hide local network info (for screenshots/OpSec)
}
type Point struct {
x, y int
}
type QueueItem struct {
pos Point
path []Point
}
func NewTUI(scanner *Scanner) (*TUI, error) {
screen, err := tcell.NewScreen()
if err != nil {
return nil, err
}
if err := screen.Init(); err != nil {
return nil, err
}
screen.SetStyle(tcell.StyleDefault.Background(CurrentTheme.Background).Foreground(CurrentTheme.Text))
screen.Clear()
screen.Show() // Force clear to display immediately
width, height := screen.Size()
// Calculate maze dimensions to match box width above
titleWidth := width - 4
boxWidth := titleWidth/2 - 1
mazeWidth := boxWidth - 2 // Subtract 2 for left/right borders
mazeHeight := 14 // Reduced from 18 to fit better in normal CMD windows
tui := &TUI{
screen: screen,
width: width,
height: height,
scanner: scanner,
globe: NewGlobe(60, 25),
showGlobe: false,
running: true,
showSplash: true,
splashProgress: 0.0,
mazeWidth: mazeWidth,
mazeHeight: mazeHeight,
}
tui.initMaze()
return tui, nil
}
func (tui *TUI) drawText(x, y int, text string, style tcell.Style) {
// Rainbow colors for Rainbow theme
rainbowColors := []tcell.Color{
tcell.NewRGBColor(255, 0, 0), // Red
tcell.NewRGBColor(255, 127, 0), // Orange
tcell.NewRGBColor(255, 255, 0), // Yellow
tcell.NewRGBColor(0, 255, 0), // Green
tcell.NewRGBColor(0, 0, 255), // Blue
tcell.NewRGBColor(75, 0, 130), // Indigo
tcell.NewRGBColor(148, 0, 211), // Violet
}
for i, r := range text {
if x+i < tui.width {
finalStyle := style
// Apply rainbow colors if in Rainbow theme
if CurrentTheme.Name == "RAINBOW" {
// Wider diagonal stripes: divide by 4 for better readability
colorIdx := (((x + i) + y) / 4) % len(rainbowColors)
finalStyle = tcell.StyleDefault.Foreground(rainbowColors[colorIdx])
}
tui.screen.SetContent(x+i, y, r, nil, finalStyle)
}
}
}
func (tui *TUI) drawBox(x, y, width, height int, title string, style tcell.Style) {
// Rainbow colors for Rainbow theme
rainbowColors := []tcell.Color{
tcell.NewRGBColor(255, 0, 0), // Red
tcell.NewRGBColor(255, 127, 0), // Orange
tcell.NewRGBColor(255, 255, 0), // Yellow
tcell.NewRGBColor(0, 255, 0), // Green
tcell.NewRGBColor(0, 0, 255), // Blue
tcell.NewRGBColor(75, 0, 130), // Indigo
tcell.NewRGBColor(148, 0, 211), // Violet
}
getRainbowStyle := func(px, py int, baseStyle tcell.Style) tcell.Style {
if CurrentTheme.Name == "RAINBOW" {
// Wider diagonal stripes: divide by 4 for better readability
colorIdx := ((px + py) / 4) % len(rainbowColors)
return tcell.StyleDefault.Foreground(rainbowColors[colorIdx])
}
return baseStyle
}
// Top border
tui.screen.SetContent(x, y, '╔', nil, getRainbowStyle(x, y, style))
for i := 1; i < width-1; i++ {
tui.screen.SetContent(x+i, y, '═', nil, getRainbowStyle(x+i, y, style))
}
tui.screen.SetContent(x+width-1, y, '╗', nil, getRainbowStyle(x+width-1, y, style))
// Title
if title != "" {
titleText := fmt.Sprintf(" %s ", title)
titleX := x + (width-len(titleText))/2
tui.drawText(titleX, y, titleText, style.Bold(true))
}
// Sides
for i := 1; i < height-1; i++ {
tui.screen.SetContent(x, y+i, '║', nil, getRainbowStyle(x, y+i, style))
tui.screen.SetContent(x+width-1, y+i, '║', nil, getRainbowStyle(x+width-1, y+i, style))
}
// Bottom border
tui.screen.SetContent(x, y+height-1, '╚', nil, getRainbowStyle(x, y+height-1, style))
for i := 1; i < width-1; i++ {
tui.screen.SetContent(x+i, y+height-1, '═', nil, getRainbowStyle(x+i, y+height-1, style))
}
tui.screen.SetContent(x+width-1, y+height-1, '╝', nil, getRainbowStyle(x+width-1, y+height-1, style))
}
func (tui *TUI) generateSkittlesColors() {
// Bold, vibrant color palette with high contrast
colorPalette := []tcell.Color{
tcell.NewRGBColor(255, 0, 0), // Bright Red
tcell.NewRGBColor(255, 165, 0), // Orange
tcell.NewRGBColor(255, 255, 0), // Yellow
tcell.NewRGBColor(0, 255, 0), // Bright Green
tcell.NewRGBColor(0, 255, 255), // Cyan
tcell.NewRGBColor(0, 100, 255), // Bright Blue
tcell.NewRGBColor(138, 43, 226), // Blue Violet
tcell.NewRGBColor(255, 0, 255), // Magenta
tcell.NewRGBColor(255, 20, 147), // Deep Pink
tcell.NewRGBColor(255, 105, 180), // Hot Pink
tcell.NewRGBColor(50, 205, 50), // Lime Green
tcell.NewRGBColor(255, 69, 0), // Red Orange
}
// Shuffle and pick 6 random colors from the palette
used := make(map[int]bool)
for i := 0; i < 6; i++ {
var idx int
for {
idx = rand.Intn(len(colorPalette))
if !used[idx] {
used[idx] = true
break
}
}
tui.skittlesBoxColors[i] = colorPalette[idx]
}
}
// ===========================================================================
// MAZE PATHFINDING ANIMATION
// ===========================================================================
func (tui *TUI) initMaze() {
// Safety check: ensure dimensions are positive
if tui.mazeWidth <= 0 || tui.mazeHeight <= 0 {
return
}
// Initialize maze grid
tui.maze = make([][]rune, tui.mazeHeight)
tui.mazeVisited = make([][]bool, tui.mazeHeight)
for y := 0; y < tui.mazeHeight; y++ {
tui.maze[y] = make([]rune, tui.mazeWidth)
tui.mazeVisited[y] = make([]bool, tui.mazeWidth)
for x := 0; x < tui.mazeWidth; x++ {
if x == 0 || x == tui.mazeWidth-1 || y == 0 || y == tui.mazeHeight-1 {
tui.maze[y][x] = '#'
} else if rand.Float32() < 0.25 {
tui.maze[y][x] = '#'
} else {
tui.maze[y][x] = ' '
}
tui.mazeVisited[y][x] = false
}
}
tui.mazeStart = Point{1, 1}
tui.mazeEnd = Point{tui.mazeWidth - 2, tui.mazeHeight - 2}
tui.maze[tui.mazeStart.y][tui.mazeStart.x] = 'S'
tui.maze[tui.mazeEnd.y][tui.mazeEnd.x] = 'X'
// Pre-calculate entire BFS solution to build animation sequence
tui.mazeAnimationSequence = []func(){}
queue := []QueueItem{{pos: tui.mazeStart, path: []Point{}}}
visited := make([][]bool, tui.mazeHeight)
for y := 0; y < tui.mazeHeight; y++ {
visited[y] = make([]bool, tui.mazeWidth)
}
visited[tui.mazeStart.y][tui.mazeStart.x] = true
var finalPath []Point
foundPath := false
// Run BFS to completion and record each step
for len(queue) > 0 && !foundPath {
current := queue[0]
queue = queue[1:]
// Check if we reached the end
if current.pos.x == tui.mazeEnd.x && current.pos.y == tui.mazeEnd.y {
finalPath = current.path
foundPath = true
break
}
// Add multiple animation frames for exploring this position
// SLOW exploration = visible searching simulation (blue dots spreading)
pos := current.pos
for i := 0; i < 20; i++ { // 20 frames per exploration - slow and visible
tui.mazeAnimationSequence = append(tui.mazeAnimationSequence, func() {
if tui.maze[pos.y][pos.x] != 'S' && tui.maze[pos.y][pos.x] != 'X' {
tui.maze[pos.y][pos.x] = '·'
}
})
}
// Explore neighbors
neighbors := tui.getMazeNeighbors(current.pos, visited)
for _, neighbor := range neighbors {
visited[neighbor.y][neighbor.x] = true
newPath := append([]Point{}, current.path...)
newPath = append(newPath, current.pos)
queue = append(queue, QueueItem{pos: neighbor, path: newPath})
// Add multiple animation frames for marking as queued
nPos := neighbor
for i := 0; i < 10; i++ { // 10 frames per neighbor - part of slow exploration
tui.mazeAnimationSequence = append(tui.mazeAnimationSequence, func() {
if tui.maze[nPos.y][nPos.x] != 'X' {
tui.maze[nPos.y][nPos.x] = '?'
}
})
}
}
}
// Add path drawing steps - slower so it reaches X at exactly 100%
if foundPath {
for _, p := range finalPath {
pathPos := p
// Even slower path drawing - 120 frames per cell so it reaches X at 100%
for i := 0; i < 120; i++ {
tui.mazeAnimationSequence = append(tui.mazeAnimationSequence, func() {
if tui.maze[pathPos.y][pathPos.x] != 'S' && tui.maze[pathPos.y][pathPos.x] != 'X' {
tui.maze[pathPos.y][pathPos.x] = '*'
}
})
}
}
}
// Calculate total steps so far
baseSteps := len(tui.mazeAnimationSequence)
// Add very minimal padding - just 2-3% extra so animation completes at 98-100%
paddingFrames := baseSteps / 40 // Add ~2.5% padding
for i := 0; i < paddingFrames; i++ {
tui.mazeAnimationSequence = append(tui.mazeAnimationSequence, func() {
// No-op frame, just holds the final state very briefly
})
}
// Reset state for animation
tui.mazeAnimating = true
tui.mazeComplete = false
tui.mazeCurrentStep = 0
tui.mazeTotalSolutionSteps = len(tui.mazeAnimationSequence)
}
func (tui *TUI) getMazeNeighbors(pos Point, visited [][]bool) []Point {
neighbors := []Point{}
dirs := []Point{{0, -1}, {1, 0}, {0, 1}, {-1, 0}}
for _, dir := range dirs {
newX := pos.x + dir.x
newY := pos.y + dir.y
if newX > 0 && newX < tui.mazeWidth-1 && newY > 0 && newY < tui.mazeHeight-1 &&
tui.maze[newY][newX] != '#' && !visited[newY][newX] {
neighbors = append(neighbors, Point{newX, newY})
}
}
return neighbors
}
func (tui *TUI) stepMazeAnimation() {
// In free mode, auto-restart when complete ONLY if no scan has ever run (idle state)
if !tui.mazeSyncMode && tui.mazeComplete && !tui.scanHasEverRun {
tui.initMaze() // Generate new maze and restart
return
}
if !tui.mazeAnimating || tui.mazeComplete {
return
}
// Check if we've finished all animation steps
if tui.mazeCurrentStep >= tui.mazeTotalSolutionSteps {
tui.mazeComplete = true
tui.mazeAnimating = false
return
}
if tui.mazeSyncMode {
// Sync mode: Step based on scan progress
completed := atomic.LoadInt64(&tui.scanner.LiveStats.CompletedRequests)
total := tui.scanner.LiveStats.TotalRequests
if total > 0 && tui.mazeTotalSolutionSteps > 0 {
var targetStep int
// If scan is complete, ensure we execute ALL remaining frames
if completed >= total {
targetStep = tui.mazeTotalSolutionSteps
} else {
// Calculate target step based on scan progress
scanProgress := float64(completed) / float64(total)
targetStep = int(scanProgress * float64(tui.mazeTotalSolutionSteps))
}
// Execute ALL animation steps up to target instantly
// This makes animation speed match actual scan speed (fast scan = fast animation)
for tui.mazeCurrentStep < targetStep && tui.mazeCurrentStep < tui.mazeTotalSolutionSteps {
if tui.mazeCurrentStep < len(tui.mazeAnimationSequence) {
tui.mazeAnimationSequence[tui.mazeCurrentStep]()
}
tui.mazeCurrentStep++
}
// Check if we completed after sync execution
if tui.mazeCurrentStep >= tui.mazeTotalSolutionSteps {
tui.mazeComplete = true
tui.mazeAnimating = false
}
}
} else {
// Free running mode: Step through frames for watchable animation
// With increased frames, stepping 120 frames = smooth ~12-15 second animation
// Visual animation completes near 100%, minimal hold at end
framesPerStep := 120
for i := 0; i < framesPerStep && tui.mazeCurrentStep < tui.mazeTotalSolutionSteps; i++ {
if tui.mazeCurrentStep < len(tui.mazeAnimationSequence) {
tui.mazeAnimationSequence[tui.mazeCurrentStep]()
}
tui.mazeCurrentStep++
}
}
}
func (tui *TUI) renderMaze(startX, startY int) {
// Safety check: ensure maze is initialized and has valid dimensions
if tui.maze == nil || len(tui.maze) == 0 || tui.mazeHeight <= 0 || tui.mazeWidth <= 0 {
return
}
// Draw maze box
boxStyle := tcell.StyleDefault.Foreground(CurrentTheme.Border)
if CurrentTheme.Name == "SKITTLES" {
boxStyle = tcell.StyleDefault.Foreground(tui.skittlesBoxColors[2])
}
tui.drawBox(startX, startY, tui.mazeWidth+2, tui.mazeHeight+3, "PATHFINDER", boxStyle)
// Render maze with bounds checking
for y := 0; y < tui.mazeHeight && y < len(tui.maze); y++ {
for x := 0; x < tui.mazeWidth && x < len(tui.maze[y]); x++ {
char := tui.maze[y][x]
var style tcell.Style
switch char {
case '#':
style = tcell.StyleDefault.Foreground(CurrentTheme.Border)
case 'S':
style = tcell.StyleDefault.Foreground(CurrentTheme.Success).Bold(true)
case 'X':
style = tcell.StyleDefault.Foreground(CurrentTheme.Danger).Bold(true)
case '*':
style = tcell.StyleDefault.Foreground(CurrentTheme.Warning).Bold(true)
case '·':
style = tcell.StyleDefault.Foreground(CurrentTheme.Info).Dim(true)
case '?':
style = tcell.StyleDefault.Foreground(CurrentTheme.Primary)
default:
style = tcell.StyleDefault.Foreground(CurrentTheme.Text).Dim(true)
}
tui.screen.SetContent(startX+x+1, startY+y+2, char, nil, style)
}
}
// Status text
statusY := startY + tui.mazeHeight + 2
if tui.mazeComplete {
status := "Complete! Press F6 to reset"
tui.drawText(startX+2, statusY, status, tcell.StyleDefault.Foreground(CurrentTheme.Success))
} else if tui.mazeAnimating && tui.mazeSyncMode {
// Get scan progress to show in status
completed := atomic.LoadInt64(&tui.scanner.LiveStats.CompletedRequests)
total := tui.scanner.LiveStats.TotalRequests