diff --git a/event_handler.go b/event_handler.go index ee5b4bf..98087b3 100644 --- a/event_handler.go +++ b/event_handler.go @@ -43,6 +43,9 @@ type AnsiEventHandler interface { // Origin Mode DECOM(bool) error + // 132 Column Mode + DECCOLM(bool) error + // Erase in Display ED(int) error diff --git a/parser_action_helpers.go b/parser_action_helpers.go index ab5ef11..4388020 100644 --- a/parser_action_helpers.go +++ b/parser_action_helpers.go @@ -67,6 +67,8 @@ func getInts(params []string, minCount int, dflt int) []int { func (ap *AnsiParser) modeDispatch(param string, set bool) error { switch param { + case "?3": + return ap.eventHandler.DECCOLM(set) case "?6": return ap.eventHandler.DECOM(set) case "?25": diff --git a/test_event_handler.go b/test_event_handler.go index 8bda91b..60f9f30 100644 --- a/test_event_handler.go +++ b/test_event_handler.go @@ -92,6 +92,11 @@ func (h *TestAnsiEventHandler) DECOM(visible bool) error { return nil } +func (h *TestAnsiEventHandler) DECCOLM(use132 bool) error { + h.recordCall("DECOLM", []string{strconv.FormatBool(use132)}) + return nil +} + func (h *TestAnsiEventHandler) ED(param int) error { h.recordCall("ED", []string{strconv.Itoa(param)}) return nil diff --git a/winterm/win_event_handler.go b/winterm/win_event_handler.go index 21a3b99..2d492b3 100644 --- a/winterm/win_event_handler.go +++ b/winterm/win_event_handler.go @@ -387,6 +387,45 @@ func (h *WindowsAnsiEventHandler) DECOM(enable bool) error { return h.CUP(1, 1) } +func (h *WindowsAnsiEventHandler) DECCOLM(use132 bool) error { + if err := h.Flush(); err != nil { + return err + } + logger.Infof("DECCOLM: [%v]", []string{strconv.FormatBool(use132)}) + h.clearWrap() + if err := h.ED(2); err != nil { + return err + } + info, err := GetConsoleScreenBufferInfo(h.fd) + if err != nil { + return err + } + targetWidth := SHORT(80) + if use132 { + targetWidth = 132 + } + if info.Size.X < targetWidth { + if err := SetConsoleScreenBufferSize(h.fd, COORD{targetWidth, info.Size.Y}); err != nil { + logger.Info("set buffer failed:", err) + return err + } + } + window := info.Window + window.Left = 0 + window.Right = targetWidth - 1 + if err := SetConsoleWindowInfo(h.fd, true, window); err != nil { + logger.Info("set window failed:", err) + return err + } + if info.Size.X > targetWidth { + if err := SetConsoleScreenBufferSize(h.fd, COORD{targetWidth, info.Size.Y}); err != nil { + logger.Info("set buffer failed:", err) + return err + } + } + return SetConsoleCursorPosition(h.fd, COORD{0, 0}) +} + func (h *WindowsAnsiEventHandler) ED(param int) error { if err := h.Flush(); err != nil { return err