<commit_before>package term

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

// Term struct representing a console manager
type Term struct {
	cmds map[string]func([]string)
	done chan bool
	_prompt string
}


// NewTerm creates a new initialized Term struct
func NewTerm(prompt string) *Term {
	t:= &Term{make(map[string]func([]string), 1), make(chan bool),prompt}
	return t
}

// AddCommand adds a function handler for this command
func (t *Term) AddCommand(name string, funct func([]string)) {
	t.cmds[name] = funct
}

// RemoveCommand removes a command/handler entry
func (t *Term) RemoveCommand(name string) {
	delete(t.cmds, name)
}

// Prompt set the prompt
func (t *Term) Prompt(prompt string) {
	t._prompt=prompt
}

// Display the prompt and listen for new commands
// Add them with .AddCommand(command name, function implementing it)
func (t *Term) listen() {
	scanner := bufio.NewScanner(os.Stdin)
	running := true
	fmt.Print(t._prompt + " ")
	for running && scanner.Scan() {
		tokens := strings.Split(strings.TrimSpace(scanner.Text()), " ")
		command := tokens[0]
		if command == "quit" || command == "exit" {
			running = false
		} else {
			f, found := t.cmds[command]
			switch {
			case found && len(tokens) > 1:
				f(tokens[1:])
			case found:
				f([]string{})
			}
			fmt.Print(t._prompt + " ")
		}
	}
	t.done <- true
}

func (t *Term) ListenUntilExit() {
	go t.listen()
	<-t.done
}<commit_msg>Added handler for unknown commands<commit_after>package term

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

// Term struct representing a console manager
type Term struct {
	cmds map[string]func([]string)
	done chan bool
	_prompt string
	unknownHandler func(string)
}


// NewTerm creates a new initialized Term struct
func NewTerm(prompt string) *Term {
	t:= &Term{make(map[string]func([]string), 1), make(chan bool),prompt,nil}
	return t
}

// AddCommand adds a function handler for this command
func (t *Term) AddCommand(name string, funct func([]string)) {
	t.cmds[name] = funct
}

// RemoveCommand removes a command/handler entry
func (t *Term) RemoveCommand(name string) {
	delete(t.cmds, name)
}

// AddUnknownHandler adds a function handler for unknown command
func (t *Term) AddUnknownHandler(funct func(string)) {
	t.unknownHandler = funct
}

// Prompt set the prompt
func (t *Term) Prompt(prompt string) {
	t._prompt=prompt
}

// Display the prompt and listen for new commands
// Add them with .AddCommand(command name, function implementing it)
func (t *Term) listen() {
	scanner := bufio.NewScanner(os.Stdin)
	running := true
	fmt.Print(t._prompt + " ")
	for running && scanner.Scan() {
		tokens := strings.Split(strings.TrimSpace(scanner.Text()), " ")
		command := tokens[0]
		if command == "quit" || command == "exit" {
			running = false
		} else {
			f, found := t.cmds[command]
			switch {
			case found && len(tokens) > 1:
				f(tokens[1:])
			case found:
				f([]string{})
			default:
				if t.unknownHandler!=nil && command!="" {
					t.unknownHandler(command)
				}
			}
			fmt.Print(t._prompt + " ")
		}
	}
	t.done <- true
}

func (t *Term) ListenUntilExit() {
	go t.listen()
	<-t.done
}
{'fraction_non_alphanumeric': 0.14455128205128207, 'fraction_numerical': 0.002564102564102564, 'mean_word_length': 3.78680981595092, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '4339647', 'n_tokens_mistral': 1157, 'n_tokens_neox': 1055, 'n_words': 310}