Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Non-UTF console workaround.

+ Added console_encoding parameter to settings
+ Modific.py now uses this parameter to encode command line arguments for
popen
+ Updated README.md
+ Minor refactoring of Modific.py
  • Loading branch information...
commit 90715931eaa0136e4e5a4bbe2d21f118aef6ba0f 1 parent d65e1f8
@stdk stdk authored
Showing with 22 additions and 5 deletions.
  1. +17 −5 Modific.py
  2. +4 −0 Modific.sublime-settings
  3. +1 −0  README.md
View
22 Modific.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
import sublime
import sublime_plugin
import os
@@ -12,13 +13,19 @@
settings = sublime.load_settings("Modific.sublime-settings")
+#helper function to test for vcs existence in given folder
+#uses closure to lock cycle variable value inside lambda
+vcs_check = [ (lambda vcs: lambda dir: os.path.exists(os.path.join(dir,'.'+vcs))
+ and {'root': dir, 'name': vcs}) (vcs)
+ for vcs,_ in settings.get('vcs') ]
def get_vcs(directory):
- test = lambda vcs: lambda dir: os.path.exists(os.path.join(dir,'.'+vcs)) and {'root': dir, 'name': vcs}
- checkers = [ test(vcs) for vcs,_ in settings.get('vcs') ]
-
+ """
+ Determines, which of VCS systems we should use for given folder.
+ Currently, uses priority of definitions in settings.get('vcs')
+ """
while directory:
- available = filter(lambda x:x,[check(directory) for check in checkers ])
+ available = filter(lambda x:x,[check(directory) for check in vcs_check])
if available: return available[0]
parent = os.path.realpath(os.path.join(directory, os.path.pardir))
if parent == directory:
@@ -51,13 +58,14 @@ def do_when(conditional, callback, *args, **kwargs):
class CommandThread(threading.Thread):
- def __init__(self, command, on_done, working_dir="", fallback_encoding="", **kwargs):
+ def __init__(self, command, on_done, working_dir="", fallback_encoding="", console_encoding="", **kwargs):
threading.Thread.__init__(self)
self.command = command
self.on_done = on_done
self.working_dir = working_dir
self.stdin = kwargs.get('stdin',None)
self.stdout = kwargs.get('stdout',subprocess.PIPE)
+ self.console_encoding = console_encoding
self.fallback_encoding = fallback_encoding
self.kwargs = kwargs
@@ -69,6 +77,9 @@ def run(self):
if self.working_dir != "":
os.chdir(self.working_dir)
+ if self.console_encoding:
+ self.command = [s.encode(self.console_encoding) for s in self.command]
+
proc = subprocess.Popen(self.command,
stdout=self.stdout, stderr=subprocess.STDOUT,
stdin=subprocess.PIPE,
@@ -101,6 +112,7 @@ def run_command(self, command, callback=None, show_status=True,
kwargs['working_dir'] = self.get_working_dir()
if 'fallback_encoding' not in kwargs and self.active_view() and self.active_view().settings().get('fallback_encoding'):
kwargs['fallback_encoding'] = self.active_view().settings().get('fallback_encoding').rpartition('(')[2].rpartition(')')[0]
+ kwargs['console_encoding'] = settings.get('console_encoding')
if self.active_view() and self.active_view().is_dirty() and not no_save:
self.active_view().run_command('save')
View
4 Modific.sublime-settings
@@ -12,6 +12,10 @@
["hg" , "hg"]
],
+ //if you have some weird OS, that has non-unicode console
+ //place its console encoding here
+ "console_encoding" : "cp1251",
+
// if true, plugin prints some debug information to the console window
"debug": false
}
View
1  README.md
@@ -65,6 +65,7 @@ If you want to change something, don't do it in this file. Open `Preferences ->
You can configure is a type of icon (dot, circle or bookmark) and path for your VCS binaries (or leave them as is, if you have them in your PATH). It's also possible to set priority for VCS used (when you have more than one simultaneously) by reordering their definitions.
+If some sacred punishment has been bestowed upon you, and you have no other choice but to use OS, where console has non-UTF8 encoding, you can set console_encoding parameter to the name of your beloved encoding. This parameter is specifically designed for Windows XP users, who have their git repositories in folders with cyrillic path. Since russian XP uses CP1251 as default encoding (including console), VCS diff commands will be encoded appropriately, when using this parameter.
License
Please sign in to comment.
Something went wrong with that request. Please try again.