refactored render to internal/render added logging with charmbracelet/log

This commit is contained in:
steven carpenter 2025-07-22 03:39:21 -04:00
parent 109c54f1e5
commit 6f0b534d8d
20 changed files with 356 additions and 13 deletions

4
Output/README.md Normal file
View file

@ -0,0 +1,4 @@
# test-test
## TLDR;
A test program generated by bubblewand

28
Output/cmd/root.go Normal file
View file

@ -0,0 +1,28 @@
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
"specCon18/test-test/tui"
)
var rootCmd = &cobra.Command{
Use: "test-test",
Short: "test-test, A test program generated by bubblewand",
Run: func(cmd *cobra.Command, args []string) {
if err := tui.Run(); err != nil {
fmt.Println("Error:", err)
os.Exit(1)
}
},
}
func Execute() {
cobra.CheckErr(rootCmd.Execute())
}
func init() {
rootCmd.AddCommand(versionCmd)
}

15
Output/cmd/version.go Normal file
View file

@ -0,0 +1,15 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of test-test",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("test-test ~ 0.0.6")
},
}

19
Output/config/config.go Normal file
View file

@ -0,0 +1,19 @@
package config
import (
"fmt"
"github.com/spf13/viper"
)
func Init() {
viper.SetConfigName("config") // config.yaml
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
err := viper.ReadInConfig()
if err != nil {
fmt.Println("No config file found; using defaults.")
}
viper.SetDefault("app.theme", "dark")
}

75
Output/flake.nix Normal file
View file

@ -0,0 +1,75 @@
# This flake was initially generated by fh, the CLI for FlakeHub (version 0.1.22)
{
# A helpful description of your flake
description = "A test program generated by bubblewand";
# Flake inputs
inputs = {
flake-schemas.url = "https://flakehub.com/f/DeterminateSystems/flake-schemas/*";
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/*";
};
# Flake outputs that other flakes can use
outputs =
{
self,
flake-schemas,
nixpkgs,
}:
let
# Helpers for producing system-specific outputs
supportedSystems = [ "x86_64-linux" ];
forEachSupportedSystem =
f:
nixpkgs.lib.genAttrs supportedSystems (
system:
f {
inherit (nixpkgs) lib;
pkgs = import nixpkgs { inherit system; };
}
);
in
{
# Schemas tell Nix about the structure of your flake's outputs
schemas = flake-schemas.schemas;
packages = forEachSupportedSystem (
{ pkgs, lib }:
{
default = pkgs.callPackage (
{ buildGoModule }:
buildGoModule {
pname = "test-test";
version = "0.0.6";
src = builtins.path {
name = "source";
path = ./.;
};
vendorHash = "";
}
) { };
}
);
# Development environments
devShells = forEachSupportedSystem (
{ pkgs, ... }:
{
default = pkgs.mkShell {
# Pinned packages available in the environment
packages = with pkgs; [
just
gcc
go_1_23
nixpkgs-fmt
gopls
cobra-cli
];
env = {
CGO_ENABLED = "1";
CC = "gcc";
};
};
}
);
};
}

45
Output/go.mod Normal file
View file

@ -0,0 +1,45 @@
module specCon18/test-test
go 1.21
require (
github.com/charmbracelet/bubbletea v0.25.0
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.17.0
)
require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/text v0.13.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

View file

@ -0,0 +1,19 @@
package logger
import (
"os"
"github.com/charmbracelet/log"
)
var Log *log.Logger
func init() {
Log = log.NewWithOptions(os.Stderr, log.Options{
ReportCaller: false,
ReportTimestamp: true,
Prefix: "test-test",
Level: log.InfoLevel,
})
}

31
Output/justfile Normal file
View file

@ -0,0 +1,31 @@
# Set the shell
set shell := ["bash", "-cu"]
# Build the Go project
build:
go build -o bin/app .
# Run the Go project
run:
go run .
# Run tests
test:
go test ./...
# Clean build artifacts
clean:
rm -rf bin
# Format the code
fmt:
go fmt ./...
# Tidy up go.mod/go.sum
tidy:
go mod tidy
# Init Go module (optional first step)
init:
go mod init

7
Output/main.go Normal file
View file

@ -0,0 +1,7 @@
package main
import "specCon18/test-test/cmd"
func main() {
cmd.Execute()
}

11
Output/tui/model.go Normal file
View file

@ -0,0 +1,11 @@
package tui
import tea "github.com/charmbracelet/bubbletea"
type model struct {
count int
}
func (m model) Init() tea.Cmd {
return nil
}

10
Output/tui/run.go Normal file
View file

@ -0,0 +1,10 @@
package tui
import tea "github.com/charmbracelet/bubbletea"
func Run() error {
p := tea.NewProgram(model{})
_, err := p.Run()
return err
}

18
Output/tui/update.go Normal file
View file

@ -0,0 +1,18 @@
package tui
import tea "github.com/charmbracelet/bubbletea"
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "q", "ctrl+c":
return m, tea.Quit
case "up":
m.count++
case "down":
m.count--
}
}
return m, nil
}

7
Output/tui/view.go Normal file
View file

@ -0,0 +1,7 @@
package tui
import "fmt"
func (m model) View() string {
return "Counter: " + fmt.Sprintf("%d", m.count) + "\n[↑/↓ to change, q to quit]"
}