@@ -61,13 +61,14 @@ func getTerminalSize() (int, int) {
61
61
return cols , rows
62
62
}
63
63
64
- func printWelcomeMessage (buf * bytes.Buffer ) int {
64
+ func printWelcomeMessage (buf * bytes.Buffer , configCount int ) int {
65
65
messages := []string {
66
66
"Welcome!" ,
67
67
"This program can run any pre-config BAT file." ,
68
68
"Author: ANKDDEV https://github.com/ankddev" ,
69
69
fmt .Sprintf ("Version: %s" , version ),
70
70
"===" ,
71
+ fmt .Sprintf ("Found %d pre-configs" , configCount ),
71
72
"\n Using ARROWS on your keyboard, select BAT file from list for running or select 'Run BLOCKCHECK (Auto-setting BAT parameters)' or select 'Exit'.\n " ,
72
73
"For selection press ENTER." ,
73
74
}
@@ -80,20 +81,20 @@ func printWelcomeMessage(buf *bytes.Buffer) int {
80
81
81
82
var version string
82
83
83
- func getOptions () []string {
84
+ func getOptions () ( []string , int ) {
84
85
options := []string {
85
86
"Exit" ,
86
87
"Run BLOCKCHECK (Auto-setting BAT parameters)" ,
87
88
}
88
89
89
90
currentDir , err := os .Getwd ()
90
91
if err != nil {
91
- return options
92
+ return options , 0
92
93
}
93
94
94
95
files , err := os .ReadDir (filepath .Join (currentDir , "pre-configs" ))
95
96
if err != nil {
96
- return options
97
+ return options , 0
97
98
}
98
99
99
100
var batFiles []string
@@ -106,33 +107,28 @@ func getOptions() []string {
106
107
sort .Strings (batFiles )
107
108
options = append (options , batFiles ... )
108
109
109
- return options
110
+ return options , len ( batFiles )
110
111
}
111
112
112
113
func Run () error {
113
114
setupTerminalCleanup ()
114
115
defer fmt .Print (showCursor + exitAltScreen )
115
116
116
- // Initialize terminal
117
117
initTerminal ()
118
118
119
- // Get terminal size
120
119
_ , termHeight := getTerminalSize ()
121
120
122
121
var buf bytes.Buffer
123
122
124
- // Print welcome message
125
- currentLine := printWelcomeMessage (& buf )
126
- fmt .Print (buf .String ())
127
-
128
- // Get options list
129
- options := getOptions ()
123
+ options , configCount := getOptions ()
130
124
if len (options ) == 0 {
131
125
fmt .Println ("Can't find any BAT files in current directory." )
132
126
return nil
133
127
}
134
128
135
- // Start main UI loop
129
+ currentLine := printWelcomeMessage (& buf , configCount )
130
+ fmt .Print (buf .String ())
131
+
136
132
if err := runMainLoop (& buf , options , currentLine , termHeight ); err != nil {
137
133
return err
138
134
}
@@ -148,10 +144,8 @@ func main() {
148
144
}
149
145
150
146
func runMainLoop (buf * bytes.Buffer , options []string , startRow , termHeight int ) error {
151
- // Pre-allocate buffer
152
147
buf .Grow (bufferSize )
153
148
154
- // Create output buffer for direct writes
155
149
output := bufio .NewWriter (os .Stdout )
156
150
defer output .Flush ()
157
151
@@ -170,32 +164,28 @@ func runMainLoop(buf *bytes.Buffer, options []string, startRow, termHeight int)
170
164
buf .Reset ()
171
165
buf .WriteString ("\033 [H\033 [J" )
172
166
173
- printWelcomeMessage (buf )
167
+ options , configCount := getOptions ()
168
+ printWelcomeMessage (buf , configCount )
174
169
175
- // Show scroll indicators
176
170
if scrollOffset > 0 {
177
171
buf .WriteString (fmt .Sprintf ("%s↑ more items above%s\n " , colorGrey , colorReset ))
178
172
}
179
173
180
- // Calculate visible range
181
174
endIdx := min (scrollOffset + maxVisibleOptions , len (options ))
182
175
183
- // Update scroll position
184
176
if currentSelection >= scrollOffset + maxVisibleOptions - 1 {
185
177
scrollOffset = currentSelection - maxVisibleOptions + 2
186
178
} else if currentSelection < scrollOffset {
187
179
scrollOffset = currentSelection
188
180
}
189
181
190
- // Ensure scroll bounds
191
182
if scrollOffset < 0 {
192
183
scrollOffset = 0
193
184
}
194
185
if scrollOffset > len (options )- maxVisibleOptions {
195
186
scrollOffset = max (0 , len (options )- maxVisibleOptions )
196
187
}
197
188
198
- // Batch write visible options
199
189
for i := scrollOffset ; i < endIdx ; i ++ {
200
190
if i == currentSelection {
201
191
buf .WriteString (fmt .Sprintf ("%s► %s%s\n " , colorCyan , options [i ], colorReset ))
@@ -208,17 +198,14 @@ func runMainLoop(buf *bytes.Buffer, options []string, startRow, termHeight int)
208
198
buf .WriteString (fmt .Sprintf ("%s↓ more items below%s\n " , colorGrey , colorReset ))
209
199
}
210
200
211
- // Single write operation
212
201
output .Write (buf .Bytes ())
213
202
output .Flush ()
214
203
215
- // Precise frame timing
216
204
elapsed := time .Since (start )
217
205
if elapsed < frameTime {
218
206
time .Sleep (frameTime - elapsed )
219
207
}
220
208
221
- // Non-blocking keyboard input
222
209
if _ , key , err := keyboard .GetKey (); err == nil {
223
210
switch key {
224
211
case keyboard .KeyArrowUp :
0 commit comments