<commit_before>package mains

import (
	"errors"
	"fmt"

	"github.com/zetamatta/go-box"

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

func cstr(value interface{}) (string, bool) {
	if s, ok := value.(string); ok {
		return s, true
	}
	if s, ok := value.(fmt.Stringer); ok {
		return s.String(), true
	}
	if s, ok := value.(int); ok {
		return fmt.Sprintf("%d", s), true
	}
	return "", false
}

func cmdElevated([]interface{}) []interface{} {
	flag, _ := dos.IsElevated()
	return []interface{}{flag}
}

func cmdChdir(args []interface{}) []interface{} {
	if len(args) >= 1 {
		path, ok := cstr(args[0])
		if ok {
			dos.Chdir(path)
			return []interface{}{true}
		}
	}
	return []interface{}{nil, errors.New("directory is required")}
}

func cmdBox(args []interface{}) []interface{} {
	t, ok := args[0].(map[interface{}]interface{})
	if !ok {
		return []interface{}{nil, "Not a table"}
	}
	if len(t) == 0 {
		return []interface{}{}
	}
	sources := make([]string, 0, len(t))
	for i, i_ := 1, len(t); i <= i_; i++ {
		if val, ok := t[i]; ok {
			if str, ok := cstr(val); ok {
				sources = append(sources, str)
			}
		}
	}
	return []interface{}{box.Choice(sources, readline.Console)}
}

func cmdResetCharWidth(args []interface{}) []interface{} {
	readline.ResetCharWidth()
	return []interface{}{}
}

func cmdNetDriveToUNC(args []interface{}) []interface{} {
	if len(args) < 1 {
		return []interface{}{}
	}
	path, ok := args[0].(string)
	if !ok {
		return []interface{}{path}
	}
	unc := dos.NetDriveToUNC(path)
	return []interface{}{unc}
}<commit_msg>(internal) make functions in builtinfunc.go more simple with type= and fmt.Sprint<commit_after>package mains

import (
	"errors"
	"fmt"

	"github.com/zetamatta/go-box"

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

type any_t = interface{}

func cmdElevated([]any_t) []any_t {
	flag, _ := dos.IsElevated()
	return []any_t{flag}
}

func cmdChdir(args []any_t) []any_t {
	if len(args) >= 1 {
		dos.Chdir(fmt.Sprint(args[0]))
		return []any_t{true}
	}
	return []any_t{nil, errors.New("directory is required")}
}

func cmdBox(args []any_t) []any_t {
	t, ok := args[0].(map[any_t]any_t)
	if !ok {
		return []any_t{nil, "Not a table"}
	}
	if len(t) == 0 {
		return []any_t{}
	}
	sources := make([]string, 0, len(t))
	for i, i_ := 1, len(t); i <= i_; i++ {
		if val, ok := t[i]; ok {
			sources = append(sources, fmt.Sprint(val))
		}
	}
	return []any_t{box.Choice(sources, readline.Console)}
}

func cmdResetCharWidth(args []any_t) []any_t {
	readline.ResetCharWidth()
	return []any_t{}
}

func cmdNetDriveToUNC(args []any_t) []any_t {
	if len(args) < 1 {
		return []any_t{}
	}
	path, ok := args[0].(string)
	if !ok {
		return []any_t{path}
	}
	unc := dos.NetDriveToUNC(path)
	return []any_t{unc}
}
{'fraction_non_alphanumeric': 0.2, 'fraction_numerical': 0.005714285714285714, 'mean_word_length': 4.177449168207024, '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': '3473054', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1127, 'n_words': 253}