                  (set-bg 3)
                  (move-cursor 1 1))]
       (let [{lines :lines {x :x y :y} :cursor} (feed-csi vt "J")]
-        (is (= lines [[[0x41 {}] [0x42 {}] [0x43 {}] [0x44 {}]]
-                      [[0x45 {}] [0x20 {:bg 3}] [0x20 {:bg 3}] [0x20 {:bg 3}]]
-                      [[0x20 {:bg 3}] [0x20 {:bg 3}] [0x20 {:bg 3}] [0x20 {:bg 3}]]]))
+        (is (= (compact-lines lines) [[["ABCD" {}]]
+                                      [["E" {}] ["   " {:bg 3}]]
+                                      [["    " {:bg 3}]]]))
         (is (= x 1))
         (is (= y 1)))
       (let [{lines :lines {x :x y :y} :cursor} (feed-csi vt "1J")]
-        (is (= lines [[[0x20 {:bg 3}] [0x20 {:bg 3}] [0x20 {:bg 3}] [0x20 {:bg 3}]]
-                      [[0x20 {:bg 3}] [0x20 {:bg 3}] [0x47 {}] [0x48 {}]]
-                      [[0x49 {}] [0x4a {}] [0x20 {}] [0x20 {}]]]))
+        (is (= (compact-lines lines) [[["    " {:bg 3}]]
+                                      [["  " {:bg 3}] ["GH" {}]]
+                                      [["IJ  " {}]]]))
         (is (= x 1))
         (is (= y 1)))
       (let [{lines :lines {x :x y :y} :cursor} (feed-csi vt "2J")]
-        (is (= lines [[[0x20 {:bg 3}] [0x20 {:bg 3}] [0x20 {:bg 3}] [0x20 {:bg 3}]]
-                      [[0x20 {:bg 3}] [0x20 {:bg 3}] [0x20 {:bg 3}] [0x20 {:bg 3}]]
-                      [[0x20 {:bg 3}] [0x20 {:bg 3}] [0x20 {:bg 3}] [0x20 {:bg 3}]]]))
+        (is (= (compact-lines lines) [[["    " {:bg 3}]]
+                                      [["    " {:bg 3}]]
+                                      [["    " {:bg 3}]]]))
         (is (= x 1))
         (is (= y 1)))))
 

               (set-fg 1))]

    (testing "printing within single line"
      (let [{:keys [lines cursor]} (feed-str vt "ABC")]
        (is (= lines [[[0x41 {:fg 1}] [0x42 {:fg 1}] [0x43 {:fg 1}] [0x20 {}]]
                      [[0x20 {}] [0x20 {}] [0x20 {}] [0x20 {}]]
                      [[0x20 {}] [0x20 {}] [0x20 {}] [0x20 {}]]]))
        (is (= cursor {:x 3 :y 0 :visible true}))))

    (testing "printing non-ASCII characters"
      (let [{:keys [lines cursor]} (feed-str vt "ABCżÓłĆ")]
        (is (= lines [[[0x41 {:fg 1}] [0x42 {:fg 1}] [0x43 {:fg 1}] [0x017c {:fg 1}]]
                      [[0xd3 {:fg 1}] [0x0142 {:fg 1}] [0x0106 {:fg 1}] [0x20 {}]]
                      [[0x20 {}] [0x20 {}] [0x20 {}] [0x20 {}]]]))
        (is (= cursor {:x 3 :y 1 :visible true}))))

    (testing "printing ASCII art using special drawing character set"
      (let [{:keys [lines cursor]} (-> vt
                                       (feed-esc "(0") ; use drawing character set
                                       (feed-str "abcd{|}~")
                                       (feed-esc "(B") ; back to ASCII
                                       (feed-str "abc"))]
        (is (= (compact-lines lines) [[["▒␉␌␍" {:fg 1}]]
                                      [["π≠£⋅" {:fg 1}]]
                                      [["abc" {:fg 1}] [" " {}]]]))))

    (testing "printing in insert mode"
      (let [vt (-> vt

              {:keys [lines] {:keys [x y]} :cursor} vt]
          (is (= x 2))
          (is (= y 1))
          (is (= (compact-lines lines) [[["ABC " {}]]
                                        [["DE  " {}]]
                                        [["    " {}]]]))))))

  (testing "CSI ?h (DECSM)" ; set multiple modes
    (let [vt (-> (make-vt 80 24)
