diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 627c54ec0..fb78ea59e 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -2170,6 +2170,20 @@ test "Terminal: fullReset with a non-empty pen" { try testing.expect(cell.fg.eql(.{})); } +test "Terminal: fullReset origin mode" { + var t = try init(testing.allocator, 10, 10); + defer t.deinit(testing.allocator); + + t.setCursorPos(3, 5); + t.modes.set(.origin, true); + t.fullReset(testing.allocator); + + // Origin mode should be reset and the cursor should be moved + try testing.expectEqual(@as(usize, 0), t.screen.cursor.y); + try testing.expectEqual(@as(usize, 0), t.screen.cursor.x); + try testing.expect(!t.modes.get(.origin)); +} + test "Terminal: input with no control characters" { var t = try init(testing.allocator, 80, 80); defer t.deinit(testing.allocator); diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index c800c6589..ce8ffec88 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -1749,7 +1749,9 @@ const StreamHandler = struct { // Schedule a render since we changed colors .reverse_colors => try self.queueRender(), - // Origin resets cursor pos + // Origin resets cursor pos. This is called whether or not + // we're enabling or disabling origin mode and whether or + // not the value changed. .origin => self.terminal.setCursorPos(1, 1), .enable_left_and_right_margin => if (!enabled) { diff --git a/website/app/vt/modes/decom/page.mdx b/website/app/vt/modes/decom/page.mdx new file mode 100644 index 000000000..b633a7fc0 --- /dev/null +++ b/website/app/vt/modes/decom/page.mdx @@ -0,0 +1,64 @@ +import VTMode from "@/components/VTMode"; + +# Origin (DECOM) + + + +Changes the origin of grid coordinates to be relative to the current scroll +region. + +When set or unset, this invokes [Cursor Position (CUP)](/vt/cup) with row 1 and +column 1. If origin mode is set, this will position the cursor to the +top-left location of the current scroll region. If origin mode is not set, +this will position the cursor to the top-left location of the screen. The +cursor position will be set even if the origin mode is _unchanged_. + +The following commands are affected by origin mode. Please see their +respective documentation for details on how origin mode impacts their +behavior. + +- [Carriage Return (CR)](/vt/cr) +- [Cursor Position Set (CUP)](/vt/cup) +- [Cursor Position Report (CPR)](/vt/cpr) +- [Save Cursor (DECSC)](/vt/decsc) +- [Restore Cursor (DECRC)](/vt/decrc) +- [Horizontal Position Absolute (HPA)](/vt/hpa) +- [Vertical Position Absolute (VPA)](/vt/vpa) +- [Horizontal Position Relative (HPR)](/vt/hpr) +- [Vertical Position Relative (VPR)](/vt/vpr) +- [Cursor Backward Tabulation (CBT)](/vt/cbt) +- [Screen Alignment Test (DECALN)](/vt/decaln) +- [Full Reset (RIS)](/vt/ris) +- [Soft Reset (DECSTR)](/vt/decstr) + +## Validation + +### DECOM V-1: Unset No Margins + +```bash +printf "\033[H" +printf "\033[2J" +printf "ABC\n" +printf "\033[?6l" +printf "X" +``` + +``` +|XBC_____| +|________| +``` + +### DECOM V-1: Set No Margins + +```bash +printf "\033[H" +printf "\033[2J" +printf "ABC\n" +printf "\033[?6h" +printf "X" +``` + +``` +|XBC_____| +|________| +```