Skip to content

Commit

Permalink
Merge #125.
Browse files Browse the repository at this point in the history
  • Loading branch information
gauteh committed Aug 15, 2013
2 parents 42aa04e + b706adb commit 2224a86
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/sup/buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ def ask domain, question, default=nil, &block
tf.deactivate
draw_screen :sync => false, :status => status, :title => title
end
tf.value.tap { |x| x.fix_encoding if x }
tf.value.tap { |x| x }
end

def ask_getch question, accept=nil
Expand Down
10 changes: 10 additions & 0 deletions lib/sup/textfield.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ def get_cursed_value
else # trailing spaces
v + (" " * (x - @question.length - v.length))
end

# ncurses returns a ASCII-8BIT (binary) string, which
# bytes presumably are of current charset encoding. we force_encoding
# so that the char representation / string is tagged will be the
# system locale and also hopefully the terminal/input encoding. an
# incorrectly configured terminal encoding (not matching the system
# encoding) will produce erronous results, but will also do that for
# a log of other programs since it is impossible to detect which is
# which and what encoding the inputted byte chars are supposed to have.
v.force_encoding($encoding).fix_encoding
end

def remove_extra_space
Expand Down
10 changes: 1 addition & 9 deletions lib/sup/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,7 @@ def wrap len
#
# Not Ruby 1.8 compatible
def fix_encoding
# first try to set the string to utf-8 and check if it is valid
# in case ruby just thinks it is something else
orig_encoding = encoding
force_encoding 'UTF-8'
return self if valid_encoding?

# that didn't work, go back to original and try to convert
force_encoding orig_encoding

# first try to encode to utf-8 from whatever current encoding
encode!('UTF-8', :invalid => :replace, :undef => :replace)

# do this anyway in case string is set to be UTF-8, encoding to
Expand Down

0 comments on commit 2224a86

Please sign in to comment.