<commit_before>package frame

import (
	"context"
	"fmt"
	"os"
	"path/filepath"

	"github.com/mattn/go-colorable"

	"github.com/zetamatta/nyagos/history"
	"github.com/zetamatta/nyagos/readline"
	"github.com/zetamatta/nyagos/shell"
)

type CmdStreamConsole struct {
	shell.CmdSeeker
	DoPrompt func() (int, error)
	History  *history.Container
	Editor   *readline.Editor
	HistPath string
}

func NewCmdStreamConsole(doPrompt func() (int, error)) *CmdStreamConsole {
	history1 := &history.Container{}
	this := &CmdStreamConsole{
		History: history1,
		Editor: &readline.Editor{
			History: history1,
			Prompt:  doPrompt,
			Writer:  colorable.NewColorableStdout()},
		HistPath: filepath.Join(AppDataDir(), "nyagos.history"),
		CmdSeeker: shell.CmdSeeker{
			PlainHistory: []string{},
			Pointer:      -1,
		},
	}
	history1.Load(this.HistPath)
	history1.Save(this.HistPath)
	return this
}

func (this *CmdStreamConsole) DisableHistory(value bool) bool {
	return this.History.IgnorePush(value)
}

func (this *CmdStreamConsole) ReadLine(ctx context.Context) (context.Context, string, error) {
	if this.Pointer >= 0 {
		if this.Pointer < len(this.PlainHistory) {
			this.Pointer++
			return ctx, this.PlainHistory[this.Pointer-1], nil
		}
		this.Pointer = -1
	}
	var line string
	var err error
	for {
		line, err = this.Editor.ReadLine(ctx)
		if err != nil {<commit_msg>(#377) Fix: Escape sequence does not work after `git gui` installed by scoop<commit_after>package frame

import (
	"context"
	"fmt"
	"os"
	"path/filepath"

	"github.com/mattn/go-colorable"

	"github.com/zetamatta/nyagos/history"
	"github.com/zetamatta/nyagos/readline"
	"github.com/zetamatta/nyagos/shell"
)

type CmdStreamConsole struct {
	shell.CmdSeeker
	DoPrompt func() (int, error)
	History  *history.Container
	Editor   *readline.Editor
	HistPath string
}

func NewCmdStreamConsole(doPrompt func() (int, error)) *CmdStreamConsole {
	history1 := &history.Container{}
	this := &CmdStreamConsole{
		History: history1,
		Editor: &readline.Editor{
			History: history1,
			Prompt:  doPrompt,
			Writer:  colorable.NewColorableStdout()},
		HistPath: filepath.Join(AppDataDir(), "nyagos.history"),
		CmdSeeker: shell.CmdSeeker{
			PlainHistory: []string{},
			Pointer:      -1,
		},
	}
	history1.Load(this.HistPath)
	history1.Save(this.HistPath)
	return this
}

func (this *CmdStreamConsole) DisableHistory(value bool) bool {
	return this.History.IgnorePush(value)
}

func (this *CmdStreamConsole) ReadLine(ctx context.Context) (context.Context, string, error) {
	if this.Pointer >= 0 {
		if this.Pointer < len(this.PlainHistory) {
			this.Pointer++
			return ctx, this.PlainHistory[this.Pointer-1], nil
		}
		this.Pointer = -1
	}
	var line string
	var err error
	for {
		disabler := colorable.EnableColorsStdout(nil)
		line, err = this.Editor.ReadLine(ctx)
		disabler()
		if err != nil {
{'fraction_non_alphanumeric': 0.12947368421052632, 'fraction_numerical': 0.007368421052631579, 'mean_word_length': 4.420152091254753, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4390701', 'n_tokens_mistral': 1099, 'n_tokens_neox': 1034, 'n_words': 215}