# Insert and Delete Column (DECIC, DECDC)

> Insert or delete whole columns at the cursor, shifting the rest of the scrolling region sideways.

- **Sequence:** `CSI Pn ' }`
- **Defaults:** Pn = 1
- **DEC STD 070:** [§5.11 Insert Column, p. 5-150](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n404/mode/1up)
- **VT510:** [DECIC—Insert Column](https://vt100.net/docs/vt510-rm/DECIC.html)

`CSI Pn ' }` (DECIC) inserts `Pn` blank columns at the cursor's column, and
`CSI Pn ' ~` (DECDC) deletes `Pn` columns there. They are
[ICH](https://control-codes.page/csi/ich/index.html.md) and [DCH](https://control-codes.page/csi/dch/index.html.md) for every line of the scrolling region
at once: only the part of the screen between the top, bottom, left and right
margins moves. Inserted columns push the rest of the region right, and what
passes the right margin is lost; deleting pulls it left, and blank columns
come in at the right margin. A `0` is taken as `1`, and the cursor does not
move.

Both do nothing if the cursor is outside the margins. DEC STD 070 defines
DECDC at
[§5.11, p. 5-151](https://archive.org/details/bitsavers_decstandar0VideoSystemsReferenceManualDec91_74264381/page/n405/mode/1up),
and the VT510 manual has [DECDC—Delete Column](https://vt100.net/docs/vt510-rm/DECDC.html).

These are VT420 functions: DEC STD 070 makes them part of level 4's
horizontal scrolling extension. xterm is a VT420 unless told otherwise
([`DFT_DECID`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/ptyx.h#L398-L400)), and it implements both
([`CASE_DECDC`, `CASE_DECIC`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/charproc.c#L5398-L5412),
which shift each line of the region with
[`xtermColScroll`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/util.c#L1176-L1245)).
The cases follow xterm, and esctest2's `decic.py` and `decdc.py` test
the same things.

libghostty-vt identifies itself as a VT220 (see [DA](https://control-codes.page/csi/da/index.html.md)) and does
not implement either. Its CSI dispatch in `stream.zig` handles a final `}`
only with the intermediate `$`, for DECSASD, and has no case for `~`, so
both are ignored, and the cases below that change the screen are marked as
known differences.

## Validation

### DECIC-1: Insert one column

*A known difference: libghostty-vt does not pass this case.*

Input, one step per line:

```text
ABCDE\r\n
FGHIJ
\e[1;2H
\e['}
```

Expected screen:

```text
|A_BCDE|
|F_GHIJ|
cursor 1,2
```

### DECIC-2: Columns pushed past the edge are lost

*A known difference: libghostty-vt does not pass this case.*

Input, one step per line:

```text
ABCDE
\e[1;2H
\e[2'}
```

Expected screen:

```text
|A__BCD|
```

### DECIC-3: Only within the top and bottom margins

*A known difference: libghostty-vt does not pass this case.*

Input, one step per line:

```text
ABC\r\n
DEF\r\n
GHI
\e[2;3r   # region is lines 2 and 3
\e[2;2H
\e['}
```

Expected screen:

```text
|ABC_|
|D_EF|
|G_HI|
```

### DECIC-4: Only within the left and right margins

*A known difference: libghostty-vt does not pass this case.*

Input, one step per line:

```text
ABCDEFG
\e[?69h   # allow left and right margins
\e[2;5s   # margins at columns 2 and 5
\e[1;3H
\e['}
```

Expected screen:

```text
|AB_CDFG|
```

### DECIC-5: Nothing outside the margins

Input, one step per line:

```text
ABCDEFG
\e[?69h   # allow left and right margins
\e[2;5s   # margins at columns 2 and 5
\e[1;1H   # outside them
\e[3'}
```

Expected screen:

```text
|ABCDEFG|
```

This one passes in libghostty-vt only because it ignores DECIC altogether.

### DECIC-6: DECDC deletes one column

*A known difference: libghostty-vt does not pass this case.*

Input, one step per line:

```text
ABCDE\r\n
FGHIJ
\e[1;2H
\e['~
```

Expected screen:

```text
|ACDE__|
|FHIJ__|
cursor 1,2
```

### DECIC-7: DECDC within a right margin

*A known difference: libghostty-vt does not pass this case.*

Input, one step per line:

```text
ABCDEF
\e[?69h   # allow left and right margins
\e[1;4s   # margins at columns 1 and 4
\e[1;2H
\e[2'~
```

Expected screen:

```text
|AD__EF|
```

---

This is the Markdown version of <https://control-codes.page/csi/decic/>. On that page every validation case runs live in libghostty-vt, the terminal emulation core of Ghostty, compiled to WebAssembly.

The validation cases are written in the notation described in <https://control-codes.page/notation/index.html.md>.
