diff --git a/terminal/cursor.go b/terminal/cursor.go index 75117e08..396527d4 100644 --- a/terminal/cursor.go +++ b/terminal/cursor.go @@ -14,6 +14,8 @@ import ( var COORDINATE_SYSTEM_BEGIN Short = 1 +var CURSOR_STAGNATES_ON_LAST_CHAR = false + var dsrPattern = regexp.MustCompile(`\x1b\[(\d+);(\d+)R$`) type Cursor struct { diff --git a/terminal/cursor_windows.go b/terminal/cursor_windows.go index 5ade0d70..49f8310e 100644 --- a/terminal/cursor_windows.go +++ b/terminal/cursor_windows.go @@ -3,12 +3,24 @@ package terminal import ( "bytes" "fmt" + log "github.com/Iilun/survey/v2/internal" + "os" "syscall" "unsafe" ) var COORDINATE_SYSTEM_BEGIN Short = 0 +var CURSOR_STAGNATES_ON_LAST_CHAR = false + +func init() { + if windowsTerminalSession := os.Getenv("WT_SESSION"); windowsTerminalSession != "" { + CURSOR_STAGNATES_ON_LAST_CHAR = true + } + CURSOR_STAGNATES_ON_LAST_CHAR = true + log.Printf("Cursor stagnates %t", CURSOR_STAGNATES_ON_LAST_CHAR) +} + // shared variable to save the cursor location from CursorSave() var cursorLoc Coord diff --git a/terminal/runereader.go b/terminal/runereader.go index a12231c9..cdc6285a 100644 --- a/terminal/runereader.go +++ b/terminal/runereader.go @@ -62,14 +62,17 @@ func (rr *RuneReader) ReadLineWithDefault(mask rune, d []rune, onRunes ...OnRune // we set the current location of the cursor once cursorCurrent, _ := cursor.Location(rr.Buffer()) // CHANGE THIS - wroteOnLine := true + wroteOnLine := COORDINATE_SYSTEM_BEGIN == 0 increment := func() { - if !cursorIsInLastPosition && cursorCurrent.CursorIsAtLineEnd(terminalSize) { + if CURSOR_STAGNATES_ON_LAST_CHAR && !cursorIsInLastPosition && cursorCurrent.CursorIsAtLineEnd(terminalSize) { cursorIsInLastPosition = true } else if cursorCurrent.CursorIsAtLineEnd(terminalSize) { - cursorCurrent.X = 1 + cursorCurrent.X = COORDINATE_SYSTEM_BEGIN + if CURSOR_STAGNATES_ON_LAST_CHAR { + cursorCurrent.X++ + } cursorCurrent.Y++ - wroteOnLine = true + wroteOnLine = COORDINATE_SYSTEM_BEGIN == 0 cursorIsInLastPosition = false } else { cursorCurrent.X++