<commit_before>package cli

import (
	"fmt"
	"io"
	"strconv"
	"strings"

	"github.com/chzyer/readline"
	"github.com/jamesnetherton/homehub-cli/cmd"
	"github.com/jamesnetherton/homehub-cli/service"
)

// CLI is a representation of the home hub command line interface
type CLI struct {
	readline *readline.Instance
	commands []cmd.Command
}

// NewCLI creates a new CLI
func NewCLI(commands []cmd.Command, readLine *readline.Instance) (cli *CLI) {
	c := &CLI{
		readLine,
		commands,
	}

	c.readline.Config.AutoComplete = readline.NewPrefixCompleter(readline.PcItemDynamic(c.commandListFunction()))

	return c
}

// Run starts the CLI and processes user input
func (c *CLI) Run() {
	defer c.readline.Close()

	banner()

	for {
		line, err := c.readline.Readline()
		if err == readline.ErrInterrupt {
			if len(line) == 0 {
				break
			} else {
				continue
			}
		} else if err == io.EOF {
			break
		}

		line = strings.TrimSpace(line)
		if !service.StringIsEmpty(line) {
			commandLine := strings.Split(line, " ")
			commandName := commandLine[0]

			command := c.findCommand(commandName)
			if command != nil {
				args := append(commandLine[:0], commandLine[1:]...)
				command.ExecuteLifecylce(args)
			} else {
				fmt.Println("homehub: Command not found:", strconv.Quote(commandName))
			}
		}
	}<commit_msg>Prevent CLI exiting on ctrl+c<commit_after>package cli

import (
	"fmt"
	"io"
	"strconv"
	"strings"

	"github.com/chzyer/readline"
	"github.com/jamesnetherton/homehub-cli/cmd"
	"github.com/jamesnetherton/homehub-cli/service"
)

// CLI is a representation of the home hub command line interface
type CLI struct {
	readline *readline.Instance
	commands []cmd.Command
}

// NewCLI creates a new CLI
func NewCLI(commands []cmd.Command, readLine *readline.Instance) (cli *CLI) {
	c := &CLI{
		readLine,
		commands,
	}

	c.readline.Config.AutoComplete = readline.NewPrefixCompleter(readline.PcItemDynamic(c.commandListFunction()))

	return c
}

// Run starts the CLI and processes user input
func (c *CLI) Run() {
	defer c.readline.Close()

	banner()

	for {
		line, err := c.readline.Readline()
		if err == readline.ErrInterrupt {
			continue
		} else if err == io.EOF {
			break
		}

		line = strings.TrimSpace(line)
		if !service.StringIsEmpty(line) {
			commandLine := strings.Split(line, " ")
			commandName := commandLine[0]

			command := c.findCommand(commandName)
			if command != nil {
				args := append(commandLine[:0], commandLine[1:]...)
				command.ExecuteLifecylce(args)
			} else {
				fmt.Println("homehub: Command not found:", strconv.Quote(commandName))
			}
		}
	}
{'fraction_non_alphanumeric': 0.13459313536444273, 'fraction_numerical': 0.002699575780948708, 'mean_word_length': 3.707803992740472, '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': '6974340', 'n_tokens_mistral': 1028, 'n_tokens_neox': 917, 'n_words': 207}