<commit_before>package shell

import (
	"context"
	"os"
	"strings"
	"syscall"

	"golang.org/x/sys/windows"

	"github.com/zetamatta/nyagos/dos"
	"github.com/zetamatta/nyagos/nodos"
)

func encloseWithQuote(fullpath string) string {
	if strings.ContainsRune(fullpath, ' ') {
		var f strings.Builder
		f.WriteByte('"')
		f.WriteString(fullpath)
		f.WriteByte('"')
		return f.String()
	} else {
		return fullpath
	}
}

func (cmd *Cmd) lookpath() string {
	return nodos.LookPath(LookCurdirOrder, cmd.args[0], "NYAGOSPATH")
}

func (cmd *Cmd) startProcess(ctx context.Context) (int, error) {
	if cmd.UseShellExecute {
		// GUI Application
		cmdline := makeCmdline(cmd.args[1:], cmd.rawArgs[1:])
		pid, err := dos.ShellExecute("open", cmd.args[0], cmdline, "")
		if err == nil && pid != 0 && cmd.OnBackExec != nil {
			cmd.OnBackExec(pid)
			if cmd.OnBackDone != nil {
				if process, err := os.FindProcess(pid); err == nil {
					go func(f func(int)) {
						process.Wait()
						f(pid)
					}(cmd.OnBackDone)
				}
			}
		}
		return 0, err
	}
	if closer, err := dos.ChangeConsoleMode(windows.Stdin, dos.ModeSet(0x7)); err == nil {
		defer closer()
	}
	if closer, err := dos.ChangeConsoleMode(windows.Stdout); err == nil {
		defer closer()<commit_msg>Replace magic-number(7) to constant for SetConsoleMode<commit_after>package shell

import (
	"context"
	"os"
	"strings"
	"syscall"

	"golang.org/x/sys/windows"

	"github.com/zetamatta/nyagos/dos"
	"github.com/zetamatta/nyagos/nodos"
)

func encloseWithQuote(fullpath string) string {
	if strings.ContainsRune(fullpath, ' ') {
		var f strings.Builder
		f.WriteByte('"')
		f.WriteString(fullpath)
		f.WriteByte('"')
		return f.String()
	} else {
		return fullpath
	}
}

func (cmd *Cmd) lookpath() string {
	return nodos.LookPath(LookCurdirOrder, cmd.args[0], "NYAGOSPATH")
}

func (cmd *Cmd) startProcess(ctx context.Context) (int, error) {
	if cmd.UseShellExecute {
		// GUI Application
		cmdline := makeCmdline(cmd.args[1:], cmd.rawArgs[1:])
		pid, err := dos.ShellExecute("open", cmd.args[0], cmdline, "")
		if err == nil && pid != 0 && cmd.OnBackExec != nil {
			cmd.OnBackExec(pid)
			if cmd.OnBackDone != nil {
				if process, err := os.FindProcess(pid); err == nil {
					go func(f func(int)) {
						process.Wait()
						f(pid)
					}(cmd.OnBackDone)
				}
			}
		}
		return 0, err
	}
	if closer, err := dos.ChangeConsoleMode(windows.Stdin,
		dos.ModeSet(
			windows.ENABLE_PROCESSED_INPUT|
				windows.ENABLE_LINE_INPUT|
				windows.ENABLE_ECHO_INPUT)); err == nil {
		defer closer()
	}
	if closer, err := dos.ChangeConsoleMode(windows.Stdout); err == nil {
		defer closer()
{'fraction_non_alphanumeric': 0.15765422696115766, 'fraction_numerical': 0.0057121096725057125, 'mean_word_length': 3.707885304659498, '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': '4094575', 'n_tokens_mistral': 1103, 'n_tokens_neox': 979, 'n_words': 203}