Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/dbc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ func main() {
args cmds
)

// Attempt to enable VT processing or disable colors if we can't
initVTProcessing()

if err := initDBCClient(); err != nil {
fmt.Fprintf(os.Stderr, "error initializing client: %v\n", err)
os.Exit(1)
Expand Down
19 changes: 19 additions & 0 deletions cmd/dbc/terminal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2026 Columnar Technologies Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !windows

package main

func initVTProcessing() {}
67 changes: 67 additions & 0 deletions cmd/dbc/terminal_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2026 Columnar Technologies Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build windows

package main

import (
"os"

"golang.org/x/sys/windows"
)

const (
ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004
)

func initVTProcessing() {
if !enableVTProcessing(os.Stdout) || !enableVTProcessing(os.Stderr) {
disableColors()
return
}
}

// enableVTProcessing attempts to enable ENABLE_VIRTUAL_TERMINAL_PROCESSING
// on the given file handle. Returns true if successful or already enabled.
func enableVTProcessing(f *os.File) bool {
handle := windows.Handle(f.Fd())
var mode uint32

// Get current console mode
err := windows.GetConsoleMode(handle, &mode)
if err != nil {
return false
}

// Check if VT processing is already enabled
if mode&ENABLE_VIRTUAL_TERMINAL_PROCESSING != 0 {
return true
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a normal system, we always hit this return.

}

// Try to enable VT processing
newMode := mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING
err = windows.SetConsoleMode(handle, newMode)
if err != nil {
return false
}

return true
}

// disableColors sets the NO_COLOR environment variable to disable ANSI colors.
// lipgloss and colorprofile respect NO_COLOR automatically.
func disableColors() {
os.Setenv("NO_COLOR", "1")
}
Loading