Permalink
Browse files

Merge pull request #5 from stdk/console-enc

Console encoding
  • Loading branch information...
2 parents f213b28 + cad7cc8 commit e8f23b10ca2f10562f7deb9230047acd06b9a2e1 @gornostal committed Jun 12, 2012
Showing with 20 additions and 4 deletions.
  1. +15 −4 Modific.py
  2. +4 −0 Modific.sublime-settings
  3. +1 −0 README.md
View
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
import sublime
import sublime_plugin
import os
@@ -14,11 +15,16 @@
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')
+ """
+ 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') ]
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 +57,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 +76,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 +111,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
@@ -12,6 +12,10 @@
["hg" , "hg"]
],
+ //if you have some weird OS, that has non-unicode console
+ //place its console encoding here
+ "console_encoding" : "",
+
// if true, plugin prints some debug information to the console window
"debug": false
}
View
@@ -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

0 comments on commit e8f23b1

Please sign in to comment.