2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2019 Kevin Lamonte
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
32 import java
.awt
.FontMetrics
;
33 import java
.awt
.Graphics2D
;
34 import java
.awt
.image
.BufferedImage
;
36 import java
.io
.InputStream
;
37 import java
.io
.IOException
;
38 import java
.lang
.reflect
.Field
;
39 import java
.text
.MessageFormat
;
40 import java
.util
.ArrayList
;
41 import java
.util
.HashMap
;
42 import java
.util
.List
;
44 import java
.util
.ResourceBundle
;
46 import jexer
.backend
.ECMA48Terminal
;
47 import jexer
.backend
.GlyphMaker
;
48 import jexer
.backend
.MultiScreen
;
49 import jexer
.backend
.SwingTerminal
;
50 import jexer
.bits
.Cell
;
51 import jexer
.bits
.CellAttributes
;
52 import jexer
.event
.TKeypressEvent
;
53 import jexer
.event
.TMenuEvent
;
54 import jexer
.event
.TMouseEvent
;
55 import jexer
.event
.TResizeEvent
;
56 import jexer
.menu
.TMenu
;
57 import jexer
.tterminal
.DisplayLine
;
58 import jexer
.tterminal
.DisplayListener
;
59 import jexer
.tterminal
.ECMA48
;
60 import static jexer
.TKeypress
.*;
63 * TTerminalWindow exposes a ECMA-48 / ANSI X3.64 style terminal in a widget.
65 public class TTerminalWidget
extends TScrollableWidget
66 implements DisplayListener
{
71 private static final ResourceBundle i18n
= ResourceBundle
.getBundle(TTerminalWidget
.class.getName());
73 // ------------------------------------------------------------------------
74 // Variables --------------------------------------------------------------
75 // ------------------------------------------------------------------------
80 private ECMA48 emulator
;
83 * The Process created by the shell spawning constructor.
85 private Process shell
;
88 * If true, we are using the ptypipe utility to support dynamic window
89 * resizing. ptypipe is available at
90 * https://gitlab.com/klamonte/ptypipe .
92 private boolean ptypipe
= false;
97 private GlyphMaker doubleFont
;
100 * Last text width value.
102 private int lastTextWidth
= -1;
105 * Last text height value.
107 private int lastTextHeight
= -1;
110 * The blink state, used only by ECMA48 backend and when double-width
111 * chars must be drawn.
113 private boolean blinkState
= true;
116 * Timer flag, used only by ECMA48 backend and when double-width chars
119 private boolean haveTimer
= false;
122 * The last seen scrollback lines.
124 private List
<DisplayLine
> scrollback
;
127 * The last seen display lines.
129 private List
<DisplayLine
> display
;
132 * If true, the display has changed and needs updating.
134 private volatile boolean dirty
= true;
137 * Time that the display was last updated.
139 private long lastUpdateTime
= 0;
142 * If true, hide the mouse after typing a keystroke.
144 private boolean hideMouseWhenTyping
= true;
147 * If true, the mouse should not be displayed because a keystroke was
150 private boolean typingHidMouse
= false;
153 * The return value from the emulator.
155 private int exitValue
= -1;
158 * Title to expose to a window.
160 private String title
= "";
162 // ------------------------------------------------------------------------
163 // Constructors -----------------------------------------------------------
164 // ------------------------------------------------------------------------
167 * Public constructor spawns a custom command line.
169 * @param parent parent widget
170 * @param x column relative to parent
171 * @param y row relative to parent
172 * @param commandLine the command line to execute
174 public TTerminalWidget(final TWidget parent
, final int x
,
175 final int y
, final String commandLine
) {
177 this(parent
, x
, y
, commandLine
.split("\\s+"));
181 * Public constructor spawns a custom command line.
183 * @param parent parent widget
184 * @param x column relative to parent
185 * @param y row relative to parent
186 * @param command the command line to execute
188 public TTerminalWidget(final TWidget parent
, final int x
,
189 final int y
, final String
[] command
) {
191 super(parent
, x
, y
, 80, 24);
193 String
[] fullCommand
;
195 // Spawn a shell and pass its I/O to the other constructor.
196 if ((System
.getProperty("jexer.TTerminal.ptypipe") != null)
197 && (System
.getProperty("jexer.TTerminal.ptypipe").
201 fullCommand
= new String
[command
.length
+ 1];
202 fullCommand
[0] = "ptypipe";
203 System
.arraycopy(command
, 0, fullCommand
, 1, command
.length
);
204 } else if (System
.getProperty("os.name").startsWith("Windows")) {
205 fullCommand
= new String
[3];
206 fullCommand
[0] = "cmd";
207 fullCommand
[1] = "/c";
208 fullCommand
[2] = stringArrayToString(command
);
209 } else if (System
.getProperty("os.name").startsWith("Mac")) {
210 fullCommand
= new String
[6];
211 fullCommand
[0] = "script";
212 fullCommand
[1] = "-q";
213 fullCommand
[2] = "-F";
214 fullCommand
[3] = "/dev/null";
215 fullCommand
[4] = "-c";
216 fullCommand
[5] = stringArrayToString(command
);
218 // Default: behave like Linux
219 fullCommand
= new String
[5];
220 fullCommand
[0] = "script";
221 fullCommand
[1] = "-fqe";
222 fullCommand
[2] = "/dev/null";
223 fullCommand
[3] = "-c";
224 fullCommand
[4] = stringArrayToString(command
);
226 spawnShell(fullCommand
);
230 * Public constructor spawns a shell.
232 * @param parent parent widget
233 * @param x column relative to parent
234 * @param y row relative to parent
236 public TTerminalWidget(final TWidget parent
, final int x
, final int y
) {
238 super(parent
, x
, y
, 80, 24);
240 if (System
.getProperty("jexer.TTerminal.shell") != null) {
241 String shell
= System
.getProperty("jexer.TTerminal.shell");
242 if (shell
.trim().startsWith("ptypipe")) {
245 spawnShell(shell
.split("\\s+"));
249 String cmdShellWindows
= "cmd.exe";
251 // You cannot run a login shell in a bare Process interactively, due
252 // to libc's behavior of buffering when stdin/stdout aren't a tty.
253 // Use 'script' instead to run a shell in a pty. And because BSD and
254 // GNU differ on the '-f' vs '-F' flags, we need two different
256 String cmdShellGNU
= "script -fqe /dev/null";
257 String cmdShellBSD
= "script -q -F /dev/null";
259 // ptypipe is another solution that permits dynamic window resizing.
260 String cmdShellPtypipe
= "ptypipe /bin/bash --login";
262 // Spawn a shell and pass its I/O to the other constructor.
263 if ((System
.getProperty("jexer.TTerminal.ptypipe") != null)
264 && (System
.getProperty("jexer.TTerminal.ptypipe").
268 spawnShell(cmdShellPtypipe
.split("\\s+"));
269 } else if (System
.getProperty("os.name").startsWith("Windows")) {
270 spawnShell(cmdShellWindows
.split("\\s+"));
271 } else if (System
.getProperty("os.name").startsWith("Mac")) {
272 spawnShell(cmdShellBSD
.split("\\s+"));
273 } else if (System
.getProperty("os.name").startsWith("Linux")) {
274 spawnShell(cmdShellGNU
.split("\\s+"));
276 // When all else fails, assume GNU.
277 spawnShell(cmdShellGNU
.split("\\s+"));
281 // ------------------------------------------------------------------------
282 // TScrollableWidget ------------------------------------------------------
283 // ------------------------------------------------------------------------
286 * Draw the display buffer.
290 int width
= getDisplayWidth();
291 boolean syncEmulator
= false;
292 if ((System
.currentTimeMillis() - lastUpdateTime
>= 25)
295 // Too much time has passed, draw it all.
297 } else if (emulator
.isReading() && (dirty
== false)) {
298 // Wait until the emulator has brought more data in.
299 syncEmulator
= false;
300 } else if (!emulator
.isReading() && (dirty
== true)) {
301 // The emulator won't receive more data, update the display.
305 if ((syncEmulator
== true)
306 || (scrollback
== null)
309 // We want to minimize the amount of time we have the emulator
310 // locked. Grab a copy of its display.
311 synchronized (emulator
) {
312 // Update the scroll bars
315 if ((scrollback
== null) || emulator
.isReading()) {
316 scrollback
= copyBuffer(emulator
.getScrollbackBuffer());
317 display
= copyBuffer(emulator
.getDisplayBuffer());
319 width
= emulator
.getWidth();
324 // Draw the box using my superclass
327 // Put together the visible rows
328 int visibleHeight
= getHeight();
329 int visibleBottom
= scrollback
.size() + display
.size()
330 + getVerticalValue();
331 assert (visibleBottom
>= 0);
333 List
<DisplayLine
> preceedingBlankLines
= new ArrayList
<DisplayLine
>();
334 int visibleTop
= visibleBottom
- visibleHeight
;
335 if (visibleTop
< 0) {
336 for (int i
= visibleTop
; i
< 0; i
++) {
337 preceedingBlankLines
.add(emulator
.getBlankDisplayLine());
341 assert (visibleTop
>= 0);
343 List
<DisplayLine
> displayLines
= new ArrayList
<DisplayLine
>();
344 displayLines
.addAll(scrollback
);
345 displayLines
.addAll(display
);
347 List
<DisplayLine
> visibleLines
= new ArrayList
<DisplayLine
>();
348 visibleLines
.addAll(preceedingBlankLines
);
349 visibleLines
.addAll(displayLines
.subList(visibleTop
,
352 visibleHeight
-= visibleLines
.size();
353 assert (visibleHeight
>= 0);
355 // Now draw the emulator screen
357 for (DisplayLine line
: visibleLines
) {
358 int widthMax
= width
;
359 if (line
.isDoubleWidth()) {
362 if (widthMax
> getWidth()) {
363 widthMax
= getWidth();
365 for (int i
= 0; i
< widthMax
; i
++) {
366 Cell ch
= line
.charAt(i
);
369 putCharXY(i
, row
, ch
);
373 Cell newCell
= new Cell(ch
);
374 boolean reverse
= line
.isReverseColor() ^ ch
.isReverse();
375 newCell
.setReverse(false);
377 if (ch
.getForeColorRGB() < 0) {
378 newCell
.setBackColor(ch
.getForeColor());
379 newCell
.setBackColorRGB(-1);
381 newCell
.setBackColorRGB(ch
.getForeColorRGB());
383 if (ch
.getBackColorRGB() < 0) {
384 newCell
.setForeColor(ch
.getBackColor());
385 newCell
.setForeColorRGB(-1);
387 newCell
.setForeColorRGB(ch
.getBackColorRGB());
390 if (line
.isDoubleWidth()) {
391 putDoubleWidthCharXY(line
, (i
* 2), row
, newCell
);
393 putCharXY(i
, row
, newCell
);
397 if (row
== getHeight()) {
398 // Don't overwrite the box edge
402 CellAttributes background
= new CellAttributes();
403 // Fill in the blank lines on bottom
404 for (int i
= 0; i
< visibleHeight
; i
++) {
405 hLineXY(0, i
+ row
, getWidth(), ' ', background
);
411 * Handle window close.
414 public void close() {
417 terminateShellChildProcess();
424 * Handle window/screen resize events.
426 * @param resize resize event
429 public void onResize(final TResizeEvent resize
) {
431 // Synchronize against the emulator so we don't stomp on its reader
433 synchronized (emulator
) {
435 if (resize
.getType() == TResizeEvent
.Type
.WIDGET
) {
436 // Resize the scroll bars
440 // Get out of scrollback
444 emulator
.setWidth(getWidth());
445 emulator
.setHeight(getHeight());
447 emulator
.writeRemote("\033[8;" + getHeight() + ";" +
451 // Pass the correct text cell width/height to the emulator
452 if (getScreen() != null) {
453 emulator
.setTextWidth(getScreen().getTextWidth());
454 emulator
.setTextHeight(getScreen().getTextHeight());
459 } // synchronized (emulator)
463 * Resize scrollbars for a new width/height.
466 public void reflowData() {
468 // Synchronize against the emulator so we don't stomp on its reader
470 synchronized (emulator
) {
472 // Pull cursor information
475 // Vertical scrollbar
476 setTopValue(getHeight()
477 - (emulator
.getScrollbackBuffer().size()
478 + emulator
.getDisplayBuffer().size()));
479 setVerticalBigChange(getHeight());
481 } // synchronized (emulator)
487 * @param keypress keystroke event
490 public void onKeypress(final TKeypressEvent keypress
) {
491 if (hideMouseWhenTyping
) {
492 typingHidMouse
= true;
495 // Scrollback up/down
496 if (keypress
.equals(kbShiftPgUp
)
497 || keypress
.equals(kbCtrlPgUp
)
498 || keypress
.equals(kbAltPgUp
)
500 bigVerticalDecrement();
503 if (keypress
.equals(kbShiftPgDn
)
504 || keypress
.equals(kbCtrlPgDn
)
505 || keypress
.equals(kbAltPgDn
)
507 bigVerticalIncrement();
511 if (emulator
.isReading()) {
512 // Get out of scrollback
514 emulator
.addUserEvent(keypress
);
516 // UGLY HACK TIME! cmd.exe needs CRLF, not just CR, so if
517 // this is kBEnter then also send kbCtrlJ.
518 if (keypress
.equals(kbEnter
)) {
519 if (System
.getProperty("os.name").startsWith("Windows")
520 && (System
.getProperty("jexer.TTerminal.cmdHack",
521 "true").equals("true"))
523 emulator
.addUserEvent(new TKeypressEvent(kbCtrlJ
));
531 // Process is closed, honor "normal" TUI keystrokes
532 super.onKeypress(keypress
);
536 * Handle mouse press events.
538 * @param mouse mouse button press event
541 public void onMouseDown(final TMouseEvent mouse
) {
542 if (hideMouseWhenTyping
) {
543 typingHidMouse
= false;
546 // If the emulator is tracking mouse buttons, it needs to see wheel
548 if (emulator
.getMouseProtocol() == ECMA48
.MouseProtocol
.OFF
) {
549 if (mouse
.isMouseWheelUp()) {
553 if (mouse
.isMouseWheelDown()) {
558 if (mouseOnEmulator(mouse
)) {
559 emulator
.addUserEvent(mouse
);
564 // Emulator didn't consume it, pass it on
565 super.onMouseDown(mouse
);
569 * Handle mouse release events.
571 * @param mouse mouse button release event
574 public void onMouseUp(final TMouseEvent mouse
) {
575 if (hideMouseWhenTyping
) {
576 typingHidMouse
= false;
579 if (mouseOnEmulator(mouse
)) {
580 emulator
.addUserEvent(mouse
);
585 // Emulator didn't consume it, pass it on
586 super.onMouseUp(mouse
);
590 * Handle mouse motion events.
592 * @param mouse mouse motion event
595 public void onMouseMotion(final TMouseEvent mouse
) {
596 if (hideMouseWhenTyping
) {
597 typingHidMouse
= false;
600 if (mouseOnEmulator(mouse
)) {
601 emulator
.addUserEvent(mouse
);
606 // Emulator didn't consume it, pass it on
607 super.onMouseMotion(mouse
);
610 // ------------------------------------------------------------------------
611 // TTerminalWidget --------------------------------------------------------
612 // ------------------------------------------------------------------------
615 * Get the desired window title.
619 public String
getTitle() {
624 * Returns true if this window does not want the application-wide mouse
625 * cursor drawn over it.
627 * @return true if this window does not want the application-wide mouse
628 * cursor drawn over it
630 public boolean hasHiddenMouse() {
631 return (emulator
.hasHiddenMousePointer() || typingHidMouse
);
635 * See if the terminal is still running.
637 * @return if true, we are still connected to / reading from the remote
640 public boolean isReading() {
641 return emulator
.isReading();
645 * Convert a string array to a whitespace-separated string.
647 * @param array the string array
648 * @return a single string
650 private String
stringArrayToString(final String
[] array
) {
651 StringBuilder sb
= new StringBuilder(array
[0].length());
652 for (int i
= 0; i
< array
.length
; i
++) {
654 if (i
< array
.length
- 1) {
658 return sb
.toString();
664 * @param command the command line to execute
666 private void spawnShell(final String
[] command
) {
669 System.err.printf("spawnShell(): '%s'\n",
670 stringArrayToString(command));
673 // We will have vScroller for its data fields and mouse event
674 // handling, but do not want to draw it.
675 vScroller
= new TVScroller(null, getWidth(), 0, getHeight());
676 vScroller
.setVisible(false);
679 title
= i18n
.getString("windowTitle");
682 ECMA48
.DeviceType deviceType
= ECMA48
.DeviceType
.XTERM
;
685 ProcessBuilder pb
= new ProcessBuilder(command
);
686 Map
<String
, String
> env
= pb
.environment();
687 env
.put("TERM", ECMA48
.deviceTypeTerm(deviceType
));
688 env
.put("LANG", ECMA48
.deviceTypeLang(deviceType
, "en"));
689 env
.put("COLUMNS", "80");
690 env
.put("LINES", "24");
691 pb
.redirectErrorStream(true);
693 emulator
= new ECMA48(deviceType
, shell
.getInputStream(),
694 shell
.getOutputStream(), this);
695 } catch (IOException e
) {
696 messageBox(i18n
.getString("errorLaunchingShellTitle"),
697 MessageFormat
.format(i18n
.getString("errorLaunchingShellText"),
701 // Setup the scroll bars
702 onResize(new TResizeEvent(TResizeEvent
.Type
.WIDGET
, getWidth(),
705 // Hide mouse when typing option
706 if (System
.getProperty("jexer.TTerminal.hideMouseWhenTyping",
707 "true").equals("false")) {
709 hideMouseWhenTyping
= false;
714 * Terminate the child of the 'script' process used on POSIX. This may
717 private void terminateShellChildProcess() {
719 if (shell
.getClass().getName().equals("java.lang.UNIXProcess")) {
720 /* get the PID on unix/linux systems */
722 Field field
= shell
.getClass().getDeclaredField("pid");
723 field
.setAccessible(true);
724 pid
= field
.getInt(shell
);
725 } catch (Throwable e
) {
726 // SQUASH, this didn't work. Just bail out quietly.
731 // shell.destroy() works successfully at killing this side of
732 // 'script'. But we need to make sure the other side (child
733 // process) is also killed.
734 String
[] cmdKillIt
= {
735 "pkill", "-P", Integer
.toString(pid
)
738 Runtime
.getRuntime().exec(cmdKillIt
);
739 } catch (Throwable e
) {
740 // SQUASH, this didn't work. Just bail out quietly.
747 * Hook for subclasses to be notified of the shell termination.
749 public void onShellExit() {
750 if (getParent() instanceof TTerminalWindow
) {
751 ((TTerminalWindow
) getParent()).onShellExit();
753 getApplication().postEvent(new TMenuEvent(TMenu
.MID_REPAINT
));
757 * Copy out variables from the emulator that TTerminal has to expose on
760 private void readEmulatorState() {
761 // Synchronize against the emulator so we don't stomp on its reader
763 synchronized (emulator
) {
765 setCursorX(emulator
.getCursorX());
766 setCursorY(emulator
.getCursorY()
767 + (getHeight() - emulator
.getHeight())
768 - getVerticalValue());
769 setCursorVisible(emulator
.isCursorVisible());
770 if (getCursorX() > getWidth()) {
771 setCursorVisible(false);
773 if ((getCursorY() >= getHeight()) || (getCursorY() < 0)) {
774 setCursorVisible(false);
776 if (emulator
.getScreenTitle().length() > 0) {
777 // Only update the title if the shell is still alive
779 title
= emulator
.getScreenTitle();
783 // Check to see if the shell has died.
784 if (!emulator
.isReading() && (shell
!= null)) {
786 int rc
= shell
.exitValue();
787 // The emulator exited on its own, all is fine
788 title
= MessageFormat
.format(i18n
.
789 getString("windowTitleCompleted"), title
, rc
);
794 } catch (IllegalThreadStateException e
) {
795 // The emulator thread has exited, but the shell Process
796 // hasn't figured that out yet. Do nothing, we will see
797 // this in a future tick.
799 } else if (emulator
.isReading() && (shell
!= null)) {
800 // The shell might be dead, let's check
802 int rc
= shell
.exitValue();
803 // If we got here, the shell died.
804 title
= MessageFormat
.format(i18n
.
805 getString("windowTitleCompleted"), title
, rc
);
810 } catch (IllegalThreadStateException e
) {
811 // The shell is still running, do nothing.
815 } // synchronized (emulator)
819 * Check if a mouse press/release/motion event coordinate is over the
822 * @param mouse a mouse-based event
823 * @return whether or not the mouse is on the emulator
825 private boolean mouseOnEmulator(final TMouseEvent mouse
) {
827 if (!emulator
.isReading()) {
831 if ((mouse
.getX() >= 0)
832 && (mouse
.getX() < getWidth() - 1)
833 && (mouse
.getY() >= 0)
834 && (mouse
.getY() < getHeight())
842 * Copy a display buffer.
844 * @param buffer the buffer to copy
845 * @return a deep copy of the buffer's data
847 private List
<DisplayLine
> copyBuffer(final List
<DisplayLine
> buffer
) {
848 ArrayList
<DisplayLine
> result
= new ArrayList
<DisplayLine
>(buffer
.size());
849 for (DisplayLine line
: buffer
) {
850 result
.add(new DisplayLine(line
));
856 * Draw glyphs for a double-width or double-height VT100 cell to two
859 * @param line the line this VT100 cell is in
860 * @param x the X position to draw the left half to
861 * @param y the Y position to draw to
862 * @param cell the cell to draw
864 private void putDoubleWidthCharXY(final DisplayLine line
, final int x
,
865 final int y
, final Cell cell
) {
867 int textWidth
= getScreen().getTextWidth();
868 int textHeight
= getScreen().getTextHeight();
869 boolean cursorBlinkVisible
= true;
871 if (getScreen() instanceof SwingTerminal
) {
872 SwingTerminal terminal
= (SwingTerminal
) getScreen();
873 cursorBlinkVisible
= terminal
.getCursorBlinkVisible();
874 } else if (getScreen() instanceof ECMA48Terminal
) {
875 ECMA48Terminal terminal
= (ECMA48Terminal
) getScreen();
877 if (!terminal
.hasSixel()) {
878 // The backend does not have sixel support, draw this as text
880 putCharXY(x
, y
, cell
);
881 putCharXY(x
+ 1, y
, ' ', cell
);
884 cursorBlinkVisible
= blinkState
;
886 // We don't know how to dray glyphs to this screen, draw them as
887 // text and bail out.
888 putCharXY(x
, y
, cell
);
889 putCharXY(x
+ 1, y
, ' ', cell
);
893 if ((textWidth
!= lastTextWidth
) || (textHeight
!= lastTextHeight
)) {
894 // Screen size has changed, reset the font.
895 setupFont(textHeight
);
896 lastTextWidth
= textWidth
;
897 lastTextHeight
= textHeight
;
899 assert (doubleFont
!= null);
902 if (line
.getDoubleHeight() == 1) {
903 // Double-height top half: don't draw the underline.
904 Cell newCell
= new Cell(cell
);
905 newCell
.setUnderline(false);
906 image
= doubleFont
.getImage(newCell
, textWidth
* 2, textHeight
* 2,
909 image
= doubleFont
.getImage(cell
, textWidth
* 2, textHeight
* 2,
913 // Now that we have the double-wide glyph drawn, copy the right
914 // pieces of it to the cells.
915 Cell left
= new Cell(cell
);
916 Cell right
= new Cell(cell
);
918 BufferedImage leftImage
= null;
919 BufferedImage rightImage
= null;
921 System.err.println("image " + image + " textWidth " + textWidth +
922 " textHeight " + textHeight);
925 switch (line
.getDoubleHeight()) {
927 // Top half double height
928 leftImage
= image
.getSubimage(0, 0, textWidth
, textHeight
);
929 rightImage
= image
.getSubimage(textWidth
, 0, textWidth
, textHeight
);
932 // Bottom half double height
933 leftImage
= image
.getSubimage(0, textHeight
, textWidth
, textHeight
);
934 rightImage
= image
.getSubimage(textWidth
, textHeight
,
935 textWidth
, textHeight
);
938 // Either single height double-width, or error fallback
939 BufferedImage wideImage
= new BufferedImage(textWidth
* 2,
940 textHeight
, BufferedImage
.TYPE_INT_ARGB
);
941 Graphics2D grWide
= wideImage
.createGraphics();
942 grWide
.drawImage(image
, 0, 0, wideImage
.getWidth(),
943 wideImage
.getHeight(), null);
945 leftImage
= wideImage
.getSubimage(0, 0, textWidth
, textHeight
);
946 rightImage
= wideImage
.getSubimage(textWidth
, 0, textWidth
,
950 left
.setImage(leftImage
);
951 right
.setImage(rightImage
);
952 // Since we have image data, ditch the character here. Otherwise, a
953 // drawBoxShadow() over the terminal window will show the characters
954 // which looks wrong.
957 putCharXY(x
, y
, left
);
958 putCharXY(x
+ 1, y
, right
);
962 * Set up the double-width font.
964 * @param fontSize the size of font to request for the single-width font.
965 * The double-width font will be 2x this value.
967 private void setupFont(final int fontSize
) {
968 doubleFont
= GlyphMaker
.getInstance(fontSize
* 2);
970 // Special case: the ECMA48 backend needs to have a timer to drive
972 if (getScreen() instanceof jexer
.backend
.ECMA48Terminal
) {
974 // Blink every 500 millis.
976 getApplication().addTimer(millis
, true,
979 blinkState
= !blinkState
;
980 getApplication().doRepaint();
989 // ------------------------------------------------------------------------
990 // DisplayListener --------------------------------------------------------
991 // ------------------------------------------------------------------------
994 * Called by emulator when fresh data has come in.
996 public void displayChanged() {
998 getApplication().postEvent(new TMenuEvent(TMenu
.MID_REPAINT
));
1002 * Function to call to obtain the display width.
1004 * @return the number of columns in the display
1006 public int getDisplayWidth() {
1014 * Function to call to obtain the display height.
1016 * @return the number of rows in the display
1018 public int getDisplayHeight() {