MCPcopy Create free account
hub / github.com/codechenx/FastTableViewer / main

Function main

ftv.go:157–249  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

155}
156
157func main() {
158 initView()
159 args.setDefault()
160 RootCmd := &cobra.Command{
161 Use: "ftv {File_Name}",
162 Version: "0.8.1",
163 Short: "Fast table viewer for delimited file in terminal",
164 Run: func(cmd *cobra.Command, cmdargs []string) {
165 if args.Sep == "\\t" {
166 args.Sep = " "
167 }
168 if len([]rune(args.Sep)) > 0 {
169 b.sep = []rune(args.Sep)[0]
170 }
171
172 // Configure memory limit
173 if args.MemoryMB > 0 {
174 b.setMemoryLimit(int64(args.MemoryMB) * 1024 * 1024) // Convert MB to bytes
175 }
176 // else use default (unlimited - 0)
177
178 info, err := os.Stdin.Stat()
179 fatalError(err)
180
181 // Determine if we should use async loading
182 useAsync := args.AsyncLoad
183
184 //check whether from a console pipe
185 if info.Mode()&os.ModeCharDevice != 0 {
186 // FILE MODE
187 if len(cmdargs) < 1 {
188 stopView()
189 _ = cmd.Help()
190 return
191 }
192 //get file name form console
193 args.FileName = cmdargs[0]
194
195 // Check if file exists before attempting to load
196 if _, err := os.Stat(args.FileName); os.IsNotExist(err) {
197 stopView()
198 fmt.Printf("⚠️ File not found: %s\n", args.FileName)
199 os.Exit(1)
200 } else if err != nil {
201 stopView()
202 fmt.Printf("⚠️ Cannot access file: %s\n", err)
203 os.Exit(1)
204 }
205
206 if useAsync {
207 err = loadAndDisplayAsync(func(b *Buffer, updateChan chan<- bool, doneChan chan<- error) {
208 go loadFileToBufferAsync(args.FileName, b, updateChan, doneChan)
209 }, "File")
210 fatalError(err)
211 } else {
212 err = loadAndDisplaySync(func(b *Buffer) error {
213 return loadFileToBuffer(args.FileName, b)
214 }, "File")

Callers 1

Test_mainFunction · 0.85

Calls 11

initViewFunction · 0.85
fatalErrorFunction · 0.85
stopViewFunction · 0.85
loadAndDisplayAsyncFunction · 0.85
loadFileToBufferAsyncFunction · 0.85
loadAndDisplaySyncFunction · 0.85
loadFileToBufferFunction · 0.85
loadPipeToBufferAsyncFunction · 0.85
loadPipeToBufferFunction · 0.85
setDefaultMethod · 0.80
setMemoryLimitMethod · 0.80

Tested by 1

Test_mainFunction · 0.68