Skip to content

Commit 8daa6e7

Browse files
committed
add initial stuff
1 parent 796bbf4 commit 8daa6e7

36 files changed

+1778
-142
lines changed

.sqlfluff

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[sqlfluff:rules]
2+
exclude_rules = AM04

LICENSE

Whitespace-only changes.

cmd/root.go

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
Copyright © 2025 NAME HERE <EMAIL ADDRESS>
3+
*/
4+
package cmd
5+
6+
import (
7+
"context"
8+
"os"
9+
"sync"
10+
11+
tea "github.com/charmbracelet/bubbletea"
12+
"github.com/kujtimiihoxha/termai/internal/app"
13+
"github.com/kujtimiihoxha/termai/internal/db"
14+
"github.com/kujtimiihoxha/termai/internal/tui"
15+
"github.com/spf13/cobra"
16+
"github.com/spf13/viper"
17+
)
18+
19+
var rootCmd = &cobra.Command{
20+
Use: "termai",
21+
Short: "A terminal ai assistant",
22+
Long: `A terminal ai assistant`,
23+
RunE: func(cmd *cobra.Command, args []string) error {
24+
if cmd.Flag("help").Changed {
25+
cmd.Help()
26+
return nil
27+
}
28+
debug, _ := cmd.Flags().GetBool("debug")
29+
viper.Set("debug", debug)
30+
if debug {
31+
viper.Set("log.level", "debug")
32+
}
33+
34+
conn, err := db.Connect()
35+
if err != nil {
36+
return err
37+
}
38+
ctx := context.Background()
39+
40+
app := app.New(ctx, conn)
41+
app.Logger.Info("Starting termai...")
42+
tui := tea.NewProgram(
43+
tui.New(app),
44+
tea.WithAltScreen(),
45+
)
46+
app.Logger.Info("Setting up subscriptions...")
47+
ch, unsub := setupSubscriptions(app)
48+
defer unsub()
49+
50+
go func() {
51+
for msg := range ch {
52+
tui.Send(msg)
53+
}
54+
}()
55+
if _, err := tui.Run(); err != nil {
56+
return err
57+
}
58+
return nil
59+
},
60+
}
61+
62+
func setupSubscriptions(app *app.App) (chan tea.Msg, func()) {
63+
ch := make(chan tea.Msg)
64+
wg := sync.WaitGroup{}
65+
ctx, cancel := context.WithCancel(app.Context)
66+
67+
if viper.GetBool("debug") {
68+
sub := app.Logger.Subscribe(ctx)
69+
wg.Add(1)
70+
go func() {
71+
for ev := range sub {
72+
ch <- ev
73+
}
74+
wg.Done()
75+
}()
76+
}
77+
{
78+
sub := app.Sessions.Subscribe(ctx)
79+
wg.Add(1)
80+
go func() {
81+
for ev := range sub {
82+
ch <- ev
83+
}
84+
wg.Done()
85+
}()
86+
}
87+
return ch, func() {
88+
cancel()
89+
wg.Wait()
90+
close(ch)
91+
}
92+
}
93+
94+
// Execute adds all child commands to the root command and sets flags appropriately.
95+
// This is called by main.main(). It only needs to happen once to the rootCmd.
96+
func Execute() {
97+
err := rootCmd.Execute()
98+
if err != nil {
99+
os.Exit(1)
100+
}
101+
}
102+
103+
func loadConfig() {
104+
viper.SetConfigName(".termai")
105+
viper.SetConfigType("yaml")
106+
viper.AddConfigPath("$HOME")
107+
viper.AddConfigPath("$XDG_CONFIG_HOME/termai")
108+
viper.AddConfigPath(".")
109+
viper.SetEnvPrefix("TERMAI")
110+
// SET DEFAULTS
111+
viper.SetDefault("log.level", "info")
112+
viper.SetDefault("data.dir", ".termai")
113+
114+
//
115+
viper.ReadInConfig()
116+
}
117+
118+
func init() {
119+
loadConfig()
120+
// Here you will define your flags and configuration settings.
121+
// Cobra supports persistent flags, which, if defined here,
122+
// will be global for your application.
123+
124+
rootCmd.Flags().BoolP("help", "h", false, "Help")
125+
rootCmd.Flags().BoolP("debug", "d", false, "Help")
126+
}

cmd/termai/main.go

Lines changed: 0 additions & 56 deletions
This file was deleted.

go.mod

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,64 @@ require (
77
github.com/charmbracelet/bubbles v0.20.0
88
github.com/charmbracelet/bubbletea v1.3.4
99
github.com/charmbracelet/glamour v0.9.1
10+
github.com/charmbracelet/huh v0.6.0
1011
github.com/charmbracelet/lipgloss v1.1.0
1112
github.com/go-logfmt/logfmt v0.6.0
12-
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561
13+
github.com/golang-migrate/migrate/v4 v4.18.2
14+
github.com/google/uuid v1.6.0
15+
github.com/mattn/go-runewidth v0.0.16
16+
github.com/mattn/go-sqlite3 v1.14.24
17+
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6
18+
github.com/muesli/reflow v0.3.0
19+
github.com/muesli/termenv v0.16.0
20+
github.com/spf13/cobra v1.9.1
21+
github.com/spf13/viper v1.20.0
22+
golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0
1323
)
1424

1525
require (
1626
github.com/alecthomas/chroma/v2 v2.15.0 // indirect
27+
github.com/atotto/clipboard v0.1.4 // indirect
1728
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
1829
github.com/aymerick/douceur v0.2.0 // indirect
1930
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
2031
github.com/charmbracelet/x/ansi v0.8.0 // indirect
2132
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
33+
github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0 // indirect
2234
github.com/charmbracelet/x/term v0.2.1 // indirect
2335
github.com/dlclark/regexp2 v1.11.4 // indirect
36+
github.com/dustin/go-humanize v1.0.1 // indirect
2437
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
38+
github.com/fsnotify/fsnotify v1.8.0 // indirect
39+
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
2540
github.com/gorilla/css v1.0.1 // indirect
41+
github.com/hashicorp/errwrap v1.1.0 // indirect
42+
github.com/hashicorp/go-multierror v1.1.1 // indirect
43+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
44+
github.com/kujtimiihoxha/vimtea v0.0.3-0.20250317175717-9d8ba9c69840 // indirect
2645
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
2746
github.com/mattn/go-isatty v0.0.20 // indirect
2847
github.com/mattn/go-localereader v0.0.1 // indirect
29-
github.com/mattn/go-runewidth v0.0.16 // indirect
3048
github.com/microcosm-cc/bluemonday v1.0.27 // indirect
31-
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
49+
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
3250
github.com/muesli/cancelreader v0.2.2 // indirect
33-
github.com/muesli/reflow v0.3.0 // indirect
34-
github.com/muesli/termenv v0.16.0 // indirect
51+
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
3552
github.com/rivo/uniseg v0.4.7 // indirect
53+
github.com/sagikazarmark/locafero v0.7.0 // indirect
54+
github.com/sahilm/fuzzy v0.1.1 // indirect
55+
github.com/sourcegraph/conc v0.3.0 // indirect
56+
github.com/spf13/afero v1.12.0 // indirect
57+
github.com/spf13/cast v1.7.1 // indirect
58+
github.com/spf13/pflag v1.0.6 // indirect
59+
github.com/subosito/gotenv v1.6.0 // indirect
3660
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
3761
github.com/yuin/goldmark v1.7.8 // indirect
3862
github.com/yuin/goldmark-emoji v1.0.5 // indirect
63+
go.uber.org/atomic v1.9.0 // indirect
64+
go.uber.org/multierr v1.9.0 // indirect
3965
golang.org/x/net v0.33.0 // indirect
4066
golang.org/x/sync v0.12.0 // indirect
4167
golang.org/x/sys v0.30.0 // indirect
4268
golang.org/x/text v0.23.0 // indirect
69+
gopkg.in/yaml.v3 v3.0.1 // indirect
4370
)

0 commit comments

Comments
 (0)