Skip to content

Commit aade61f

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 a6bd13c commit aade61f

File tree

7 files changed

+82
-14
lines changed

7 files changed

+82
-14
lines changed

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

Lines changed: 4 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
@@ -15,6 +15,7 @@
1515
package org.eclipse.debug.internal.ui;
1616

1717
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
18+
import org.eclipse.debug.internal.ui.preferences.DebugPreferencesMessages;
1819
import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants;
1920
import org.eclipse.debug.internal.ui.views.memory.MemoryViewUtil;
2021
import org.eclipse.debug.ui.IDebugUIConstants;
@@ -84,6 +85,8 @@ public void initializeDefaultPreferences() {
8485
prefs.setDefault(IDebugPreferenceConstants.CONSOLE_TAB_WIDTH, 8);
8586
prefs.setDefault(IDebugPreferenceConstants.CONSOLE_INTERPRET_CONTROL_CHARACTERS, false);
8687
prefs.setDefault(IDebugPreferenceConstants.CONSOLE_INTERPRET_CR_AS_CONTROL_CHARACTER, true);
88+
prefs.setDefault(IDebugPreferenceConstants.CONSOLE_ELAPSED_FORMAT,
89+
DebugPreferencesMessages.ConsoleDefaultElapsedTimeFormat);
8790

8891
// console colors
8992
setThemeBasedPreferences(prefs, false);

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

Lines changed: 45 additions & 2 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
@@ -15,6 +15,7 @@
1515

1616

1717
import java.text.MessageFormat;
18+
import java.util.regex.Pattern;
1819

1920
import org.eclipse.debug.internal.ui.DebugUIPlugin;
2021
import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
@@ -24,6 +25,7 @@
2425
import org.eclipse.jface.preference.FieldEditorPreferencePage;
2526
import org.eclipse.jface.preference.IPreferenceStore;
2627
import org.eclipse.jface.preference.IntegerFieldEditor;
28+
import org.eclipse.jface.preference.StringFieldEditor;
2729
import org.eclipse.jface.util.PropertyChangeEvent;
2830
import org.eclipse.swt.SWT;
2931
import org.eclipse.swt.events.SelectionAdapter;
@@ -87,6 +89,8 @@ protected void clearErrorMessage() {
8789
private BooleanFieldEditor2 fInterpretControlCharactersEditor;
8890
private BooleanFieldEditor2 fInterpretCrAsControlCharacterEditor;
8991

92+
private StringFieldEditor fElapsedFormat;
93+
9094
/**
9195
* Create the console page.
9296
*/
@@ -159,6 +163,11 @@ public void widgetSelected(SelectionEvent e) {
159163
addField(new BooleanFieldEditor(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT, DebugPreferencesMessages.ConsolePreferencePage_Show__Console_View_when_there_is_program_output_3, SWT.NONE, getFieldEditorParent()));
160164
addField(new BooleanFieldEditor(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR, DebugPreferencesMessages.ConsolePreferencePage_Show__Console_View_when_there_is_program_error_3, SWT.NONE, getFieldEditorParent()));
161165

166+
fElapsedFormat = new StringFieldEditor(IDebugPreferenceConstants.CONSOLE_ELAPSED_FORMAT,
167+
DebugPreferencesMessages.ConsoleElapsedTimeLabel, getFieldEditorParent());
168+
fElapsedFormat.setErrorMessage(DebugPreferencesMessages.ConsoleElapsedTimeInvalidFormat);
169+
addField(fElapsedFormat);
170+
162171
ColorFieldEditor sysout= new ColorFieldEditor(IDebugPreferenceConstants.CONSOLE_SYS_OUT_COLOR, DebugPreferencesMessages.ConsolePreferencePage_Standard_Out__2, getFieldEditorParent());
163172
ColorFieldEditor syserr= new ColorFieldEditor(IDebugPreferenceConstants.CONSOLE_SYS_ERR_COLOR, DebugPreferencesMessages.ConsolePreferencePage_Standard_Error__3, getFieldEditorParent());
164173
ColorFieldEditor sysin= new ColorFieldEditor(IDebugPreferenceConstants.CONSOLE_SYS_IN_COLOR, DebugPreferencesMessages.ConsolePreferencePage_Standard_In__4, getFieldEditorParent());
@@ -197,6 +206,15 @@ public boolean performOk() {
197206
int low = store.getInt(IDebugPreferenceConstants.CONSOLE_LOW_WATER_MARK);
198207
int high = low + 8000;
199208
store.setValue(IDebugPreferenceConstants.CONSOLE_HIGH_WATER_MARK, high);
209+
210+
String elapsedTime = fElapsedFormat.getStringValue();
211+
if (validateElapsedTimeFormat(elapsedTime)) {
212+
DebugUIPlugin.getDefault().getPreferenceStore().setValue(IDebugPreferenceConstants.CONSOLE_ELAPSED_FORMAT,
213+
elapsedTime);
214+
} else {
215+
fElapsedFormat.showErrorMessage();
216+
}
217+
200218
return ok;
201219
}
202220

@@ -211,6 +229,8 @@ protected void initialize() {
211229
updateBufferSizeEditor();
212230
updateInterpretCrAsControlCharacterEditor();
213231
updateWordWrapEditorFromConsolePreferences();
232+
updateElapsedTimePreferences(false);
233+
214234
}
215235

216236
/**
@@ -266,10 +286,12 @@ protected void performDefaults() {
266286
updateWidthEditor();
267287
updateBufferSizeEditor();
268288
updateInterpretCrAsControlCharacterEditor();
289+
updateElapsedTimePreferences(true);
269290
}
270291

271292
protected boolean canClearErrorMessage() {
272-
return fWidthEditor.isValid() && fBufferSizeEditor.isValid() && fTabSizeEditor.isValid();
293+
return fWidthEditor.isValid() && fBufferSizeEditor.isValid() && fTabSizeEditor.isValid()
294+
&& fElapsedFormat.isValid();
273295
}
274296

275297
/**
@@ -301,4 +323,25 @@ public void propertyChange(PropertyChangeEvent event) {
301323
super.propertyChange(event);
302324
}
303325
}
326+
327+
protected void updateElapsedTimePreferences(boolean setDefault) {
328+
if (setDefault) {
329+
fElapsedFormat.setStringValue(DebugPreferencesMessages.ConsoleDefaultElapsedTimeFormat); // Default
330+
} else {
331+
IPreferenceStore pref = DebugUIPlugin.getDefault().getPreferenceStore();
332+
pref.setValue(IDebugPreferenceConstants.CONSOLE_ELAPSED_FORMAT, fElapsedFormat.getStringValue());
333+
}
334+
}
335+
336+
private boolean validateElapsedTimeFormat(String format) {
337+
if (format.isEmpty()) {
338+
return true;
339+
}
340+
String matcherFormat = "^((%d|%0\\d+d):%0\\d+d(:%0\\d+d)?(\\.%0\\d+d)?|(%0\\d+dh )?(%0\\d+dm )?(%0\\d+ds)?)$"; //$NON-NLS-1$
341+
Pattern pattern = Pattern.compile(matcherFormat);
342+
if (pattern.matcher(format).matches()) {
343+
return true;
344+
}
345+
return false;
346+
}
304347
}

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

Lines changed: 8 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,12 @@ public class DebugPreferencesMessages extends NLS {
218218

219219
public static String RunDebugPropertiesPage_0;
220220

221+
public static String ConsoleElapsedTime;
222+
223+
public static String ConsoleElapsedTimeInvalidFormat;
224+
225+
public static String ConsoleDefaultElapsedTimeFormat;
226+
227+
public static String ConsoleElapsedTimeLabel;
221228

222229
}

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

Lines changed: 5 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,10 @@ 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
35+
ConsoleElapsedTimeLabel=Elapsed Time Format (Leave blank to disable)
36+
ConsoleElapsedTimeInvalidFormat=Invalid elapsed time format, eg. %d:%02d:%02d, %02d:%02d:%02d.%03d
37+
ConsoleDefaultElapsedTimeFormat=%d:%02d:%02d
3438

3539
DebugPreferencePage_1=General Settings for Running and Debugging.
3640
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: 2 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,7 @@ 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_FORMAT = "org.eclipse.console.elapsedTimeFormat"; //$NON-NLS-1$
338339
}
339340

340341

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: 15 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+
361+
String elapsedTimeFormat = store.getString(IDebugPreferenceConstants.CONSOLE_ELAPSED_FORMAT);
362+
String elapsedString = "";//$NON-NLS-1$
363+
if (!elapsedTimeFormat.isEmpty()) {
364+
Duration elapsedTime = Duration.between(
365+
launchTime != null ? launchTime.toInstant() : Instant.now(),
366+
terminateTime != null ? terminateTime.toInstant() : Instant.now());
367+
elapsedFormat = "elapsed " + elapsedTimeFormat; //$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

0 commit comments

Comments
 (0)