Last active
March 2, 2017 00:16
-
-
Save Guevara-chan/4f0dd72736bed52a4cfbfd2eead1ffaf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
conv = require 'iconv-lite' | |
# ~/Generic patcher proc/~ | |
patch866 = (proc, args...) -> | |
decoder_tmp = (encoding = 'utf8', start, end) -> | |
Δ866 iconv.decode, new Buffer(@, start, end), encoding | |
proc_swap = () -> | |
[Buffer.prototype.toString, decoder_tmp] = [decoder_tmp, Buffer.prototype.toString] | |
Δ866 = (proc, args...) -> | |
[proc_swap(), proc(args...), proc_swap()][1] | |
Δ866 proc, args... | |
# ~/Specific patcher proc/~ | |
question_fix = (old_proc, query = '', options = {}, args...) -> | |
if query then process.stdout.write query | |
options.encoding = 'cp866' unless options.encoding? | |
patch866 old_proc, '', options, args... | |
# =Usage sample= | |
rl = require('readline-sync') | |
rl.question = question_fix.bind(rl, rl.question) | |
user_name = rl.question "Как вас зовут ? " | |
console.log "Hello, #{user_name} !" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment