Import "containerd/console" lib to support colorful output in Windows terminal

This commit is contained in:
vinjn
2023-11-23 22:21:32 -08:00
committed by jmorganca
parent 29e90cc13b
commit 66ef308abd
4 changed files with 13 additions and 23 deletions

View File

@@ -16,10 +16,13 @@ import (
"os"
"os/signal"
"path/filepath"
"runtime"
"strings"
"syscall"
"time"
"github.com/containerd/console"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
"golang.org/x/crypto/ssh"
@@ -810,6 +813,11 @@ func NewCLI() *cobra.Command {
log.SetFlags(log.LstdFlags | log.Lshortfile)
cobra.EnableCommandSorting = false
if runtime.GOOS == "windows" {
// Enable colorful ANSI escape code in Windows terminal (disabled by default)
console.ConsoleFromFile(os.Stdout)
}
rootCmd := &cobra.Command{
Use: "ollama",
Short: "Large language model runner",

View File

@@ -10,32 +10,9 @@ import (
"strings"
"syscall"
"golang.org/x/sys/windows"
"github.com/jmorganca/ollama/api"
)
func init() {
var inMode uint32
var outMode uint32
var errMode uint32
in := windows.Handle(os.Stdin.Fd())
if err := windows.GetConsoleMode(in, &inMode); err == nil {
windows.SetConsoleMode(in, inMode|windows.ENABLE_VIRTUAL_TERMINAL_INPUT) //nolint:errcheck
}
out := windows.Handle(os.Stdout.Fd())
if err := windows.GetConsoleMode(out, &outMode); err == nil {
windows.SetConsoleMode(out, outMode|windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING) //nolint:errcheck
}
errf := windows.Handle(os.Stderr.Fd())
if err := windows.GetConsoleMode(errf, &errMode); err == nil {
windows.SetConsoleMode(errf, errMode|windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING) //nolint:errcheck
}
}
func startApp(ctx context.Context, client *api.Client) error {
// log.Printf("XXX Attempting to find and start ollama app")
AppName := "ollama app.exe"