Skip to content

Commit 076ccd0

Browse files
committed
feat: show count of found pre-configs in add_to_autorun and run_preconfig
1 parent 615502b commit 076ccd0

File tree

2 files changed

+20
-32
lines changed

2 files changed

+20
-32
lines changed

cmd/add_to_autorun/add_to_autorun.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func (sm *ServiceManager) installService(batFilePath string) error {
127127
return nil
128128
}
129129

130-
func getOptions() []string {
130+
func getOptions() ([]string, int) {
131131
options := []string{
132132
"Exit",
133133
"Delete service from autorun",
@@ -136,12 +136,12 @@ func getOptions() []string {
136136

137137
currentDir, err := os.Getwd()
138138
if err != nil {
139-
return options
139+
return options, 0
140140
}
141141

142142
files, err := os.ReadDir(filepath.Join(currentDir, "pre-configs"))
143143
if err != nil {
144-
return options
144+
return options, 0
145145
}
146146

147147
var batFiles []string
@@ -154,20 +154,21 @@ func getOptions() []string {
154154
sort.Strings(batFiles)
155155
options = append(options, batFiles...)
156156

157-
return options
157+
return options, len(batFiles)
158158
}
159159

160160
func clearScreen(buf *bytes.Buffer) {
161161
buf.WriteString(clearScreenSequence)
162162
}
163163

164-
func printWelcomeMessage(buf *bytes.Buffer) {
164+
func printWelcomeMessage(buf *bytes.Buffer, configCount int) {
165165
messages := []string{
166166
"Welcome!",
167167
"This program can install BAT file as service with autorun.",
168168
"Author: ANKDDEV https://github.com/ankddev",
169169
fmt.Sprintf("Version: %s", version),
170170
"===",
171+
fmt.Sprintf("Found %d pre-configs", configCount),
171172
"\nUsing ARROWS on your keyboard, select BAT file from list for installing service 'discordfix_zapret' or select 'Delete service from autorun' or 'Run BLOCKCHECK (Auto-setting BAT parameters)' or select 'Exit'.\n",
172173
"For selection press ENTER.",
173174
}
@@ -217,7 +218,7 @@ func main() {
217218
output := bufio.NewWriter(os.Stdout)
218219
defer output.Flush()
219220

220-
options := getOptions()
221+
options, configCount := getOptions()
221222
if len(options) == 0 {
222223
fmt.Println("Can't find any BAT files in current directory.")
223224
return
@@ -240,7 +241,7 @@ func main() {
240241
buf.Reset()
241242
buf.WriteString("\033[H\033[J")
242243

243-
printWelcomeMessage(&buf)
244+
printWelcomeMessage(&buf, configCount)
244245

245246
// Calculate visible range and scroll position
246247
endIdx := min(startIdx+visibleItems, len(options))

cmd/run_preconfig/run_preconfig.go

+12-25
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,14 @@ func getTerminalSize() (int, int) {
6161
return cols, rows
6262
}
6363

64-
func printWelcomeMessage(buf *bytes.Buffer) int {
64+
func printWelcomeMessage(buf *bytes.Buffer, configCount int) int {
6565
messages := []string{
6666
"Welcome!",
6767
"This program can run any pre-config BAT file.",
6868
"Author: ANKDDEV https://github.com/ankddev",
6969
fmt.Sprintf("Version: %s", version),
7070
"===",
71+
fmt.Sprintf("Found %d pre-configs", configCount),
7172
"\nUsing ARROWS on your keyboard, select BAT file from list for running or select 'Run BLOCKCHECK (Auto-setting BAT parameters)' or select 'Exit'.\n",
7273
"For selection press ENTER.",
7374
}
@@ -80,20 +81,20 @@ func printWelcomeMessage(buf *bytes.Buffer) int {
8081

8182
var version string
8283

83-
func getOptions() []string {
84+
func getOptions() ([]string, int) {
8485
options := []string{
8586
"Exit",
8687
"Run BLOCKCHECK (Auto-setting BAT parameters)",
8788
}
8889

8990
currentDir, err := os.Getwd()
9091
if err != nil {
91-
return options
92+
return options, 0
9293
}
9394

9495
files, err := os.ReadDir(filepath.Join(currentDir, "pre-configs"))
9596
if err != nil {
96-
return options
97+
return options, 0
9798
}
9899

99100
var batFiles []string
@@ -106,33 +107,28 @@ func getOptions() []string {
106107
sort.Strings(batFiles)
107108
options = append(options, batFiles...)
108109

109-
return options
110+
return options, len(batFiles)
110111
}
111112

112113
func Run() error {
113114
setupTerminalCleanup()
114115
defer fmt.Print(showCursor + exitAltScreen)
115116

116-
// Initialize terminal
117117
initTerminal()
118118

119-
// Get terminal size
120119
_, termHeight := getTerminalSize()
121120

122121
var buf bytes.Buffer
123122

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()
130124
if len(options) == 0 {
131125
fmt.Println("Can't find any BAT files in current directory.")
132126
return nil
133127
}
134128

135-
// Start main UI loop
129+
currentLine := printWelcomeMessage(&buf, configCount)
130+
fmt.Print(buf.String())
131+
136132
if err := runMainLoop(&buf, options, currentLine, termHeight); err != nil {
137133
return err
138134
}
@@ -148,10 +144,8 @@ func main() {
148144
}
149145

150146
func runMainLoop(buf *bytes.Buffer, options []string, startRow, termHeight int) error {
151-
// Pre-allocate buffer
152147
buf.Grow(bufferSize)
153148

154-
// Create output buffer for direct writes
155149
output := bufio.NewWriter(os.Stdout)
156150
defer output.Flush()
157151

@@ -170,32 +164,28 @@ func runMainLoop(buf *bytes.Buffer, options []string, startRow, termHeight int)
170164
buf.Reset()
171165
buf.WriteString("\033[H\033[J")
172166

173-
printWelcomeMessage(buf)
167+
options, configCount := getOptions()
168+
printWelcomeMessage(buf, configCount)
174169

175-
// Show scroll indicators
176170
if scrollOffset > 0 {
177171
buf.WriteString(fmt.Sprintf("%s↑ more items above%s\n", colorGrey, colorReset))
178172
}
179173

180-
// Calculate visible range
181174
endIdx := min(scrollOffset+maxVisibleOptions, len(options))
182175

183-
// Update scroll position
184176
if currentSelection >= scrollOffset+maxVisibleOptions-1 {
185177
scrollOffset = currentSelection - maxVisibleOptions + 2
186178
} else if currentSelection < scrollOffset {
187179
scrollOffset = currentSelection
188180
}
189181

190-
// Ensure scroll bounds
191182
if scrollOffset < 0 {
192183
scrollOffset = 0
193184
}
194185
if scrollOffset > len(options)-maxVisibleOptions {
195186
scrollOffset = max(0, len(options)-maxVisibleOptions)
196187
}
197188

198-
// Batch write visible options
199189
for i := scrollOffset; i < endIdx; i++ {
200190
if i == currentSelection {
201191
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)
208198
buf.WriteString(fmt.Sprintf("%s↓ more items below%s\n", colorGrey, colorReset))
209199
}
210200

211-
// Single write operation
212201
output.Write(buf.Bytes())
213202
output.Flush()
214203

215-
// Precise frame timing
216204
elapsed := time.Since(start)
217205
if elapsed < frameTime {
218206
time.Sleep(frameTime - elapsed)
219207
}
220208

221-
// Non-blocking keyboard input
222209
if _, key, err := keyboard.GetKey(); err == nil {
223210
switch key {
224211
case keyboard.KeyArrowUp:

0 commit comments

Comments
 (0)