Skip to content

Commit

Permalink
Merge pull request #17 from jstarks/ichdch
Browse files Browse the repository at this point in the history
Add support for ICH and DCH
  • Loading branch information
jstarks committed Aug 7, 2015
2 parents 42a7d91 + 4e767af commit 5d67ac6
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
6 changes: 6 additions & 0 deletions event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ type AnsiEventHandler interface {
// Delete Line
DL(int) error

// Insert Character
ICH(int) error

// Delete Character
DCH(int) error

// Set Graphics Rendition
SGR([]int) error

Expand Down
4 changes: 4 additions & 0 deletions parser_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func (ap *AnsiParser) csiDispatch() error {
logger.Infof("csiDispatch: %v(%v)", cmd, params)

switch cmd {
case "@":
return ap.eventHandler.ICH(getInt(params, 1))
case "A":
return ap.eventHandler.CUU(getInt(params, 1))
case "B":
Expand Down Expand Up @@ -67,6 +69,8 @@ func (ap *AnsiParser) csiDispatch() error {
return ap.eventHandler.IL(getInt(params, 1))
case "M":
return ap.eventHandler.DL(getInt(params, 1))
case "P":
return ap.eventHandler.DCH(getInt(params, 1))
case "S":
return ap.eventHandler.SU(getInt(params, 1))
case "T":
Expand Down
10 changes: 10 additions & 0 deletions test_event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ func (h *TestAnsiEventHandler) DL(param int) error {
return nil
}

func (h *TestAnsiEventHandler) ICH(param int) error {
h.recordCall("ICH", []string{strconv.Itoa(param)})
return nil
}

func (h *TestAnsiEventHandler) DCH(param int) error {
h.recordCall("DCH", []string{strconv.Itoa(param)})
return nil
}

func (h *TestAnsiEventHandler) SGR(params []int) error {
strings := []string{}
for _, v := range params {
Expand Down
39 changes: 39 additions & 0 deletions winterm/scroll_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,42 @@ func (h *WindowsAnsiEventHandler) scroll(param int, sr scrollRegion, info *CONSO
}
return nil
}

func (h *WindowsAnsiEventHandler) deleteCharacters(param int) error {
info, err := GetConsoleScreenBufferInfo(h.fd)
if err != nil {
return err
}
return h.scrollLine(param, info.CursorPosition, info)
}

func (h *WindowsAnsiEventHandler) insertCharacters(param int) error {
return h.deleteCharacters(-param)
}

// scrollLine scrolls a line horizontally starting at the provided position by a number of columns.
func (h *WindowsAnsiEventHandler) scrollLine(columns int, position COORD, info *CONSOLE_SCREEN_BUFFER_INFO) error {
// Copy from and clip to the scroll region (full buffer width)
scrollRect := SMALL_RECT{
Top: position.Y,
Bottom: position.Y,
Left: position.X,
Right: info.Size.X - 1,
}

// Origin to which area should be copied
destOrigin := COORD{
X: position.X - SHORT(columns),
Y: position.Y,
}

char := CHAR_INFO{
UnicodeChar: ' ',
Attributes: h.attributes,
}

if err := ScrollConsoleScreenBuffer(h.fd, scrollRect, scrollRect, destOrigin, char); err != nil {
return err
}
return nil
}
18 changes: 18 additions & 0 deletions winterm/win_event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,24 @@ func (h *WindowsAnsiEventHandler) DL(param int) error {
return h.deleteLines(param)
}

func (h *WindowsAnsiEventHandler) ICH(param int) error {
if err := h.Flush(); err != nil {
return err
}
logger.Infof("ICH: [%v]", strconv.Itoa(param))
h.clearWrap()
return h.insertCharacters(param)
}

func (h *WindowsAnsiEventHandler) DCH(param int) error {
if err := h.Flush(); err != nil {
return err
}
logger.Infof("DCH: [%v]", strconv.Itoa(param))
h.clearWrap()
return h.deleteCharacters(param)
}

func (h *WindowsAnsiEventHandler) SGR(params []int) error {
if err := h.Flush(); err != nil {
return err
Expand Down

0 comments on commit 5d67ac6

Please sign in to comment.