import assert from "node:assert/strict";
import { describe, it } from "vitest";
import { syncHardwareCursorForIME } from "../hardware-cursor.js";

describe("syncHardwareCursorForIME", () => {
	it("hides_cursor_when_no_marker", () => {
		let hid = 0;
		const term = {
			hideCursor: () => {
				hid++;
			},
			showCursor: () => {},
			write: () => {},
		};
		const row = syncHardwareCursorForIME(term, {
			cursorPos: null,
			totalLines: 5,
			hardwareCursorRow: 0,
			showHardwareCursor: true,
		});
		assert.equal(hid, 1);
		assert.equal(row, 0);
	});

	it("writes_row_and_column_escapes", () => {
		const writes: string[] = [];
		const term = {
			hideCursor: () => {},
			showCursor: () => {},
			write: (s: string) => {
				writes.push(s);
			},
		};
		const next = syncHardwareCursorForIME(term, {
			cursorPos: { row: 2, col: 3 },
			totalLines: 10,
			hardwareCursorRow: 0,
			showHardwareCursor: false,
		});
		assert.equal(next, 2);
		const joined = writes.join("");
		assert.ok(joined.includes("\x1b[2B"));
		assert.ok(joined.includes("\x1b[4G"));
	});
});
