TTerminalWindow sixel support wip
[nikiroo-utils.git] / src / jexer / TTerminalWindow.java
index b36e86b62dfca47b0d6f95864f19c3b6b1d1cf15..818a52f6eb6bbccc20dfc45042cad9653ba1b7be 100644 (file)
  */
 package jexer;
 
-import java.awt.image.BufferedImage;
 import java.awt.Font;
 import java.awt.FontMetrics;
 import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
 
 import java.io.InputStream;
 import java.io.IOException;
@@ -761,6 +761,22 @@ public class TTerminalWindow extends TScrollableWindow
 
         // Add shortcut text
         newStatusBar(i18n.getString("statusBarRunning"));
+
+        // Pass the correct text cell width/height to the emulator
+        int textWidth = 16;
+        int textHeight = 20;
+        if (getScreen() instanceof SwingTerminal) {
+            SwingTerminal terminal = (SwingTerminal) getScreen();
+
+            textWidth = terminal.getTextWidth();
+            textHeight = terminal.getTextHeight();
+        } else if (getScreen() instanceof ECMA48Terminal) {
+            ECMA48Terminal terminal = (ECMA48Terminal) getScreen();
+            textWidth = terminal.getTextWidth();
+            textHeight = terminal.getTextHeight();
+        }
+        emulator.setTextWidth(textWidth);
+        emulator.setTextHeight(textHeight);
     }
 
     /**
@@ -954,6 +970,14 @@ public class TTerminalWindow extends TScrollableWindow
         } else if (getScreen() instanceof ECMA48Terminal) {
             ECMA48Terminal terminal = (ECMA48Terminal) getScreen();
 
+            if (!terminal.hasSixel()) {
+                // The backend does not have sixel support, draw this as text
+                // and bail out.
+                putCharXY(x, y, cell);
+                putCharXY(x + 1, y, ' ', cell);
+                return;
+            }
+
             textWidth = terminal.getTextWidth();
             textHeight = terminal.getTextHeight();
             cursorBlinkVisible = blinkState;