<commit_before>// +build windows

package terminal

func (ui TerminalUI) AskForPassword(prompt string, args ...interface{}) (passwd string) {
	return ui.Ask(prompt, args...)
}<commit_msg>Hide password on input for Windows based systems<commit_after>// +build windows

package terminal

import (
	"os"
	"syscall"
)

// see SetConsoleMode documentation for bit flags
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms686033(v=vs.85).aspx
const ENABLE_ECHO_INPUT = 0x0004

func (ui TerminalUI) AskForPassword(prompt string, args ...interface{}) (passwd string) {
	hStdin := syscall.Handle(os.Stdin.Fd())
	var originalMode uint32

	err := syscall.GetConsoleMode(hStdin, &originalMode)
	if err != nil {
		return
	}

	var newMode uint32 = (originalMode &^ ENABLE_ECHO_INPUT)

	err = setConsoleMode(hStdin, newMode)
	defer setConsoleMode(hStdin, originalMode)
	defer ui.Say("")

	if err != nil {
		return
	}

	return ui.Ask(prompt, args...)
}

func setConsoleMode(console syscall.Handle, mode uint32) (err error) {
	dll := syscall.MustLoadDLL("kernel32")
	proc := dll.MustFindProc("SetConsoleMode")
	r, _, err := proc.Call(uintptr(console), uintptr(mode))

	if r == 0 {
		return err
	}
	return nil
}
{'fraction_non_alphanumeric': 0.13300083125519535, 'fraction_numerical': 0.01828761429758936, 'mean_word_length': 4.574074074074074, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4713373', 'n_tokens_mistral': 454, 'n_tokens_neox': 405, 'n_words': 105}