<commit_before>// Copyright 2012 <NAME>. All Rights Reserved.
// Author: <EMAIL> (<NAME>)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

/*
#include <pwd.h>
#include <stdlib.h>
#include <unistd.h>
*/
import "C"

import (
	"unsafe"
)

const (
	maxPasswordSize = 256
)

func readPassword(prompt string) string {
	cPrompt := C.CString(prompt)
	defer C.free(unsafe.Pointer(cPrompt))

	cPass := C.getpass(cPrompt)
	return C.GoString(cPass)
}<commit_msg>Replaced readPassword with a version that doesn't screw signal handling.<commit_after>// Copyright 2012 <NAME>. All Rights Reserved.
// Author: <EMAIL> (<NAME>)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

/*
#include <termios.h>
*/
import "C"

import (
	"bufio"
	"fmt"
	"log"
	"os"
)

func getTermSettings() (settings C.struct_termios) {
	res := C.tcgetattr(C.int(os.Stdout.Fd()), &settings)
	if res != 0 {
		panic(res)
	}

	return
}

func setTermSettings(settings C.struct_termios) {
	res := C.tcsetattr(C.int(os.Stdout.Fd()), 0, &settings)
	if res != 0 {
		panic(res)
	}
}

func readPassword(prompt string) string {
	// Grab the current terminal settings, making sure they are later restored.
	origTermSettings := getTermSettings()
	defer setTermSettings(origTermSettings)

	// Disable echoing.
	newTermSettings := origTermSettings
	newTermSettings.c_lflag = newTermSettings.c_lflag & ^C.tcflag_t(C.ECHO)
	setTermSettings(newTermSettings)

	// Display the prompt.
	fmt.Print(prompt)

	// Read from stdin. Add a newline for the user pressing enter.
	reader := bufio.NewReader(os.Stdin)
	line, err := reader.ReadString('\n')
	fmt.Println("")
	if err != nil {
		log.Fatalln("ReadString:", err)
	}

	return line[0:len(line)-1]
}
{'fraction_non_alphanumeric': 0.12165628435324295, 'fraction_numerical': 0.008794430194210334, 'mean_word_length': 3.831858407079646, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1814486', 'n_tokens_mistral': 890, 'n_tokens_neox': 852, 'n_words': 301}