Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix readline issues in Sublime Text 3

The code loading mechanism must have changed in ST3 because moving the code in
sublime_readline.py to the main file fixed it...

Fixes #55
  • Loading branch information...
commit a24bc8e570862116f790d1a009971326e5fce9db 1 parent af2a778
@misfo authored
Showing with 48 additions and 49 deletions.
  1. +48 −5 shell_turtlestein.py
  2. +0 −44 sublime_readline.py
View
53 shell_turtlestein.py
@@ -2,11 +2,6 @@
import sublime, sublime_plugin
from functools import partial
-import sys
-sys.path.append(os.path.dirname(__file__))
-
-from sublime_readline import show_input_panel_with_readline
-
def cwd_for_window(window):
"""
@@ -201,3 +196,51 @@ class SubprocessInCwdCommand(sublime_plugin.WindowCommand):
def run(self, cmd=None, wait=False):
cwd = cwd_for_window(self.window)
run_cmd(cwd, cmd, wait)
+
+
+###########################################################################
+# readline-related stuff...
+#
+# This was in a separate file, but that caused issues starting with Sublime
+# Text 3
+###########################################################################
+
+active_input_row = -1
+
+def callback_with_history(callback, cmd_history, input_text):
+ if callback:
+ cmd = input_text.split("\n")[active_input_row]
+ if cmd in cmd_history:
+ cmd_history.remove(cmd)
+ cmd_history.append(cmd)
+ return callback(cmd)
+
+def show_input_panel_with_readline(window, caption, cmd_history,
+ on_done, on_change, on_cancel):
+ global active_input_row
+ active_input_row = -1
+ view = window.show_input_panel(caption, "\n".join(cmd_history) + "\n",
+ partial(callback_with_history, on_done, cmd_history),
+ on_change, on_cancel)
+ view.settings().set('readline_input_widget', True)
+ view.show(view.size())
+ return view
+
+class ReadlineHistoryChange(sublime_plugin.TextCommand):
+ def run_(self, someIntNotUsed, args):
+ # Override default run_ so that an edit isn't created.
+ if 'event' in args:
+ del args['event']
+ return self.run(**args)
+
+ def run(self, movement, movement_args):
+ self.view.run_command(movement, movement_args)
+ self.view.run_command("move_to", {"to": "eol", "extend": False})
+ global active_input_row
+ active_input_row, _ = self.view.rowcol(self.view.sel()[0].b)
+
+class LeftDeleteOnLine(sublime_plugin.TextCommand):
+ def run(self, edit):
+ if self.view.rowcol(self.view.sel()[0].b)[1]:
+ # Don't left delete if the cursor is at the beginning of the line
+ self.view.run_command('left_delete')
View
44 sublime_readline.py
@@ -1,44 +0,0 @@
-# Adds some GNU readline-like features to an input widget
-
-import sublime_plugin
-from functools import partial
-
-active_input_row = -1
-
-def callback_with_history(callback, cmd_history, input_text):
- if callback:
- cmd = input_text.split("\n")[active_input_row]
- if cmd in cmd_history:
- cmd_history.remove(cmd)
- cmd_history.append(cmd)
- return callback(cmd)
-
-def show_input_panel_with_readline(window, caption, cmd_history,
- on_done, on_change, on_cancel):
- global active_input_row
- active_input_row = -1
- view = window.show_input_panel(caption, "\n".join(cmd_history) + "\n",
- partial(callback_with_history, on_done, cmd_history),
- on_change, on_cancel)
- view.settings().set('readline_input_widget', True)
- view.show(view.size())
- return view
-
-class ReadlineHistoryChange(sublime_plugin.TextCommand):
- def run_(self, someIntNotUsed, args):
- # Override default run_ so that an edit isn't created.
- if 'event' in args:
- del args['event']
- return self.run(**args)
-
- def run(self, movement, movement_args):
- self.view.run_command(movement, movement_args)
- self.view.run_command("move_to", {"to": "eol", "extend": False})
- global active_input_row
- active_input_row, _ = self.view.rowcol(self.view.sel()[0].b)
-
-class LeftDeleteOnLine(sublime_plugin.TextCommand):
- def run(self, edit):
- if self.view.rowcol(self.view.sel()[0].b)[1]:
- # Don't left delete if the cursor is at the beginning of the line
- self.view.run_command('left_delete')
Please sign in to comment.
Something went wrong with that request. Please try again.