Skip to content

Commit

Permalink
Use user default encoding for editText (as editors follow locales for
Browse files Browse the repository at this point in the history
        encoding)
  • Loading branch information
digitalfox committed Nov 16, 2014
1 parent b76e546 commit ca56c5e
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions yokadi/ycli/tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@
import time
import unicodedata
import re
import locale
from getpass import getpass

from yokadi.ycli import colors as C

# Default user encoding. Used to decode all input strings
# This is the central yokadi definition of encoding - this constant is imported from all other modules
# Beware of circular import definition when add dependencies to this module

# Number of seconds between checks for end of process
PROC_POLL_INTERVAL = 0.5
# Number of seconds between checks for file modification
Expand Down Expand Up @@ -57,8 +54,9 @@ def editText(text, onChanged=None, lockManager=None, prefix="yokadi-"):
@param lockManager: function parameter that is called to 'acquire', 'update' or 'release' an editing lock
@param prefix: temporary file prefix.
@return: newText"""
encoding = locale.getpreferredencoding()
def readFile(name):
with open(name, encoding='utf-8') as data:
with open(name, encoding=encoding) as data:
return str(data.read())

def waitProcess(proc):
Expand All @@ -78,7 +76,7 @@ def waitProcess(proc):
try:
if lockManager:
lockManager.acquire()
fl = open(name, "w", encoding='utf-8')
fl = open(name, "w", encoding=encoding)
fl.write(text)
fl.close()
editor = os.environ.get("EDITOR", "vi")
Expand Down

0 comments on commit ca56c5e

Please sign in to comment.