/** * CQL Minus - cqlminus * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * * @author Paolo Lulli * @copyright Paolo Lulli 2026 */ package render import ( "cqlminus/internal/db" "fmt" "os" "strings" "text/tabwriter" ) func PrintTable(result *db.QueryResult) { if len(result.Columns) == 0 { fmt.Println("query ok, no columns returned") return } if len(result.Rows) == 0 { fmt.Println("0 rows returned") return } w := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0) header := strings.Join(result.Columns, "\t") fmt.Fprintln(w, header) sep := make([]string, len(result.Columns)) for i, c := range result.Columns { sep[i] = strings.Repeat("-", len(c)) } fmt.Fprintln(w, strings.Join(sep, "\t")) for _, row := range result.Rows { fmt.Fprintln(w, strings.Join(row, "\t")) } w.Flush() fmt.Printf("(%d rows)\n", len(result.Rows)) } func PrintError(err error) { fmt.Fprintf(os.Stderr, "error: %v\n", err) }