Skip to content

Commit

Permalink
Add DECCOLM support to toggle 80 and 132 columns
Browse files Browse the repository at this point in the history
Signed-off-by: John Starks <jostarks@microsoft.com>
  • Loading branch information
jstarks committed Aug 7, 2015
1 parent 330b4c5 commit 55ec40b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ type AnsiEventHandler interface {
// Origin Mode
DECOM(bool) error

// 132 Column Mode
DECCOLM(bool) error

// Erase in Display
ED(int) error

Expand Down
2 changes: 2 additions & 0 deletions parser_action_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
5 changes: 5 additions & 0 deletions test_event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions winterm/win_event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 55ec40b

Please sign in to comment.