Goland Stdin On WIndows Can't Debug - Forced To Use VSCode

Code Snippet:

package main

import (
	"fmt"
	"golang.org/x/term"
	"log"
	"os"
)

func main() {
	var err error

	stdin := os.Stdin

	// Segment 1
	stdin, err = os.OpenFile("CONIN$", os.O_RDWR, 0o644)
	if err != nil {
		log.Fatalln(err)
	}
	// End Segment 1

	// Segment 2
	state, err := term.MakeRaw(int(stdin.Fd()))
	if err != nil {
		log.Fatalln(err)
	}

	defer func() {
		err := term.Restore(int(stdin.Fd()), state)
		if err != nil {
			log.Println(err)
		}
	}()
	// End Segment 2

	bytes := make([]byte, 100)
	count, err := stdin.Read(bytes)
	if err != nil {
		log.Fatalln(err)
	}

	fmt.Print(string(bytes[:count]))
}

I started with both segment 1 & 2 commented out- since the console was not in raw mode, .Read() only returns when I input a linebreak.  So I uncommented segment 2 to use raw mode so that I receive every character immediately.  However, when debugging in Goland, this code fails with “invalid handle”.  That makes sense, since the debugger console stdin is likely redirected from somewhere and is not a console handle.  So, I uncommented segment 1 in order to get the console handle underlying the debugger. 

Unfortunately, this code doesn't work at all- none of my input is picked up by the program.  As far as I can tell, the stream of my typing in the debugger console is not the underlying console handle, so if I'm reading from the console handle, I am not reading my input in the debugging console.

This unfortunately means that I am not capable of debugging a TUI (or any character-mode terminal application) in jetbrains IDEs.  VSCode doesn't have this problem because it has the option of debugging in the IDE's integrated terminal.  I'm afraid that this means I will need to cancel my jetbrains subscription until I start to work on a project where it can actually debug my code.

 

0
1 comment

Hi Sdbaynham ! Could you please let me know if the problem you were facing still persists? I'd suggest trying to update to the latest stable version of the IDE first and then see if that makes any difference. Please let me know how it goes.

0

Please sign in to leave a comment.