gitlab.com/Raven-IO/raven-delve@v1.22.4/pkg/terminal/out_windows.go (about)

     1  package terminal
     2  
     3  import (
     4  	"syscall"
     5  	"unsafe"
     6  )
     7  
     8  var (
     9  	kernel32                       = syscall.NewLazyDLL("kernel32.dll")
    10  	procGetStdHandle               = kernel32.NewProc("GetStdHandle")
    11  	procGetConsoleScreenBufferInfo = kernel32.NewProc("GetConsoleScreenBufferInfo")
    12  )
    13  
    14  type coord struct {
    15  	x, y int16
    16  }
    17  
    18  type smallRect struct {
    19  	left, top, right, bottom int16
    20  }
    21  
    22  type consoleScreenBufferInfo struct {
    23  	dwSize              coord
    24  	dwCursorPosition    coord
    25  	wAttributes         int16
    26  	srWindow            smallRect
    27  	dwMaximumWindowSize coord
    28  }
    29  
    30  func (w *pagingWriter) getWindowSize() {
    31  	hout, _, err := procGetStdHandle.Call(uintptr(uint32(-12 & 0xFFFFFFFF))) // stdout handle
    32  	if err != syscall.Errno(0) {
    33  		w.mode = pagingWriterNormal
    34  		return
    35  	}
    36  	var sbi consoleScreenBufferInfo
    37  	_, _, err = procGetConsoleScreenBufferInfo.Call(uintptr(hout), uintptr(unsafe.Pointer(&sbi)))
    38  	if err != syscall.Errno(0) {
    39  		w.mode = pagingWriterNormal
    40  		return
    41  	}
    42  	w.columns = int(sbi.srWindow.right - sbi.srWindow.left + 1)
    43  	w.lines = int(sbi.srWindow.bottom - sbi.srWindow.top + 1)
    44  }