...

Source file src/github.com/Azure/go-ansiterm/winterm/erase_helpers.go

Documentation: github.com/Azure/go-ansiterm/winterm

     1  // +build windows
     2  
     3  package winterm
     4  
     5  import "github.com/Azure/go-ansiterm"
     6  
     7  func (h *windowsAnsiEventHandler) clearRange(attributes uint16, fromCoord COORD, toCoord COORD) error {
     8  	// Ignore an invalid (negative area) request
     9  	if toCoord.Y < fromCoord.Y {
    10  		return nil
    11  	}
    12  
    13  	var err error
    14  
    15  	var coordStart = COORD{}
    16  	var coordEnd = COORD{}
    17  
    18  	xCurrent, yCurrent := fromCoord.X, fromCoord.Y
    19  	xEnd, yEnd := toCoord.X, toCoord.Y
    20  
    21  	// Clear any partial initial line
    22  	if xCurrent > 0 {
    23  		coordStart.X, coordStart.Y = xCurrent, yCurrent
    24  		coordEnd.X, coordEnd.Y = xEnd, yCurrent
    25  
    26  		err = h.clearRect(attributes, coordStart, coordEnd)
    27  		if err != nil {
    28  			return err
    29  		}
    30  
    31  		xCurrent = 0
    32  		yCurrent += 1
    33  	}
    34  
    35  	// Clear intervening rectangular section
    36  	if yCurrent < yEnd {
    37  		coordStart.X, coordStart.Y = xCurrent, yCurrent
    38  		coordEnd.X, coordEnd.Y = xEnd, yEnd-1
    39  
    40  		err = h.clearRect(attributes, coordStart, coordEnd)
    41  		if err != nil {
    42  			return err
    43  		}
    44  
    45  		xCurrent = 0
    46  		yCurrent = yEnd
    47  	}
    48  
    49  	// Clear remaining partial ending line
    50  	coordStart.X, coordStart.Y = xCurrent, yCurrent
    51  	coordEnd.X, coordEnd.Y = xEnd, yEnd
    52  
    53  	err = h.clearRect(attributes, coordStart, coordEnd)
    54  	if err != nil {
    55  		return err
    56  	}
    57  
    58  	return nil
    59  }
    60  
    61  func (h *windowsAnsiEventHandler) clearRect(attributes uint16, fromCoord COORD, toCoord COORD) error {
    62  	region := SMALL_RECT{Top: fromCoord.Y, Left: fromCoord.X, Bottom: toCoord.Y, Right: toCoord.X}
    63  	width := toCoord.X - fromCoord.X + 1
    64  	height := toCoord.Y - fromCoord.Y + 1
    65  	size := uint32(width) * uint32(height)
    66  
    67  	if size <= 0 {
    68  		return nil
    69  	}
    70  
    71  	buffer := make([]CHAR_INFO, size)
    72  
    73  	char := CHAR_INFO{ansiterm.FILL_CHARACTER, attributes}
    74  	for i := 0; i < int(size); i++ {
    75  		buffer[i] = char
    76  	}
    77  
    78  	err := WriteConsoleOutput(h.fd, buffer, COORD{X: width, Y: height}, COORD{X: 0, Y: 0}, &region)
    79  	if err != nil {
    80  		return err
    81  	}
    82  
    83  	return nil
    84  }
    85  

View as plain text