display_windows.go 617 B

12345678910111213141516171819202122232425262728
  1. package terminal
  2. import (
  3. "os"
  4. "syscall"
  5. "unsafe"
  6. )
  7. func EraseLine(mode EraseLineMode) {
  8. handle := syscall.Handle(os.Stdout.Fd())
  9. var csbi consoleScreenBufferInfo
  10. procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi)))
  11. var w uint32
  12. var x Short
  13. cursor := csbi.cursorPosition
  14. switch mode {
  15. case ERASE_LINE_END:
  16. x = csbi.size.X
  17. case ERASE_LINE_START:
  18. x = 0
  19. case ERASE_LINE_ALL:
  20. cursor.X = 0
  21. x = csbi.size.X
  22. }
  23. procFillConsoleOutputCharacter.Call(uintptr(handle), uintptr(' '), uintptr(x), uintptr(*(*int32)(unsafe.Pointer(&cursor))), uintptr(unsafe.Pointer(&w)))
  24. }