Skip to content
Myr

Reorganize code to ensure deletion of temp files

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent c36ddce · Browse files · 1 file+28 added−25 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+28 added−25 removed

  • other:+28 added−25 removed

1 file+28 added−25 removed

modified:src/terminal.go+28 added-25 removed
393 unmodified lines
394 startChan chan fitpad395 killChan chan bool396 serverInputChan chan []*action397 callbackChan chan versionedCallback398 bgQueue map[action][]func()398 bgQueue map[action][]func(bool)399 bgSemaphore chan struct{}400 bgSemaphores map[action]chan struct{}401 keyChan chan tui.Event402 eventChan chan tui.Event
643 unmodified lines
1046 startChan: make(chan fitpad, 1),1047 killChan: make(chan bool),1048 serverInputChan: make(chan []*action, 100),1049 callbackChan: make(chan versionedCallback, maxBgProcesses),1050 bgQueue: make(map[action][]func()),1050 bgQueue: make(map[action][]func(bool)),1051 bgSemaphore: make(chan struct{}, maxBgProcesses),1052 bgSemaphores: make(map[action]chan struct{}),1053 keyChan: make(chan tui.Event),1054 eventChan: make(chan tui.Event, 6), // start | (load + result + zero|one) | (focus) | (resize)
3315 unmodified lines
4370 command, tempFiles := t.replacePlaceholder(a.a, false, string(t.input), list)4371 version := t.bgVersion4372 cmd := t.executor.ExecCommand(command, false)4373 cmd.Env = t.environ()4374 item := func(proceed bool) {4374 item := func() {4375 out, _ := cmd.StdoutPipe()4376 reader := bufio.NewReader(out)4377 var output string4378 if err := cmd.Start(); err == nil {4379 if firstLineOnly {4380 output, _ = reader.ReadString('\n')4381 output = strings.TrimRight(output, "\r\n")4382 } else {4383 bytes, _ := io.ReadAll(reader)4384 output = string(bytes)4375 if proceed {4376 out, _ := cmd.StdoutPipe()4377 reader := bufio.NewReader(out)4378 var output string4379 if err := cmd.Start(); err == nil {4380 if firstLineOnly {4381 output, _ = reader.ReadString('\n')4382 output = strings.TrimRight(output, "\r\n")4383 } else {4384 bytes, _ := io.ReadAll(reader)4385 output = string(bytes)4386 }4387 cmd.Wait()4388 }4386 cmd.Wait()4389 t.callbackChan <- versionedCallback{version, func() { callback(output) }}4390 }4391 removeFiles(tempFiles)43924390 t.callbackChan <- versionedCallback{version, func() { callback(output) }}4393 }4394 queue, prs := t.bgQueue[a]4395 if !prs {4394 queue = []func(){}4396 queue = []func(bool){}4397 }4398 queue = append(queue, item)4399 t.bgQueue[a] = queue4400}
16 unmodified lines
4417 // Acquire local semaphore4418 case semaphore <- struct{}{}:4419 default:4420 // Failed to acquire local semaphore, putting only the last one back to the queue4421 for _, item := range queue[:len(queue)-1] {4422 item(false)4423 }4424 t.bgQueue[a] = queue[len(queue)-1:]4425 continue Loop4426 }4427 todo := item4428 go func() {4429 // Acquire global semaphore4430 t.bgSemaphore <- struct{}{}44314427 todo()4432 todo(true)4433 // Release local semaphore4434 <-semaphore4435 // Release global semaphore4436 <-t.bgSemaphore
858 unmodified lines
5295 }52965297 var event tui.Event5298 actions := []*action{}5294 callbacks := []func(){}5299 callbacks := []versionedCallback{}5300 select {5301 case event = <-t.keyChan:5302 needBarrier = true5303 case event = <-t.eventChan:
26 unmodified lines
5330 }5331 case callback := <-t.callbackChan:5332 event = tui.Invalid.AsEvent()5333 actions = append(actions, &action{t: actAsync})5329 if callback.version == t.bgVersion {5330 callbacks = append(callbacks, callback.callback)5334 callbacks = append(callbacks, callback)5331 }5335 DrainCallback:5336 for {5337 select {5338 case callback = <-t.callbackChan:5336 if callback.version == t.bgVersion {5337 callbacks = append(callbacks, callback.callback)5339 callbacks = append(callbacks, callback)5338 }5340 continue DrainCallback5341 default:5342 break DrainCallback5343 }
106 unmodified lines
5450 switch a.t {5451 case actIgnore, actStart, actClick:5452 case actAsync:5453 for _, callback := range callbacks {5454 if t.bgVersion == callback.version {5453 callback()5455 callback.callback()5456 }5457 }5458 case actBecome:5459 valid, list := t.buildPlusList(a.a, false)5460 if valid {
1421 unmodified lines