From 9396711c5d9b23125ad0d3e6e8a06c73a127cde0 Mon Sep 17 00:00:00 2001
From: Rodrigo Rosenfeld Rosas <rr_rosas@yahoo.com.br>
Date: Mon, 1 Nov 2010 13:37:43 -0200
Subject: [PATCH 3/4] Separate normal unix bindings from Mac OS bindings

The Delete behavior is the only change currently.
---
 src/main/java/jline/Terminal.java                  |    6 ++-
 .../resources/jline/keybindings-mac.properties     |   62 ++++++++++++++++++++
 2 files changed, 67 insertions(+), 1 deletions(-)
 create mode 100644 src/main/resources/jline/keybindings-mac.properties

diff --git a/src/main/java/jline/Terminal.java b/src/main/java/jline/Terminal.java
index 9f268b3..6eecbe0 100644
--- a/src/main/java/jline/Terminal.java
+++ b/src/main/java/jline/Terminal.java
@@ -175,6 +175,10 @@ public abstract class Terminal implements ConsoleOperations {
     public abstract void disableEcho();
 
     public InputStream getDefaultBindings() {
-        return Terminal.class.getResourceAsStream("keybindings.properties");
+        // Mac bindings are slightly different from Unix/Linux.
+        // For instance, the Delete key behavior is different between them.
+        return Terminal.class.getResourceAsStream(
+                System.getProperty("os.name").toLowerCase().startsWith("mac") ?
+                    "keybindings-mac.properties" : "keybindings.properties");
     }
 }
diff --git a/src/main/resources/jline/keybindings-mac.properties b/src/main/resources/jline/keybindings-mac.properties
new file mode 100644
index 0000000..6f13615
--- /dev/null
+++ b/src/main/resources/jline/keybindings-mac.properties
@@ -0,0 +1,62 @@
+# Keybinding mapping for JLine. The format is:
+#    [key code]: [logical operation]
+
+# CTRL-B: move to the previous character
+2: PREV_CHAR
+
+# CTRL-G: move to the previous word
+7: PREV_WORD
+
+# CTRL-F: move to the next character
+6: NEXT_CHAR
+
+# CTRL-A: move to the beginning of the line
+1: MOVE_TO_BEG
+
+# CTRL-D: close out the input stream
+4: EXIT
+
+# CTRL-E: move the cursor to the end of the line
+5: MOVE_TO_END
+
+# BACKSPACE, CTRL-H: delete the previous character
+# 8 is the ASCII code for backspace and therefor
+# deleting the previous character
+8: DELETE_PREV_CHAR
+
+# TAB, CTRL-I: signal that console completion should be attempted
+9: COMPLETE
+
+# CTRL-J, CTRL-M: newline
+10: NEWLINE
+
+# CTRL-K: erase the current line
+11: KILL_LINE
+
+# ENTER: newline
+13: NEWLINE
+
+# CTRL-L: clear screen
+12: CLEAR_SCREEN
+
+# CTRL-N: scroll to the next element in the history buffer
+14: NEXT_HISTORY
+
+# CTRL-P: scroll to the previous element in the history buffer
+16: PREV_HISTORY
+
+# CTRL-R: redraw the current line
+18: REDISPLAY
+
+# CTRL-U: delete all the characters before the cursor position
+21: KILL_LINE_PREV
+
+# CTRL-V: paste the contents of the clipboard (useful for Windows terminal)
+22: PASTE
+
+# CTRL-W: delete the word directly before the cursor
+23: DELETE_PREV_WORD
+
+# DELETE, CTRL-?: delete the previous character
+# 127 is the ASCII code for delete
+127: DELETE_PREV_CHAR
-- 
1.7.2.3

