winterm/win_event_handler.go
func (h *windowsAnsiEventHandler) simulateLF(includeCR bool) (bool, error) {
	if h.wrapNext {
		if err := h.Flush(); err != nil {
			return false, err
		}
		h.clearWrap()
	}
	pos, info, err := h.getCurrentInfo()
	if err != nil {
		return false, err
	}
	sr := h.effectiveSr(info.Window)
	if pos.Y == sr.bottom {
		// Scrolling is necessary. Let Windows automatically scroll if the scrolling region
		// is the full window.
		if sr.top == info.Window.Top && sr.bottom == info.Window.Bottom {
			if includeCR {
				pos.X = 0
				h.updatePos(pos)
			}
			return false, nil
		}

		// A custom scroll region is active. Scroll the window manually to simulate
		// the LF.
		if err := h.Flush(); err != nil {
			return false, err
		}
		h.logf("Simulating LF inside scroll region")
		if err := h.scrollUp(1); err != nil {
			return false, err
		}
		if includeCR {
			pos.X = 0
			if err := SetConsoleCursorPosition(h.fd, pos); err != nil {
				return false, err
			}
		}
		return true, nil

	} else if pos.Y < info.Window.Bottom {
		// Let Windows handle the LF.
		pos.Y++
		if includeCR {
			pos.X = 0
		}
		h.updatePos(pos)
		return false, nil
	} else {
		// The cursor is at the bottom of the screen but outside the scroll
		// region. Skip the LF.
		h.logf("Simulating LF outside scroll region")
		if includeCR {
			if err := h.Flush(); err != nil {
				return false, err
			}
			pos.X = 0
			if err := SetConsoleCursorPosition(h.fd, pos); err != nil {
				return false, err
			}
		}
		return true, nil
	}
}
func (h *windowsAnsiEventHandler) simulateLF(includeCR bool) (bool, error) {
	if h.wrapNext {
		if err := h.Flush(); err != nil {
			return false, err
		}
		h.clearWrap()
	}
	pos, info, err := h.getCurrentInfo()
	if err != nil {
		return false, err
	}
	sr := h.effectiveSr(info.Window)
	if pos.Y == sr.bottom {
		// Scrolling is necessary. Let Windows automatically scroll if the scrolling region
		// is the full window.
		if sr.top == info.Window.Top && sr.bottom == info.Window.Bottom {
			if includeCR {
				pos.X = 0
				h.updatePos(pos)
			}
			return false, nil
		}

		// A custom scroll region is active. Scroll the window manually to simulate
		// the LF.
		if err := h.Flush(); err != nil {
			return false, err
		}
		h.logf("Simulating LF inside scroll region")
		if err := h.scrollUp(1); err != nil {
			return false, err
		}
		if includeCR {
			pos.X = 0
			if err := SetConsoleCursorPosition(h.fd, pos); err != nil {
				return false, err
			}
		}
		return true, nil

	} else if pos.Y < info.Window.Bottom {
		// Let Windows handle the LF.
		pos.Y++
		if includeCR {
			pos.X = 0
		}
		h.updatePos(pos)
		return false, nil
	} else {
		// The cursor is at the bottom of the screen but outside the scroll
		// region. Skip the LF.
		h.logf("Simulating LF outside scroll region")
		if includeCR {
			if err := h.Flush(); err != nil {
				return false, err
			}
			pos.X = 0
			if err := SetConsoleCursorPosition(h.fd, pos); err != nil {
				return false, err
			}
		}
		return true, nil
	}
}
func ( h * windowsAnsiEventHandler ) simulateLF ( includeCR bool ) ( bool , error ) { if h . wrapNext { if err := h . Flush ( ) ; err != nil { return false , err } h . clearWrap ( ) } pos , info , err := h . getCurrentInfo ( ) if err != nil { return false , err } sr := h . effectiveSr ( info . Window ) if pos . Y == sr . bottom { // Scrolling is necessary. Let Windows automatically scroll if the scrolling region // is the full window. if sr . top == info . Window . Top && sr . bottom == info . Window . Bottom { if includeCR { pos . X = 0 h . updatePos ( pos ) } return false , nil } // A custom scroll region is active. Scroll the window manually to simulate // the LF. if err := h . Flush ( ) ; err != nil { return false , err } h . logf ( " " ) if err := h . scrollUp ( 1 ) ; err != nil { return false , err } if includeCR { pos . X = 0 if err := SetConsoleCursorPosition ( h . fd , pos ) ; err != nil { return false , err } } return true , nil } else if pos . Y < info . Window . Bottom { // Let Windows handle the LF. pos . Y ++ if includeCR { pos . X = 0 } h . updatePos ( pos ) return false , nil } else { // The cursor is at the bottom of the screen but outside the scroll // region. Skip the LF. h . logf ( " " ) if includeCR { if err := h . Flush ( ) ; err != nil { return false , err } pos . X = 0 if err := SetConsoleCursorPosition ( h . fd , pos ) ; err != nil { return false , err } } return true , nil } }
// simulateLF simulates a LF or CR+LF by scrolling if necessary to handle the
// current cursor position and scroll region settings, in which case it returns
// true. If no special handling is necessary, then it does nothing and returns
// false.
//
// In the false case, the caller should ensure that a carriage return
// and line feed are inserted or that the text is otherwise wrapped.
simulateLF simulates a LF or CR + LF by scrolling if necessary to handle the current cursor position and scroll region settings in which case it returns true . If no special handling is necessary then it does nothing and returns false . In the false case the caller should ensure that a carriage return and line feed are inserted or that the text is otherwise wrapped .