@@ -29,28 +29,28 @@ type KongContextBinder func(ctx context.Context, kctx *kong.Context) context.Con
29
29
type exitPanic struct {}
30
30
31
31
type interactiveConsole struct {
32
- projectConfig projectconfig.Config
33
- l * readline.Instance
34
- binder KongContextBinder
35
- k * kong.Kong
36
- closeWait sync.WaitGroup
37
- closed bool
32
+ projectConfig projectconfig.Config
33
+ l * readline.Instance
34
+ binder KongContextBinder
35
+ k * kong.Kong
36
+ closeWait sync.WaitGroup
37
+ closed bool
38
+ currentLineCallback func (string )
38
39
}
39
40
40
41
func newInteractiveConsole (k * kong.Kong , binder KongContextBinder , projectConfig projectconfig.Config , eventSource * schemaeventsource.EventSource ) (* interactiveConsole , error ) {
42
+ it := & interactiveConsole {k : k , binder : binder , projectConfig : projectConfig }
41
43
l , err := readline .NewEx (& readline.Config {
42
44
Prompt : interactivePrompt ,
43
45
InterruptPrompt : "^C" ,
44
46
AutoComplete : & FTLCompletion {app : k , view : eventSource .ViewOnly ()},
45
- Listener : & ExitListener {cancel : func () {
46
- _ = syscall .Kill (- syscall .Getpid (), syscall .SIGINT ) //nolint:forcetypeassert,errcheck // best effort
47
- }},
47
+ Listener : it ,
48
48
})
49
+ it .l = l
49
50
if err != nil {
50
51
return nil , fmt .Errorf ("init readline: %w" , err )
51
52
}
52
53
53
- it := & interactiveConsole {k : k , binder : binder , l : l , projectConfig : projectConfig }
54
54
it .closeWait .Add (1 )
55
55
return it , nil
56
56
}
@@ -98,7 +98,6 @@ func (r *interactiveConsole) run(ctx context.Context) error {
98
98
if tsm , ok = sm .(* terminalStatusManager ); ok {
99
99
tsm .statusLock .Lock ()
100
100
tsm .clearStatusMessages ()
101
- tsm .console = true
102
101
tsm .consoleRefresh = r .l .Refresh
103
102
tsm .recalculateLines ()
104
103
tsm .statusLock .Unlock ()
@@ -117,6 +116,7 @@ func (r *interactiveConsole) run(ctx context.Context) error {
117
116
}
118
117
119
118
for {
119
+ l .Operation .String ()
120
120
line , err := l .Readline ()
121
121
if errors .Is (err , readline .ErrInterrupt ) {
122
122
@@ -193,15 +193,12 @@ func (r *interactiveConsole) run(ctx context.Context) error {
193
193
return nil
194
194
}
195
195
196
- var _ readline.Listener = & ExitListener {}
197
-
198
- type ExitListener struct {
199
- cancel func ()
200
- }
201
-
202
- func (e ExitListener ) OnChange (line []rune , pos int , key rune ) (newLine []rune , newPos int , ok bool ) {
196
+ func (e * interactiveConsole ) OnChange (line []rune , pos int , key rune ) (newLine []rune , newPos int , ok bool ) {
203
197
if key == readline .CharInterrupt {
204
- e .cancel ()
198
+ _ = syscall .Kill (- syscall .Getpid (), syscall .SIGINT ) //nolint:forcetypeassert,errcheck // best effort
199
+ }
200
+ if e .currentLineCallback != nil {
201
+ e .currentLineCallback (string (line ))
205
202
}
206
203
return line , pos , true
207
204
}
0 commit comments