Skip to content

Commit 91db28d

Browse files
committed
Added terminal cursor display preferences
1 parent 0c3ec0c commit 91db28d

3 files changed

Lines changed: 100 additions & 14 deletions

File tree

spin-tools/src/com/maccasoft/propeller/Preferences.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,21 @@ public class Preferences {
6666
public static final String PROP_TERMINAL_FONT = "terminalFont";
6767
public static final String PROP_TERMINAL_LINE_INPUT = "terminalLineInput";
6868
public static final String PROP_TERMINAL_LOCAL_ECHO = "terminalLocalEcho";
69+
public static final String PROP_TERMINAL_CURSOR = "terminalCursor";
6970
public static final String PROP_CONSOLE_FONT = "consoleFont";
7071
public static final String PROP_CONSOLE_MAX_LINES = "consoleMaxLines";
7172
public static final String PROP_CONSOLE_WRITE_LOG_FILE = "consoleWriteLogFile";
7273
public static final String PROP_THEME = "theme";
7374
public static final String PROP_EXTERNAL_TOOLS = "externalTools";
7475
public static final String PROP_WINDOW_FONT = "windowFont";
7576

77+
public static final int CURSOR_OFF = 0x00;
78+
public static final int CURSOR_ON = 0x04;
79+
public static final int CURSOR_ULINE = 0x02;
80+
public static final int CURSOR_BLOCK = 0x00;
81+
public static final int CURSOR_FLASH = 0x01;
82+
public static final int CURSOR_SOLID = 0x00;
83+
7684
public static final String PREFERENCES_NAME = ".spin-tools";
7785

7886
public static File defaultSpin1LibraryPath = new File(System.getProperty("APP_DIR"), "library/spin1").getAbsoluteFile();
@@ -469,20 +477,22 @@ public static class TerminalPreferences {
469477
public String type;
470478
public String font;
471479
public int baudRate;
480+
public int cursor;
472481

473482
public TerminalPreferences() {
474483
lineInput = true;
475484
localEcho = false;
476485
type = "pst";
477486
baudRate = 115200;
487+
cursor = CURSOR_ON | CURSOR_FLASH | CURSOR_ULINE;
478488
}
479489

480490
@Override
481491
public int hashCode() {
482492
final int prime = 31;
483493
int result = 1;
484494
result = prime * result + Arrays.hashCode(history);
485-
result = prime * result + Objects.hash(baudRate, font, lineInput, localEcho, type, window);
495+
result = prime * result + Objects.hash(baudRate, font, lineInput, localEcho, type, window, cursor);
486496
return result;
487497
}
488498

@@ -1506,6 +1516,14 @@ public void setTerminalLocalEcho(boolean terminalLocalEcho) {
15061516
changeSupport.firePropertyChange(PROP_TERMINAL_LOCAL_ECHO, preferences.terminal.localEcho, preferences.terminal.localEcho = terminalLocalEcho);
15071517
}
15081518

1519+
public int getTerminalCursor() {
1520+
return preferences.terminal.cursor;
1521+
}
1522+
1523+
public void setTerminalCursor(int terminalCursor) {
1524+
changeSupport.firePropertyChange(PROP_TERMINAL_CURSOR, preferences.terminal.cursor, preferences.terminal.cursor = terminalCursor);
1525+
}
1526+
15091527
public String getConsoleFont() {
15101528
return preferences.console.font;
15111529
}

spin-tools/src/com/maccasoft/propeller/PreferencesDialog.java

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ public class PreferencesDialog extends Dialog {
220220
boolean oldTerminalLineInput;
221221
boolean oldTerminalLocalEcho;
222222
String oldConsoleFont;
223+
int oldTerminalCursor;
223224

224225
static int lastPage;
225226

@@ -562,6 +563,7 @@ public void widgetSelected(SelectionEvent e) {
562563
oldTerminalLineInput = preferences.getTerminalLineInput();
563564
oldTerminalLocalEcho = preferences.getTerminalLocalEcho();
564565
oldConsoleFont = preferences.getConsoleFont();
566+
oldTerminalCursor = preferences.getTerminalCursor();
565567

566568
return composite;
567569
}
@@ -1514,9 +1516,71 @@ public void widgetSelected(SelectionEvent e) {
15141516
terminalFont.setText(fontData.getName());
15151517
terminalFontSize.setSelection(fontData.getHeight());
15161518

1517-
new Label(composite, SWT.NONE);
1519+
label = new Label(composite, SWT.NONE);
1520+
label.setText("Cursor");
15181521

15191522
Composite group = new Composite(composite, SWT.NONE);
1523+
layout = new GridLayout(2, false);
1524+
layout.marginHeight = layout.marginWidth = 0;
1525+
group.setLayout(layout);
1526+
group.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
1527+
1528+
int cursorState = preferences.getTerminalCursor();
1529+
1530+
Combo combo = new Combo(group, SWT.DROP_DOWN);
1531+
combo.setItems("None", "Underline", "Block");
1532+
if ((cursorState & Preferences.CURSOR_ON) == 0) {
1533+
combo.select(0);
1534+
}
1535+
else if ((cursorState & Preferences.CURSOR_ULINE) != 0) {
1536+
combo.select(1);
1537+
}
1538+
else {
1539+
combo.select(2);
1540+
}
1541+
combo.addSelectionListener(new SelectionAdapter() {
1542+
1543+
@Override
1544+
public void widgetSelected(SelectionEvent e) {
1545+
int cursorState = preferences.getTerminalCursor() & Preferences.CURSOR_FLASH;
1546+
int selection = ((Combo) e.widget).getSelectionIndex();
1547+
if (selection == 0) {
1548+
cursorState |= Preferences.CURSOR_OFF;
1549+
}
1550+
else if (selection == 1) {
1551+
cursorState |= Preferences.CURSOR_ON | Preferences.CURSOR_ULINE;
1552+
}
1553+
else if (selection == 2) {
1554+
cursorState |= Preferences.CURSOR_ON | Preferences.CURSOR_BLOCK;
1555+
}
1556+
preferences.setTerminalCursor(cursorState);
1557+
}
1558+
1559+
});
1560+
1561+
Button blinkCursor = new Button(group, SWT.CHECK);
1562+
blinkCursor.setText("Blinking");
1563+
blinkCursor.setSelection(preferences.getTerminalLocalEcho());
1564+
blinkCursor.addSelectionListener(new SelectionAdapter() {
1565+
1566+
@Override
1567+
public void widgetSelected(SelectionEvent e) {
1568+
int cursorState = preferences.getTerminalCursor();
1569+
if (((Button) e.widget).getSelection()) {
1570+
cursorState |= Preferences.CURSOR_FLASH;
1571+
}
1572+
else {
1573+
cursorState &= ~Preferences.CURSOR_FLASH;
1574+
}
1575+
preferences.setTerminalCursor(cursorState);
1576+
}
1577+
1578+
});
1579+
blinkCursor.setSelection((cursorState & Preferences.CURSOR_FLASH) != 0);
1580+
1581+
new Label(composite, SWT.NONE);
1582+
1583+
group = new Composite(composite, SWT.NONE);
15201584
layout = new GridLayout(1, false);
15211585
layout.marginHeight = layout.marginWidth = 0;
15221586
group.setLayout(layout);
@@ -2268,6 +2332,7 @@ protected void cancelPressed() {
22682332
preferences.setTerminalFont(oldTerminalFont);
22692333
preferences.setTerminalLineInput(oldTerminalLineInput);
22702334
preferences.setTerminalLocalEcho(oldTerminalLocalEcho);
2335+
preferences.setTerminalCursor(oldTerminalCursor);
22712336

22722337
preferences.setConsoleFont(oldConsoleFont);
22732338

spin-tools/src/com/maccasoft/propeller/SerialTerminal.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ public class SerialTerminal {
8686

8787
public static final String WINDOW_TITLE = "Serial Terminal";
8888

89-
public static final int CURSOR_OFF = 0x00;
90-
public static final int CURSOR_ON = 0x04;
91-
public static final int CURSOR_ULINE = 0x02;
92-
public static final int CURSOR_BLOCK = 0x00;
93-
public static final int CURSOR_FLASH = 0x01;
94-
public static final int CURSOR_SOLID = 0x00;
89+
public static final int CURSOR_OFF = Preferences.CURSOR_OFF;
90+
public static final int CURSOR_ON = Preferences.CURSOR_ON;
91+
public static final int CURSOR_ULINE = Preferences.CURSOR_ULINE;
92+
public static final int CURSOR_BLOCK = Preferences.CURSOR_BLOCK;
93+
public static final int CURSOR_FLASH = Preferences.CURSOR_FLASH;
94+
public static final int CURSOR_SOLID = Preferences.CURSOR_SOLID;
9595

9696
public static final int CURSOR_DISPLAY = 0x1000;
9797

@@ -217,9 +217,6 @@ public void run() {
217217
if (canvas.isDisposed()) {
218218
return;
219219
}
220-
if (lineInputGroup.getVisible()) {
221-
return;
222-
}
223220
frameCounter++;
224221
if (frameCounter >= 15) {
225222
if ((cursorState & CURSOR_FLASH) != 0) {
@@ -863,13 +860,19 @@ public void propertyChange(PropertyChangeEvent evt) {
863860
break;
864861

865862
case Preferences.PROP_TERMINAL_LINE_INPUT:
863+
cy = 0;
866864
setLineInputGroupVisible((Boolean) evt.getNewValue());
867865
break;
868866

869867
case Preferences.PROP_TERMINAL_LOCAL_ECHO:
870868
localEcho = (Boolean) evt.getNewValue();
871869
break;
872870

871+
case Preferences.PROP_TERMINAL_CURSOR:
872+
cursorState = (cursorState & CURSOR_DISPLAY) | (Integer) evt.getNewValue();
873+
redraw(cx, cy, 1, 1);
874+
break;
875+
873876
case Preferences.PROP_THEME:
874877
applyTheme((String) evt.getNewValue());
875878
break;
@@ -897,7 +900,7 @@ public SerialTerminal(Display display, Preferences preferences) {
897900
break;
898901
}
899902

900-
cursorState = CURSOR_DISPLAY | CURSOR_ON | CURSOR_FLASH | CURSOR_ULINE;
903+
cursorState = CURSOR_DISPLAY | preferences.getTerminalCursor();
901904
}
902905

903906
public void open() {
@@ -1126,8 +1129,8 @@ public void paintControl(PaintEvent e) {
11261129
}
11271130
}
11281131

1129-
if (!lineInputGroup.getVisible()) {
1130-
if ((cursorState & (CURSOR_DISPLAY | CURSOR_ON)) == (CURSOR_DISPLAY | CURSOR_ON)) {
1132+
if ((cursorState & CURSOR_ON) != 0) {
1133+
if ((cursorState & CURSOR_FLASH) == 0 || (cursorState & (CURSOR_DISPLAY | CURSOR_FLASH)) == (CURSOR_DISPLAY | CURSOR_FLASH)) {
11311134
int h = characterHeight;
11321135
if ((cursorState & CURSOR_ULINE) != 0) {
11331136
h = characterHeight / 4;

0 commit comments

Comments
 (0)