Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Guevara-chan/4f0dd72736bed52a4cfbfd2eead1ffaf to your computer and use it in GitHub Desktop.
Save Guevara-chan/4f0dd72736bed52a4cfbfd2eead1ffaf to your computer and use it in GitHub Desktop.
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