Skip to content

Commit 7fea4cd

Browse files
committed
[#704] Enforce Windows console flags setting before each key press capture
1 parent dc05b7d commit 7fea4cd

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/cli/terminal_ui.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ func (term *TerminalUI) runTCR(r role.Role) error {
253253
}
254254

255255
func (term *TerminalUI) runMenuLoop(m *menu) {
256+
if term.params.Mode.IsInteractive() {
257+
_ = SetRaw()
258+
defer Restore()
259+
}
256260
for {
257261
input := term.readKeyboardInput()
258262
matched, quit := m.matchAndRun(input)
@@ -267,6 +271,9 @@ func (term *TerminalUI) runMenuLoop(m *menu) {
267271
}
268272

269273
func (term *TerminalUI) readKeyboardInput() byte {
274+
// setupTerminal() is called every time to enforce expected behaviour
275+
// in some terminal implementations such as JetBrains' embedded terminal
276+
setupTerminal()
270277
keyboardInput := make([]byte, 1)
271278
_, err := os.Stdin.Read(keyboardInput)
272279
if err != nil {
@@ -357,6 +364,7 @@ func (term *TerminalUI) Confirm(message string, defaultAnswer bool) bool {
357364

358365
keyboardInput := make([]byte, 1)
359366
for {
367+
setupTerminal()
360368
_, _ = os.Stdin.Read(keyboardInput)
361369
switch keyboardInput[0] {
362370
case 'y', 'Y':
@@ -378,11 +386,6 @@ func yesOrNoAdvice(defaultAnswer bool) string {
378386

379387
// Start runs the terminal session
380388
func (term *TerminalUI) Start() {
381-
if term.params.Mode.IsInteractive() {
382-
_ = SetRaw()
383-
defer Restore()
384-
}
385-
386389
switch term.params.Mode {
387390
case runmode.Solo{}:
388391
// When running TCR in solo mode, there's no selection menu:

0 commit comments

Comments
 (0)