Skip to content

Commit 45fd233

Browse files
committed
Add configurable elapsed time display with format customization
This commit introduces a toggle to enable or disable the display of elapsed time in the console output in Console settings. Also added support for customizing the format of the elapsed time, allowing users to choose from multiple display styles based on their preferences or requirements. fixes : #2112
1 parent 8aa4a91 commit 45fd233

File tree

7 files changed

+84
-13
lines changed

7 files changed

+84
-13
lines changed

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPreferenceInitializer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2004, 2020 IBM Corporation and others.
2+
* Copyright (c) 2004, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -84,6 +84,8 @@ public void initializeDefaultPreferences() {
8484
prefs.setDefault(IDebugPreferenceConstants.CONSOLE_TAB_WIDTH, 8);
8585
prefs.setDefault(IDebugPreferenceConstants.CONSOLE_INTERPRET_CONTROL_CHARACTERS, false);
8686
prefs.setDefault(IDebugPreferenceConstants.CONSOLE_INTERPRET_CR_AS_CONTROL_CHARACTER, true);
87+
prefs.setDefault(IDebugPreferenceConstants.CONSOLE_ELAPSED_TIME, true);
88+
prefs.setDefault(IDebugPreferenceConstants.CONSOLE_ELAPSED_FORMAT, 0);
8789

8890
// console colors
8991
setThemeBasedPreferences(prefs, false);

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/ConsolePreferencePage.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2020 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -18,6 +18,7 @@
1818

1919
import org.eclipse.debug.internal.ui.DebugUIPlugin;
2020
import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
21+
import org.eclipse.debug.internal.ui.SWTFactory;
2122
import org.eclipse.jface.preference.BooleanFieldEditor;
2223
import org.eclipse.jface.preference.ColorFieldEditor;
2324
import org.eclipse.jface.preference.FieldEditor;
@@ -30,6 +31,7 @@
3031
import org.eclipse.swt.events.SelectionEvent;
3132
import org.eclipse.swt.layout.GridData;
3233
import org.eclipse.swt.widgets.Button;
34+
import org.eclipse.swt.widgets.Combo;
3335
import org.eclipse.swt.widgets.Composite;
3436
import org.eclipse.ui.IWorkbench;
3537
import org.eclipse.ui.IWorkbenchPreferencePage;
@@ -87,6 +89,9 @@ protected void clearErrorMessage() {
8789
private BooleanFieldEditor2 fInterpretControlCharactersEditor;
8890
private BooleanFieldEditor2 fInterpretCrAsControlCharacterEditor;
8991

92+
private BooleanFieldEditor2 fshowElapsedTime;
93+
private Combo fElapsedFormat;
94+
9095
/**
9196
* Create the console page.
9297
*/
@@ -107,6 +112,7 @@ public void createControl(Composite parent) {
107112
/**
108113
* Create all field editors for this page
109114
*/
115+
@SuppressWarnings("nls")
110116
@Override
111117
public void createFieldEditors() {
112118

@@ -159,6 +165,27 @@ public void widgetSelected(SelectionEvent e) {
159165
addField(new BooleanFieldEditor(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT, DebugPreferencesMessages.ConsolePreferencePage_Show__Console_View_when_there_is_program_output_3, SWT.NONE, getFieldEditorParent()));
160166
addField(new BooleanFieldEditor(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR, DebugPreferencesMessages.ConsolePreferencePage_Show__Console_View_when_there_is_program_error_3, SWT.NONE, getFieldEditorParent()));
161167

168+
fshowElapsedTime = new BooleanFieldEditor2(IDebugPreferenceConstants.CONSOLE_ELAPSED_TIME,
169+
DebugPreferencesMessages.ConsoleElapsedTime, SWT.NONE, getFieldEditorParent());
170+
SWTFactory.createLabel(getFieldEditorParent(), "Format ", 1); //$NON-NLS-1$
171+
fElapsedFormat = new Combo(getFieldEditorParent(), SWT.BORDER|SWT.READ_ONLY);
172+
fElapsedFormat
173+
.setItems(new String[] { "H:MM:SS", "HH:MM:SS", "HH:MM:SS.mmm", "MM:SS.mmm",
174+
"HHh MMm SSs" });
175+
int defaultFormat = DebugUIPlugin.getDefault().getPreferenceStore()
176+
.getInt(IDebugPreferenceConstants.CONSOLE_ELAPSED_FORMAT);
177+
fElapsedFormat.select(defaultFormat);
178+
179+
fshowElapsedTime.getChangeControl(getFieldEditorParent()).addSelectionListener(new SelectionAdapter() {
180+
@Override
181+
public void widgetSelected(SelectionEvent e) {
182+
updateElapsedTimePreferences();
183+
}
184+
});
185+
addField(fshowElapsedTime);
186+
187+
188+
162189
ColorFieldEditor sysout= new ColorFieldEditor(IDebugPreferenceConstants.CONSOLE_SYS_OUT_COLOR, DebugPreferencesMessages.ConsolePreferencePage_Standard_Out__2, getFieldEditorParent());
163190
ColorFieldEditor syserr= new ColorFieldEditor(IDebugPreferenceConstants.CONSOLE_SYS_ERR_COLOR, DebugPreferencesMessages.ConsolePreferencePage_Standard_Error__3, getFieldEditorParent());
164191
ColorFieldEditor sysin= new ColorFieldEditor(IDebugPreferenceConstants.CONSOLE_SYS_IN_COLOR, DebugPreferencesMessages.ConsolePreferencePage_Standard_In__4, getFieldEditorParent());
@@ -197,6 +224,8 @@ public boolean performOk() {
197224
int low = store.getInt(IDebugPreferenceConstants.CONSOLE_LOW_WATER_MARK);
198225
int high = low + 8000;
199226
store.setValue(IDebugPreferenceConstants.CONSOLE_HIGH_WATER_MARK, high);
227+
DebugUIPlugin.getDefault().getPreferenceStore().setValue(IDebugPreferenceConstants.CONSOLE_ELAPSED_FORMAT,
228+
fElapsedFormat.getSelectionIndex());
200229
return ok;
201230
}
202231

@@ -211,6 +240,8 @@ protected void initialize() {
211240
updateBufferSizeEditor();
212241
updateInterpretCrAsControlCharacterEditor();
213242
updateWordWrapEditorFromConsolePreferences();
243+
updateElapsedTimePreferences();
244+
214245
}
215246

216247
/**
@@ -266,6 +297,7 @@ protected void performDefaults() {
266297
updateWidthEditor();
267298
updateBufferSizeEditor();
268299
updateInterpretCrAsControlCharacterEditor();
300+
updateElapsedTimePreferences();
269301
}
270302

271303
protected boolean canClearErrorMessage() {
@@ -301,4 +333,12 @@ public void propertyChange(PropertyChangeEvent event) {
301333
super.propertyChange(event);
302334
}
303335
}
336+
337+
protected void updateElapsedTimePreferences() {
338+
Button b = fshowElapsedTime.getChangeControl(getFieldEditorParent());
339+
fElapsedFormat.setEnabled(b.getSelection());
340+
IPreferenceStore pref = DebugUIPlugin.getDefault().getPreferenceStore();
341+
pref.setValue(IDebugPreferenceConstants.CONSOLE_ELAPSED_TIME, b.getSelection());
342+
pref.setValue(IDebugPreferenceConstants.CONSOLE_ELAPSED_FORMAT, fElapsedFormat.getSelectionIndex());
343+
}
304344
}

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/DebugPreferencesMessages.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2020 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -218,5 +218,6 @@ public class DebugPreferencesMessages extends NLS {
218218

219219
public static String RunDebugPropertiesPage_0;
220220

221+
public static String ConsoleElapsedTime;
221222

222223
}

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/DebugPreferencesMessages.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
###############################################################################
2-
# Copyright (c) 2000, 2022 IBM Corporation and others.
2+
# Copyright (c) 2000, 2025 IBM Corporation and others.
33
#
44
# This program and the accompanying materials
55
# are made available under the terms of the Eclipse Public License 2.0
@@ -31,6 +31,7 @@ ConsolePreferencePage_11=Back&ground color:
3131
ConsolePreferencePage_Interpret_control_characters=Interpret ASCII &control characters
3232
ConsolePreferencePage_Interpret_cr_as_control_character=Interpret Carriage &Return (\\r) as control character
3333
ConsolePreferencePage_Enable_Word_Wrap_text=E&nable word wrap
34+
ConsoleElapsedTime=Show console elapsed time
3435

3536
DebugPreferencePage_1=General Settings for Running and Debugging.
3637
DebugPreferencePage_2=Re&use editor when displaying source code

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/IDebugPreferenceConstants.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2019 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -335,6 +335,8 @@ public interface IDebugPreferenceConstants {
335335
* @since 3.8
336336
*/
337337
String DEBUG_VIEW_TOOLBAR_HIDDEN_PERSPECTIVES = "org.eclipse.debug.ui.Debug_view.debug_toolbar_hidden_perspectives"; //$NON-NLS-1$
338+
String CONSOLE_ELAPSED_TIME = "org.eclipse.console.elapsedTime"; //$NON-NLS-1$
339+
String CONSOLE_ELAPSED_FORMAT = "org.eclipse.console.elapsedTimeFormat"; //$NON-NLS-1$
338340
}
339341

340342

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ConsoleMessages.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
###############################################################################
2-
# Copyright (c) 2000, 2020 IBM Corporation and others.
2+
# Copyright (c) 2000, 2025 IBM Corporation and others.
33
#
44
# This program and the accompanying materials
55
# are made available under the terms of the Eclipse Public License 2.0
@@ -25,8 +25,8 @@ ProcessConsole_0=<terminated> {0}
2525
ProcessConsole_1=[Console output redirected to file:{0}]\n
2626
ProcessConsole_2=[Invalid file specified for console output: {0}]\n
2727
ProcessConsole_3=[Invalid file specified for stdin file: {0}]\n
28-
ProcessConsole_commandLabel_withStart={0} ({1} elapsed: {2})
28+
ProcessConsole_commandLabel_withStart={0} ({1} {2})
2929
ProcessConsole_commandLabel_withEnd={0} (Terminated {1})
30-
ProcessConsole_commandLabel_withStartEnd={0} ({1} \u2013 {2} elapsed: {3})
30+
ProcessConsole_commandLabel_withStartEnd={0} ({1} \u2013 {2} {3})
3131
ShowStandardErrorAction_0=Show Console When Standard Error Changes
3232
ShowStandardOutAction_0=Show Console When Standard Out Changes

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2020 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -347,8 +347,6 @@ protected String computeName() {
347347
}
348348

349349
DateFormat dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
350-
Duration elapsedTime = Duration.between(launchTime != null ? launchTime.toInstant() : Instant.now(),
351-
terminateTime != null ? terminateTime.toInstant() : Instant.now());
352350
String elapsedFormat = "%d:%02d:%02d.%03d"; //$NON-NLS-1$
353351
if (terminateTime == null) {
354352
// refresh every second:
@@ -357,8 +355,20 @@ protected String computeName() {
357355
// pointless to update milliseconds:
358356
elapsedFormat = "%d:%02d:%02d"; //$NON-NLS-1$
359357
}
360-
String elapsedString = String.format(elapsedFormat, elapsedTime.toHours(),
361-
elapsedTime.toMinutesPart(), elapsedTime.toSecondsPart(), elapsedTime.toMillisPart());
358+
359+
IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
360+
boolean showElapsed = store.getBoolean(IDebugPreferenceConstants.CONSOLE_ELAPSED_TIME);
361+
362+
String elapsedString = "";//$NON-NLS-1$
363+
if (showElapsed) {
364+
Duration elapsedTime = Duration.between(
365+
launchTime != null ? launchTime.toInstant() : Instant.now(),
366+
terminateTime != null ? terminateTime.toInstant() : Instant.now());
367+
elapsedFormat = "elapsed: " + getElapsedFormat(); //$NON-NLS-1$
368+
elapsedString = String.format(elapsedFormat, elapsedTime.toHours(), elapsedTime.toMinutesPart(),
369+
elapsedTime.toSecondsPart(), elapsedTime.toMillisPart());
370+
}
371+
362372
if (launchTime != null && terminateTime != null) {
363373
String launchTimeStr = dateTimeFormat.format(launchTime);
364374
// Check if process started and terminated at same day. If so only print the
@@ -1114,4 +1124,19 @@ public boolean exists() {
11141124
public String getHelpContextId() {
11151125
return IDebugHelpContextIds.PROCESS_CONSOLE;
11161126
}
1127+
1128+
@SuppressWarnings("nls")
1129+
private String getElapsedFormat() {
1130+
IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
1131+
int format = store.getInt(IDebugPreferenceConstants.CONSOLE_ELAPSED_FORMAT);
1132+
return switch (format) {
1133+
case 0 -> "%d:%02d:%02d";
1134+
case 1 -> "%02d:%02d:%02d";
1135+
case 2 -> "%02d:%02d:%02d.%03d";
1136+
case 3 -> "%02d:%02d.%03d";
1137+
case 4 -> "%02dh %02dm %02ds";
1138+
default -> "%d:%02d:%02d";
1139+
};
1140+
1141+
}
11171142
}

0 commit comments

Comments
 (0)