Terminal now updates view title with last issued command.
diff --git a/com.google.eclipse.terminal.local/src/com/google/eclipse/terminal/local/ui/view/CommandListener.java b/com.google.eclipse.terminal.local/src/com/google/eclipse/terminal/local/ui/view/CommandListener.java
new file mode 100644
index 0000000..6f81d0c
--- /dev/null
+++ b/com.google.eclipse.terminal.local/src/com/google/eclipse/terminal/local/ui/view/CommandListener.java
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2012 Google Inc.
+ *
+ * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License v1.0 which accompanies this distribution, and is available at
+ *
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package com.google.eclipse.terminal.local.ui.view;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+interface CommandListener {
+ void commandIssued(String command);
+}
diff --git a/com.google.eclipse.terminal.local/src/com/google/eclipse/terminal/local/ui/view/TerminalView.java b/com.google.eclipse.terminal.local/src/com/google/eclipse/terminal/local/ui/view/TerminalView.java
index c4b14c7..8c67788 100644
--- a/com.google.eclipse.terminal.local/src/com/google/eclipse/terminal/local/ui/view/TerminalView.java
+++ b/com.google.eclipse.terminal.local/src/com/google/eclipse/terminal/local/ui/view/TerminalView.java
@@ -46,6 +46,8 @@
private static final String VIEW_ID = "com.google.eclipse.terminal.local.localTerminalView";
+ private static final String VIEW_TITLE_FORMAT = "%s : %s";
+
private IPropertyChangeListener preferencesChangeListener;
private IPropertyChangeListener textFontChangeListener;
private IMemento savedState;
@@ -103,6 +105,16 @@
@Override public void createPartControl(Composite parent) {
terminalWidget = new TerminalWidget(parent, SWT.NONE);
terminalWidget.setLifeCycleListener(this);
+ terminalWidget.setCommandListener(new CommandListener() {
+ @Override public void commandIssued(final String command) {
+ runInDisplayThread(new Runnable() {
+ @Override public void run() {
+ String title = String.format(VIEW_TITLE_FORMAT, workingDirectory.lastSegment(), command);
+ setPartName(title);
+ }
+ });
+ }
+ });
terminalWidget.setTerminalListener(new ITerminalListener() {
@Override public void setTerminalTitle(final String title) {
runInDisplayThread(new Runnable() {
diff --git a/com.google.eclipse.terminal.local/src/com/google/eclipse/terminal/local/ui/view/TerminalWidget.java b/com.google.eclipse.terminal.local/src/com/google/eclipse/terminal/local/ui/view/TerminalWidget.java
index 609c177..13edd97 100644
--- a/com.google.eclipse.terminal.local/src/com/google/eclipse/terminal/local/ui/view/TerminalWidget.java
+++ b/com.google.eclipse.terminal.local/src/com/google/eclipse/terminal/local/ui/view/TerminalWidget.java
@@ -34,7 +34,8 @@
* @author alruiz@google.com (Alex Ruiz)
*/
class TerminalWidget extends Composite {
- private static Pattern WHITE_SPACE_PATTERN = Pattern.compile("[\\s]+");
+ private static final String CRLF = "\r\n";
+ private static final Pattern WHITE_SPACE_PATTERN = Pattern.compile("[\\s]+");
private final TerminalListener terminalListener = new TerminalListener();
@@ -42,6 +43,7 @@
private final EditActions editActions;
private final LastCommandTracker lastCommandTracker;
+ private CommandListener commandListener;
private LifeCycleListener lifeCycleListener;
TerminalWidget(Composite parent, int style) {
@@ -166,9 +168,11 @@
terminalControl.setScrollLock(enabled);
}
- private class LastCommandTracker extends KeyAdapter implements IStreamListener {
- private static final String CRLF = "\r\n";
+ void setCommandListener(CommandListener listener) {
+ commandListener = listener;
+ }
+ private class LastCommandTracker extends KeyAdapter implements IStreamListener {
private final List<String> words = new ArrayList<String>();
@Override public void streamAppended(String text, IStreamMonitor monitor) {
@@ -191,11 +195,17 @@
if (e.character == '\r') {
int line = terminalControl.getCursorLine();
String text = new String(terminalControl.getChars(line));
- if (words.size() > 1) {
- String prompt = words.get(0);
- text = text.substring(prompt.length());
- String command = WHITE_SPACE_PATTERN.split(text)[0];
- System.out.println("command: " + command);
+ if (words.size() <= 1) {
+ return;
+ }
+ String prompt = words.get(0);
+ text = text.substring(prompt.length());
+ String[] actualInput = WHITE_SPACE_PATTERN.split(text);
+ if (actualInput.length != 0) {
+ String command = actualInput[0];
+ if (!command.isEmpty() && commandListener != null) {
+ commandListener.commandIssued(command);
+ }
}
}
}